src/visit.c
double visit_assign(ast_t* node) {

    msg(2, "Visit %s AST node", NT_TOSTR(node->type));
    if(node != NULL) {
        //node_type_t type = node->type;
        double left;    // identifier node
        double right;   // expression node
        const char* name;

        if(node->left != NULL) {
            name = node->left->value.var->name;
            if(SYM_NO_ERROR != find_symbol(name, &left)) {
                error("symbol \"%s\" is not defined", name);
                return NAN;
            }
        }
        else {
            error("invalid left assign child node");
            return NAN;
        }

        if(node->right != NULL)
            right = node->right->visit(node->right);
        else {
            error("invalid right assign child node");
            return NAN;
        }

        switch(node->value.op->op) {
            case ASSIGN_OP:
                if(SYM_NO_ERROR != assign_symbol(name, right)) {
                    error("symbol \"%s\" is not found", name);
                    return NAN;
                }
                else
                    return right;
            default:
                error("invalid assign node type: %s", OP_TOSTR(node->value.op->op));
                return NAN;
        }
    }
    else {
        error("invalid assign node");
        return NAN; // not a number
    }

    return NAN; // unreachable
}
/*
 * Perform binary operation where the left item is the assign target and the
 * right item is the value to assign. This function causes the AST to be
 * traversed so that the assignment can be made.
 */
Perform binary operation where the left item is the assign target and the
right item is the value to assign. This function causes the AST to be
traversed so that the assignment can be made.
Perform binary operation where the left item is the assign target and the right item is the value to assign . This function causes the AST to be traversed so that the assignment can be made .
double visit_assign(ast_t* node) {
    msg(2, "Visit %s AST node", NT_TOSTR(node->type));
    if(node != NULL) {
        double left;    
        double right;   
        const char* name;
        if(node->left != NULL) {
            name = node->left->value.var->name;
            if(SYM_NO_ERROR != find_symbol(name, &left)) {
                error("symbol \"%s\" is not defined", name);
                return NAN;
            }
        }
        else {
            error("invalid left assign child node");
            return NAN;
        }
        if(node->right != NULL)
            right = node->right->visit(node->right);
        else {
            error("invalid right assign child node");
            return NAN;
        }
        switch(node->value.op->op) {
            case ASSIGN_OP:
                if(SYM_NO_ERROR != assign_symbol(name, right)) {
                    error("symbol \"%s\" is not found", name);
                    return NAN;
                }
                else
                    return right;
            default:
                error("invalid assign node type: %s", OP_TOSTR(node->value.op->op));
                return NAN;
        }
    }
    else {
        error("invalid assign node");
        return NAN; 
    }
    return NAN; 
}
double visit_assign ( ast_t * node ) { msg ( 2 , " " , NT_TOSTR ( node -> type ) ) ; if ( node != NULL ) { double left ; double right ; const char * name ; if ( node -> left != NULL ) { name = node -> left -> value . var -> name ; if ( SYM_NO_ERROR != find_symbol ( name , & left ) ) { error ( " \" \" " , name ) ; return NAN ; } } else { error ( " " ) ; return NAN ; } if ( node -> right != NULL ) right = node -> right -> visit ( node -> right ) ; else { error ( " " ) ; return NAN ; } switch ( node -> value . op -> op ) { case ASSIGN_OP : if ( SYM_NO_ERROR != assign_symbol ( name , right ) ) { error ( " \" \" " , name ) ; return NAN ; } else return right ; default : error ( " " , OP_TOSTR ( node -> value . op -> op ) ) ; return NAN ; } } else { error ( " " ) ; return NAN ; } return NAN ; }
Perform binary operation where the left item is the assign target and the
 right item is the value to assign.
Perform binary operation where the left item is the assign target and the right item is the value to assign .
//node_type_t type = node->type; // identifier node // expression node // not a number // unreachable