Question
Program 1 - Instructions program stmt_list $$ stmt_list stmt_list stmt stmt_list stmt stmt id := expr stmt read id stmt write expr stmt if condition
Program 1 - Instructions
program stmt_list $$ stmt_list stmt_list stmt stmt_list stmt stmt id := expr stmt read id stmt write expr stmt if condition then stmt_list fi condition expr relation expr expr term expr expr add_op term term factor term term mult_op factor factor ( expr ) | id add_op + add_op - mult_op * mult_op / relation < | > | <= | >= | = | !=
An id can be considered anything that is not a token above. This just follows the idea that "if it's not a keyword, it must be an identifier."
Instructions:
Modify the sample code (above) to parse "Programs" based upon the grammar above
NOTE that only the Parser and Token classes should require any changes; you may make other alterations if desired, but only these two files actually need to be changed.
The parser should "accept" valid "programs" and generate the .DOT (Graphviz) "code" necessary to draw a full parse tree.
The parser should "reject" invalid "programs" with a descriptive error message; this message should be part of output tree.
The program should accept a filename from the "Command Line" as illustrated in the example.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started