parse.c
static ParseTreeNode *MakeBinaryOpNode(ParseContext *c, int op, ParseTreeNode *left, ParseTreeNode *right)
{
    ParseTreeNode *node;
    ResolveVariableRef(c, left);
    ResolveVariableRef(c, right);
    if (IsIntegerLit(left) && IsIntegerLit(right)) {
        node = left;
        switch (op) {
        case OP_BXOR:
            node->u.integerLit.value = left->u.integerLit.value ^ right->u.integerLit.value;
            break;
        case OP_BOR:
            node->u.integerLit.value = left->u.integerLit.value | right->u.integerLit.value;
            break;
        case OP_BAND:
            node->u.integerLit.value = left->u.integerLit.value & right->u.integerLit.value;
            break;
        case OP_EQ:
            node->u.integerLit.value = left->u.integerLit.value == right->u.integerLit.value;
            break;
        case OP_NE:
            node->u.integerLit.value = left->u.integerLit.value != right->u.integerLit.value;
            break;
        case OP_LT:
            node->u.integerLit.value = left->u.integerLit.value < right->u.integerLit.value;
            break;
        case OP_LE:
            node->u.integerLit.value = left->u.integerLit.value <= right->u.integerLit.value;
            break;
        case OP_GE:
            node->u.integerLit.value = left->u.integerLit.value >= right->u.integerLit.value;
            break;
        case OP_GT:
            node->u.integerLit.value = left->u.integerLit.value > right->u.integerLit.value;
            break;
        case OP_SHL:
            node->u.integerLit.value = left->u.integerLit.value << right->u.integerLit.value;
            break;
        case OP_SHR:
            node->u.integerLit.value = left->u.integerLit.value >> right->u.integerLit.value;
            break;
        case OP_ADD:
            node->u.integerLit.value = left->u.integerLit.value + right->u.integerLit.value;
            break;
        case OP_SUB:
            node->u.integerLit.value = left->u.integerLit.value - right->u.integerLit.value;
            break;
        case OP_MUL:
            node->u.integerLit.value = left->u.integerLit.value * right->u.integerLit.value;
            break;
        case OP_DIV:
            if (right->u.integerLit.value == 0)
                ParseError(c, "division by zero in constant expression");
            node->u.integerLit.value = left->u.integerLit.value / right->u.integerLit.value;
            break;
        case OP_REM:
            if (right->u.integerLit.value == 0)
                ParseError(c, "division by zero in constant expression");
            node->u.integerLit.value = left->u.integerLit.value % right->u.integerLit.value;
            break;
        default:
            goto integerOp;
        }
    }
    else {
        if (left->type == &c->integerType) {
            if (right->type == &c->integerType) {
integerOp:
                node = NewParseTreeNode(c, NodeTypeBinaryOp);
                node->type = &c->integerType;
                node->u.binaryOp.op = op;
                node->u.binaryOp.left = left;
                node->u.binaryOp.right = right;
            }
            else {
                ParseError(c, "Expecting right operand to be anumeric expression: %d", right->nodeType);
                node = NULL; /* not reached */
            }
        }
        else {
            ParseError(c, "Expecting left operand to be a numeric expression: %d", left->nodeType);
            node = NULL; /* not reached */
        }
    }
    return node;
}
/* MakeBinaryOpNode - allocate a binary operation parse tree node */
allocate a binary operation parse tree node
allocate a binary operation parse tree node
static ParseTreeNode *MakeBinaryOpNode(ParseContext *c, int op, ParseTreeNode *left, ParseTreeNode *right)
{
    ParseTreeNode *node;
    ResolveVariableRef(c, left);
    ResolveVariableRef(c, right);
    if (IsIntegerLit(left) && IsIntegerLit(right)) {
        node = left;
        switch (op) {
        case OP_BXOR:
            node->u.integerLit.value = left->u.integerLit.value ^ right->u.integerLit.value;
            break;
        case OP_BOR:
            node->u.integerLit.value = left->u.integerLit.value | right->u.integerLit.value;
            break;
        case OP_BAND:
            node->u.integerLit.value = left->u.integerLit.value & right->u.integerLit.value;
            break;
        case OP_EQ:
            node->u.integerLit.value = left->u.integerLit.value == right->u.integerLit.value;
            break;
        case OP_NE:
            node->u.integerLit.value = left->u.integerLit.value != right->u.integerLit.value;
            break;
        case OP_LT:
            node->u.integerLit.value = left->u.integerLit.value < right->u.integerLit.value;
            break;
        case OP_LE:
            node->u.integerLit.value = left->u.integerLit.value <= right->u.integerLit.value;
            break;
        case OP_GE:
            node->u.integerLit.value = left->u.integerLit.value >= right->u.integerLit.value;
            break;
        case OP_GT:
            node->u.integerLit.value = left->u.integerLit.value > right->u.integerLit.value;
            break;
        case OP_SHL:
            node->u.integerLit.value = left->u.integerLit.value << right->u.integerLit.value;
            break;
        case OP_SHR:
            node->u.integerLit.value = left->u.integerLit.value >> right->u.integerLit.value;
            break;
        case OP_ADD:
            node->u.integerLit.value = left->u.integerLit.value + right->u.integerLit.value;
            break;
        case OP_SUB:
            node->u.integerLit.value = left->u.integerLit.value - right->u.integerLit.value;
            break;
        case OP_MUL:
            node->u.integerLit.value = left->u.integerLit.value * right->u.integerLit.value;
            break;
        case OP_DIV:
            if (right->u.integerLit.value == 0)
                ParseError(c, "division by zero in constant expression");
            node->u.integerLit.value = left->u.integerLit.value / right->u.integerLit.value;
            break;
        case OP_REM:
            if (right->u.integerLit.value == 0)
                ParseError(c, "division by zero in constant expression");
            node->u.integerLit.value = left->u.integerLit.value % right->u.integerLit.value;
            break;
        default:
            goto integerOp;
        }
    }
    else {
        if (left->type == &c->integerType) {
            if (right->type == &c->integerType) {
integerOp:
                node = NewParseTreeNode(c, NodeTypeBinaryOp);
                node->type = &c->integerType;
                node->u.binaryOp.op = op;
                node->u.binaryOp.left = left;
                node->u.binaryOp.right = right;
            }
            else {
                ParseError(c, "Expecting right operand to be anumeric expression: %d", right->nodeType);
                node = NULL; 
            }
        }
        else {
            ParseError(c, "Expecting left operand to be a numeric expression: %d", left->nodeType);
            node = NULL; 
        }
    }
    return node;
}
static ParseTreeNode * MakeBinaryOpNode ( ParseContext * c , int op , ParseTreeNode * left , ParseTreeNode * right ) { ParseTreeNode * node ; ResolveVariableRef ( c , left ) ; ResolveVariableRef ( c , right ) ; if ( IsIntegerLit ( left ) && IsIntegerLit ( right ) ) { node = left ; switch ( op ) { case OP_BXOR : node -> u . integerLit . value = left -> u . integerLit . value ^ right -> u . integerLit . value ; break ; case OP_BOR : node -> u . integerLit . value = left -> u . integerLit . value | right -> u . integerLit . value ; break ; case OP_BAND : node -> u . integerLit . value = left -> u . integerLit . value & right -> u . integerLit . value ; break ; case OP_EQ : node -> u . integerLit . value = left -> u . integerLit . value == right -> u . integerLit . value ; break ; case OP_NE : node -> u . integerLit . value = left -> u . integerLit . value != right -> u . integerLit . value ; break ; case OP_LT : node -> u . integerLit . value = left -> u . integerLit . value < right -> u . integerLit . value ; break ; case OP_LE : node -> u . integerLit . value = left -> u . integerLit . value <= right -> u . integerLit . value ; break ; case OP_GE : node -> u . integerLit . value = left -> u . integerLit . value >= right -> u . integerLit . value ; break ; case OP_GT : node -> u . integerLit . value = left -> u . integerLit . value > right -> u . integerLit . value ; break ; case OP_SHL : node -> u . integerLit . value = left -> u . integerLit . value << right -> u . integerLit . value ; break ; case OP_SHR : node -> u . integerLit . value = left -> u . integerLit . value >> right -> u . integerLit . value ; break ; case OP_ADD : node -> u . integerLit . value = left -> u . integerLit . value + right -> u . integerLit . value ; break ; case OP_SUB : node -> u . integerLit . value = left -> u . integerLit . value - right -> u . integerLit . value ; break ; case OP_MUL : node -> u . integerLit . value = left -> u . integerLit . value * right -> u . integerLit . value ; break ; case OP_DIV : if ( right -> u . integerLit . value == 0 ) ParseError ( c , " " ) ; node -> u . integerLit . value = left -> u . integerLit . value / right -> u . integerLit . value ; break ; case OP_REM : if ( right -> u . integerLit . value == 0 ) ParseError ( c , " " ) ; node -> u . integerLit . value = left -> u . integerLit . value % right -> u . integerLit . value ; break ; default : goto integerOp ; } } else { if ( left -> type == & c -> integerType ) { if ( right -> type == & c -> integerType ) { integerOp : node = NewParseTreeNode ( c , NodeTypeBinaryOp ) ; node -> type = & c -> integerType ; node -> u . binaryOp . op = op ; node -> u . binaryOp . left = left ; node -> u . binaryOp . right = right ; } else { ParseError ( c , " " , right -> nodeType ) ; node = NULL ; } } else { ParseError ( c , " " , left -> nodeType ) ; node = NULL ; } } return node ; }
MakeBinaryOpNode - allocate a binary operation parse tree node
MakeBinaryOpNode - allocate a binary operation parse tree node
/* not reached */ /* not reached */