Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago

Question

=+ Of the HR issues mentioned in the case,

Answered: 1 week ago