In this programming assignment, you will be building a parser for a simple programming language. A preliminary grammar rules of the language and its tokens were given in Programming Assignment 1. However, the following specification is an update to the previously introduced grammar rules of the language and its tokens. Your implementation of a parser to the language is based on the following grammar rules specified in EBNF notations.
Prog ::= PROGRAM IDENT StmtList END PROGRAM
DeclStmt ::= (INT | FLOAT) IdentList
IdentList ::= IDENT, {, IDENT}
StmtList ::= Stmt; {Stmt;}
Stmt ::= DeclStmt | ControlStmt
ControlStmt ::= AssigStmt | IfStmt | WriteStmt
WriteStmt ::= WRITE ExprList
IfStmt ::= IF (LogicExpr) ControlStmt
AssignStmt ::= Var = Expr
ExprList ::= Expr {, Expr}
Expr ::= Term {(+|-) Term}
Term ::= SFactor {( *| / | % ) SFactor}
SFactor ::= (+ | -) Factor | Factor
LogicExpr ::= Expr (== | >) Expr
Var ::= IDENT
Factor = IDENT | ICONST | RCONST | SCONST | (Expr)
Parser Requirements:
Implement a recursive-descent parser for the given simple programming language. You may use the lexical analyzer you wrote for Programming Assignment 1, OR you may use the provided implementation when it is posted. The parser should provide the following:
The results of an unsuccessful parsing are a set of error messages printed by the parser functions, as well as the error messages that might be detected by the lexical analyzer.If the parser fails, the program should stop after the parser function returns.The assignment does not specify the exact error messages that should be printed out by the parser; however, the format of the messages should be the line number, followed by a colon and a space, followed by some descriptive text. Suggested messages might include “No statements in program”, “Invalid statement”, “Missing Right Parentheis”, “Undefined Variable”, “Missing END”, etc.
Provided Files
You are given the header file for the parser, “parse.h” and an incomplete file for the “parse.cpp”. You should use “parse.cpp” to complete the implementation of the parser. In addition, “lex.h”, “lex.cpp”, and “prog2.cpp” files are also provided. See the details of the description of each the file in the assignment handout.