void CompilationEngine::compileClass() { /* 'class' className '{' classVarDec* subroutineDec* '}' */ tagNonTerminal("class"); nextToken(); readKeyword("class", Keyword::kCLASS); nextToken(); readIdentifier(); nextToken(); readSymbol('{'); nextToken(); while (jt.tokenType() == TokenType::kKEYWORD && (jt.keyword() == Keyword::kFIELD || jt.keyword() == Keyword::kSTATIC)) compileClassVarDec(); while (jt.tokenType() == TokenType::kKEYWORD && (jt.keyword() == Keyword::kCONSTRUCTOR || jt.keyword() == Keyword::kFUNCTION || jt.keyword() == Keyword::kMETHOD)) compileSubroutine(); readSymbol('}'); untagNonTerminal("class"); if (jt.advance()) // jack language does not allow anything else beyond the class throw CompilationException("jack language does not allow anything else beyond the class"); }
void CompilationEng::compileClass() { getToken(); printNonterminal("class"); numOfTab++; printCurrentToken(false); //<keyword> class </keyword> printCurrentToken(true); //<identifier> className </identifier> printCurrentToken(true); //<symbol> { </symbol> compileClassVarDec(); compileSubroutine(); printCurrentToken(true); //<symbol> } </symbol> numOfTab--; printNonterminal("class",false); //end of class }