Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

YOU MAY ASSUME THAT ALL INPUT IS COMPLETELY SPACE DELIMITED (just so you don't have to alter the Lexer) AND ALL LOWER CASE (though making

YOU MAY ASSUME THAT ALL INPUT IS COMPLETELY SPACE DELIMITED (just so you don't have to alter the Lexer) AND ALL LOWER CASE (though making the parser case-insensitive would be trivial). 

For an example of SYNTACTICALLY VALID Input: see EX 2.17 in the text.

Instructions:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago