void compileProcDecl(void) { Object* procObj; eat(KW_PROCEDURE); eat(TK_IDENT); checkFreshIdent(currentToken->string); procObj = createProcedureObject(currentToken->string); declareObject(procObj); enterBlock(procObj->procAttrs->scope); compileParams(); eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); exitBlock(); }
void compileConstDecls(void) { Object* constObj; ConstantValue* constValue; if (lookAhead->tokenType == KW_CONST) { eat(KW_CONST); do { eat(TK_IDENT); checkFreshIdent(currentToken->string); constObj = createConstantObject(currentToken->string); declareObject(constObj); eat(SB_EQ); constValue = compileConstant(); constObj->constAttrs->value = constValue; eat(SB_SEMICOLON); } while (lookAhead->tokenType == TK_IDENT); } }
void compileTypeDecls(void) { Object* typeObj; Type* actualType; if (lookAhead->tokenType == KW_TYPE) { eat(KW_TYPE); do { eat(TK_IDENT); checkFreshIdent(currentToken->string); typeObj = createTypeObject(currentToken->string); declareObject(typeObj); eat(SB_EQ); actualType = compileType(); typeObj->typeAttrs->actualType = actualType; eat(SB_SEMICOLON); } while (lookAhead->tokenType == TK_IDENT); } }
void compileProcDecl(void) { Object* procObj; eat(KW_PROCEDURE); eat(TK_IDENT); // TODO: Check if a procedure identifier is fresh in the block checkFreshIdent(currentToken->string); // create a procedure object procObj = createProcedureObject(currentToken->string); // declare the procedure object declareObject(procObj); // enter the procedure's block enterBlock(procObj->procAttrs->scope); // parse the procedure's parameters compileParams(); eat(SB_SEMICOLON); compileBlock(); eat(SB_SEMICOLON); // exit the block exitBlock(); }