Question: Modify the sample code (above) to parse Programs based upon the grammar above (the resulting grammar from Exercise 2.17 in the text). NOTE that only

Modify the sample code (above) to parse "Programs" based upon the grammar above (the resulting grammar from Exercise 2.17 in the text).

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. Please no HARD-CODED file paths in submitted the source.

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."

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!