// Purpose: Tests the production rule for Declaration List bool syntaxparser::DeclarationList(){ bool bDeclarationList = false; if (displayFlag){ cout <<endl<< "<DeclarationList> ::= <Declaration>;<DeclarationList>" << endl; printproduction("<DeclarationList> ::= <Declaration>;<DeclarationList>"); } Declaration(); //checks to see if next lexeme is a qualifier if(lexeme ==";"){ Lexer(); if(lexeme == "int" || lexeme == "boolean"){ project3.addType(lexeme); Lexer(); // if we have a semi colon then we recursively call for more additional declarations DeclarationList(); } else if (lexeme == "real"){ error("The 'real' type is not valid for Rat10F"); } } else error("Missing ;"); bDeclarationList = true; return bDeclarationList; }
bool syntaxparser::OptDeclarationList(){ bool OptDeclarationList=false; //checks to see if next lexeme is a qualifier if(lexeme == "int" || lexeme == "boolean"){ if (displayFlag){ cout<<endl<<"<OptDeclarationList> ::= <DeclarationList>"<<endl; printproduction("<OptDeclarationList> ::= <DeclarationList>"); } OptDeclarationList = true; DeclarationList(); } else if (lexeme == "real"){ error("The 'real' type is not valid for Rat10F"); } else{ // if no optional declaration list then its empty if (displayFlag){ cout<<"<OptDeclarationList> ::= <Empty>"<<endl; printproduction("<OptDeclarationList> ::= <Empty>"); } OptDeclarationList = true; Empty(); } return OptDeclarationList; }
Node* Parser::ExternalDecl() { Node* def = FunctionDefinitionStmt(); if(def == NULL) { if(simple) return StatementList(); return DeclarationList(); } return def; }
/* <Declaration List Prime> ::= <Declaration List> | epsilon */ void SyntaxAnalyzer::DeclarationListPrime() { if(DeclarationList()) { logger.Log("<Declaration List Prime> ::= <Declaration List>"); } else // if(epsilon()) { logger.Log("<Declaration List Prime> ::= epsilon"); } }
/* <Opt Declaration List> ::= <Declaration List> | epsilon */ void SyntaxAnalyzer::OptDeclarationList() { if(DeclarationList()) { logger.Log("<Opt Declaration List> ::= <Declaration List>"); } else { // epsilon logger.Log("<Opt Declaration List> ::= epsilon"); } }
Node* Parser::DeclarationList() { Node *decl = Declaration(); if(decl != NULL) { Node *link = DeclarationList(); if(link == NULL) { return decl; } return new NodeStmt("<decl>", decl, link); } return NULL; }
Node* Parser::CompoundStmt() { if(oper == FIGURE_LEFT_BRACKET) { Next(); Node *decl = DeclarationList(); Node *stmt = StatementList(); if(oper != FIGURE_RIGHT_BRACKET) throw ParserException(currentToken, "Compound statement without '}'"); else Next(); return new NodeStmt("{stmt}", decl, stmt); } return NULL; }
Node* Parser::Statement() { Node *link = NULL; if(simple) link = FunctionDefinitionStmt(); if(link == NULL) link = CompoundStmt(); if(link == NULL) link = ExpressionStmt(); if(link == NULL) link = DeclarationList(); if(link == NULL) link = SelectionStmt(); if(link == NULL) link = IterationStmt(); if(link == NULL) link = JumpStmt(); if(link == NULL) link = PrintStmt(); if(link == NULL) link = PauseStmt(); if(link == NULL) link = LabelStmt(); return link; }