void compileExpression3(void) { while(lookAhead->tokenType == SB_PLUS || lookAhead->tokenType == SB_MINUS){ switch(lookAhead->tokenType){ case SB_PLUS: eat(SB_PLUS); compileTerm(); compileExpression3(); break; case SB_MINUS: eat(SB_MINUS); compileTerm(); compileExpression3(); break; /*case KW_TO: case KW_DO: case SB_RPAR: case SB_COMMA: case SB_EQ: case SB_NEQ: case SB_LE: case SB_LT: case SB_GE: case SB_GT: case SB_RSEL: case SB_SEMICOLON: case KW_END: case KW_ELSE: case KW_THEN: break;*/ default: error(ERR_INVALIDEXPRESSION, lookAhead->lineNo, lookAhead->colNo); break; } } }
Type* compileExpression3(Type* argType1) { Type* argType2; Type* resultType; switch (lookAhead->tokenType) { case SB_PLUS: eat(SB_PLUS); checkIntType(argType1); argType2 = compileTerm(); checkIntType(argType2); genAD(); resultType = compileExpression3(argType1); break; case SB_MINUS: eat(SB_MINUS); checkIntType(argType1); argType2 = compileTerm(); checkIntType(argType2); genSB(); resultType = compileExpression3(argType1); break; // check the FOLLOW set case KW_TO: case KW_DO: case SB_RPAR: case SB_COMMA: case SB_EQ: case SB_NEQ: case SB_LE: case SB_LT: case SB_GE: case SB_GT: case SB_RSEL: case SB_SEMICOLON: case KW_END: case KW_ELSE: case KW_THEN: resultType = argType1; break; default: error(ERR_INVALID_EXPRESSION, lookAhead->lineNo, lookAhead->colNo); } return resultType; }
Type* compileExpression2(void) { Type* type; type = compileTerm(); compileExpression3(); return type; }
Type* compileExpression3(void) { Type* type1; Type* type2; switch (lookAhead->tokenType) { case SB_PLUS: eat(SB_PLUS); type1 = compileTerm(); checkIntType(type1); type2 = compileExpression3(); if (type2 != NULL) checkIntType(type2); return type1; break; case SB_MINUS: eat(SB_MINUS); type1 = compileTerm(); checkIntType(type1); type2 = compileExpression3(); if (type2 != NULL) checkIntType(type2); return type1; break; // check the FOLLOW set case KW_TO: case KW_DO: case SB_RPAR: case SB_COMMA: case SB_EQ: case SB_NEQ: case SB_LE: case SB_LT: case SB_GE: case SB_GT: case SB_RSEL: case SB_SEMICOLON: case KW_END: case KW_ELSE: case KW_THEN: return NULL; break; default: error(ERR_INVALID_EXPRESSION, lookAhead->lineNo, lookAhead->colNo); } return NULL; }
void compileExpression3(void) { // TODO switch(lookAhead->tokenType) { case SB_PLUS: eat(SB_PLUS); compileTerm(); compileExpression3(); break; case SB_MINUS: eat(SB_MINUS); compileTerm(); compileExpression3(); break; // Follow (statement) case SB_SEMICOLON: case KW_END: case KW_ELSE: // Follow (For statement) case KW_TO: case KW_DO: // Follow (arguments2) case SB_COMMA: // Follow (condition2) case SB_EQ: case SB_NEQ: case SB_LE: case SB_LT: case SB_GE: case SB_GT: // Follow (factor) case SB_RPAR: // Follow (indexes) case SB_RSEL: // Follow (if statement) case KW_THEN: break; // Error default: error(ERR_INVALIDEXPRESSION, lookAhead->lineNo, lookAhead->colNo); break; } }
Type* compileExpression2(void) { Type* type1; Type* type2; type1 = compileTerm(); type2 = compileExpression3(); if (type2 == NULL) return type1; else { checkTypeEquality(type1,type2); return type1; } }
void compileExpression2(void) { // TODO compileTerm(); compileExpression3(); }
void compileExpression2(void) { compileTerm(); compileExpression3(); }