void compileDoWhileSt(void) { assert("Parsing a do..while statement ...."); // TODO eat(KW_DO); compileStatement(); eat(KW_WHILE); compileCondition(); assert("Do..While statement parsed ...."); void compileForSt(void) { Type* varType; Type *type; eat(KW_FOR); varType = compileLValue(); eat(SB_ASSIGN); type = compileExpression(); checkTypeEquality(varType, type); eat(KW_TO); type = compileExpression(); checkTypeEquality(varType, type); eat(KW_DO); compileStatement(); }
void compileArgument(Object* param) { Type* type; if (param->paramAttrs->kind == PARAM_VALUE) { type = compileExpression(); checkTypeEquality(type, param->paramAttrs->type); } else { type = compileLValue(); checkTypeEquality(type, param->paramAttrs->type); } }
void compileArgument(Object* param) { // TODO: parse an argument, and check type consistency // If the corresponding parameter is a reference, the argument must be a lvalue Type* type; if (param->paramAttrs->kind == PARAM_VALUE) { type = compileExpression(); checkTypeEquality(type, param->paramAttrs->type); } else { type = compileLValue(); checkTypeEquality(type, param->paramAttrs->type); } }
void compileCondition(void) { Type* type1; Type* type2; TokenType op; type1 = compileExpression(); checkBasicType(type1); op = lookAhead->tokenType; switch (op) { case SB_EQ: eat(SB_EQ); break; case SB_NEQ: eat(SB_NEQ); break; case SB_LE: eat(SB_LE); break; case SB_LT: eat(SB_LT); break; case SB_GE: eat(SB_GE); break; case SB_GT: eat(SB_GT); break; default: error(ERR_INVALID_COMPARATOR, lookAhead->lineNo, lookAhead->colNo); } type2 = compileExpression(); checkTypeEquality(type1,type2); }
void compileCondition(void) { // DONE: check the type consistency of LHS and RSH, check the basic type Type* type1; Type* type2; type1 = compileExpression(); checkBasicType(type1); switch (lookAhead->tokenType) { case SB_EQ: eat(SB_EQ); break; case SB_NEQ: eat(SB_NEQ); break; case SB_LE: eat(SB_LE); break; case SB_LT: eat(SB_LT); break; case SB_GE: eat(SB_GE); break; case SB_GT: eat(SB_GT); break; default: error(ERR_INVALID_COMPARATOR, lookAhead->lineNo, lookAhead->colNo); } type2 = compileExpression(); checkTypeEquality(type1,type2); }
void compileCondition(void) { // check the type consistency of LHS and RSH, check the basic type Type *exp1 = compileExpression(); checkBasicType(exp1); switch (lookAhead->tokenType) { case SB_EQ: eat(SB_EQ); break; case SB_NEQ: eat(SB_NEQ); break; case SB_LE: eat(SB_LE); break; case SB_LT: eat(SB_LT); break; case SB_GE: eat(SB_GE); break; case SB_GT: eat(SB_GT); break; default: error(ERR_INVALID_COMPARATOR, lookAhead->lineNo, lookAhead->colNo); } Type *exp2 = compileExpression(); checkBasicType(exp2); // Compare 2 sides checkTypeEquality(exp1, exp2); }
void compileAssignSt(void) { // TODO: parse the assignment and check type consistency Type* varType; Type* expType; varType=compileLValue(); eat(SB_ASSIGN); expType=compileExpression(); checkTypeEquality(varType, expType); }
void compileAssignSt(void) { Type* varType; Type* expType; varType = compileLValue(); eat(SB_ASSIGN); expType = compileExpression(); checkTypeEquality(varType, expType); }
void compileAssignSt(void) { // parse the assignment and check type consistency Type *lvalueType = NULL; Type *expType = NULL; lvalueType = compileLValue(); eat(SB_ASSIGN); expType = compileExpression(); checkTypeEquality(lvalueType, expType); }
void compileForSt(void) { CodeAddress beginLoop; Instruction* fjInstruction; Type* varType; Type *type; eat(KW_FOR); varType = compileLValue(); eat(SB_ASSIGN); genCV(); type = compileExpression(); checkTypeEquality(varType, type); genST(); genCV(); genLI(); beginLoop = getCurrentCodeAddress(); eat(KW_TO); type = compileExpression(); checkTypeEquality(varType, type); genLE(); fjInstruction = genFJ(DC_VALUE); eat(KW_DO); compileStatement(); genCV(); genCV(); genLI(); genLC(1); genAD(); genST(); genCV(); genLI(); genJ(beginLoop); updateFJ(fjInstruction, getCurrentCodeAddress()); genDCT(1); }
void compileForSt(void) { // DONE: Check type consistency of FOR's variable Type* varType; Type *type; eat(KW_FOR); varType = compileLValue(); eat(SB_ASSIGN); type = compileExpression(); checkTypeEquality(varType, type); eat(KW_TO); type = compileExpression(); checkTypeEquality(varType, type); eat(KW_DO); compileStatement(); }
Type* compileTerm(void) { Type* type1; Type* type2; type1 = compileFactor(); type2 = compileTerm2(); if (type2 != NULL) { checkTypeEquality(type1,type2); } return type1; }
Type* compileExpression2(void) { Type* type1; Type* type2; type1 = compileTerm(); type2 = compileExpression3(); if (type2 == NULL) return type1; else { checkTypeEquality(type1,type2); return type1; } }
void compileAssignSt(void) { // TODO: Generate code for the assignment Type* varType; Type* expType; varType = compileLValue(); eat(SB_ASSIGN); expType = compileExpression(); checkTypeEquality(varType, expType); genST(); }
void compileForSt(void) { // TODO: Check type consistency of FOR's variable Type* varType; Type *type; eat(KW_FOR); //eat(TK_IDENT); // check if the identifier is a variable //checkDeclaredVariable(currentToken->string); varType = compileLValue(); eat(SB_ASSIGN); type = compileExpression(); checkTypeEquality(varType, type); eat(KW_TO); type = compileExpression(); checkTypeEquality(varType, type); eat(KW_DO); compileStatement(); }
void compileArgument(Object* param) { // parse an argument, and check type consistency // If the corresponding parameter is a reference, the argument must be a lvalue if (param->paramAttrs->kind == PARAM_REFERENCE) { if (lookAhead->tokenType == TK_IDENT) { checkDeclaredLValueIdent(lookAhead->string); } else { error(ERR_TYPE_INCONSISTENCY, lookAhead->lineNo, lookAhead->colNo); } } Type *argType = compileExpression(); checkTypeEquality(argType, param->paramAttrs->type); }
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(); }