void compileForSt(void) { eat(KW_FOR); eat(TK_IDENT); // TODO: check if the identifier is a variable checkDeclaredVariable(currentToken->string); eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); }
void compileForSt(void) { eat(KW_FOR); eat(TK_IDENT); // check if the identifier is a variable if (checkDeclaredVariable(currentToken->string) == NULL) error(ERR_UNDECLARED_VARIABLE, currentToken->lineNo, currentToken->colNo); eat(SB_ASSIGN); compileExpression(); eat(KW_TO); compileExpression(); eat(KW_DO); compileStatement(); }
void compileForSt(void) { // Check type consistency of FOR's variable eat(KW_FOR); eat(TK_IDENT); // check if the identifier is a variable Object *var = checkDeclaredVariable(currentToken->string); checkBasicType(var->varAttrs->type); eat(SB_ASSIGN); Type *exp1Type = compileExpression(); checkBasicType(exp1Type); eat(KW_TO); Type *exp2Type = compileExpression(); checkBasicType(exp2Type); // Compare 3 types checkTypeEquality(var->varAttrs->type, exp1Type); checkTypeEquality(exp1Type, exp2Type); eat(KW_DO); compileStatement(); }