/* <Rat11F> ::= # <Opt Function Definitions> # <Opt Declaration List> <Statement List> # */ void SyntaxAnalyzer::Rat11f() { // start it off NextRecord(); if(rrr == s_pound) { NextRecord(); OptFunctionDefinitions(); // will return with next next record as a # if(rrr == s_pound) { NextRecord(); OptDeclarationList(); StatementList(); if(rrr == s_pound) { NextRecord(); logger.Log("<Rat11F> ::= # <Opt Function Definitions># <Opt Declaration List> <Statement List> #"); } else { insert(s_pound); } } else { insert(s_pound); } } else { insert(s_pound); } }
bool syntaxparser::Function(){ bool bFunction = false; if (displayFlag){ cout<<"<Function> ::= function <identifier> [ <Opt Parameter List> ] <Opt Declaration List> <Body>"<<endl; printproduction("<Function> ::= function <identifier> [ <Opt Parameter List> ] <Opt Declaration List> <Body>"); } print(); if( lexeme == "function"){ Lexer(); print(); if(token == "identifier"){ Lexer(); print(); if(lexeme == "["){ Lexer(); if(OptParameterList()){ if(lexeme == "]"){ print(); Lexer(); cout<<endl; if(OptDeclarationList()){ if(Body()){ bFunction = true; } } }else error("Missing ']'"); } }else{ error("Missing '[' separator"); } }else{ error("Missing identifier"); } } return bFunction; }
/* <Function> ::= function <Identifier> ( <Opt Parameter List> ) <Opt Declaration List> <Body> */ void SyntaxAnalyzer::Function() { if(rrr == k_function) { NextRecord(); if(rrr == Identifier) { NextRecord(); if(rrr == s_openbracketround) { NextRecord(); OptParameterList(); if(rrr == s_closebracketround) { NextRecord(); OptDeclarationList(); Body(); logger.Log("<Function> ::= function <Identifier> ( <Opt Parameter List> ) <Opt Declaration List> <Body>"); } else { insert(s_closebracketround); } } else { insert(s_openbracketround); } } else { insert(Identifier, "MISSING IDENTIFIER"); } } else { insert(k_function); } }
void syntaxparser::Rat10F(){ setDisplay(); Lexer(); print(); if( lexeme == "$$"){ if (displayFlag){ //cout << "<Rat10F> ::= $$<Opt Function Definitions> $$ <Opt Declaration List> <Statement List> $$" << endl; //printproduction("<Rat10F> ::= $$<Opt Function Definitions> $$ <Opt Declaration List> <Statement List> $$"); cout << "<Rat10F> ::= $$ $$ <Opt Declaration List> <Statement List> $$" << endl; printproduction("<Rat10F> ::= $$ $$ <Opt Declaration List> <Statement List> $$"); } //OptFunctionDefinitions(); Lexer(); if( lexeme == "$$"){ Lexer(); OptDeclarationList(); project3.StopAddingtoSymbolTable(); StatementList(); //project3.printsymboltable(assemblyfilename); project3.printInstTable(assemblyfilename); // printing the project3 instruction table to file if( lexeme == "$$"){ print(); cout<<"========>>>>> Syntax is Correct! <<<<<=========="<<endl; } else if( lexeme != "$$") error("Missing Finishing $$"); } else if( lexeme != "$$") error("Missing $$ after Function definitions"); } else if( lexeme != "$$") error("Missing $$"); }