Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Do the Following: Down load parser.zip from Canvas. This file contains all the material you need. Please modify only the file prog.cpp by adding the
Do the Following:
Down load "parser.zip" from Canvas. This file contains all the material you need. Please
modify only the file prog.cpp by adding the methods you need for your parser.
Please use the following grammar:
prog begin stmtlist end
ist ; ist
;
stmt var expr
var
expr var expr
var expr
var
Implement a recursive descent parser similar to the ones we covered in class.
Note that:
we have two keywords: begin and end
we have only three valid identifier: A B and C
the grammar supports three operators: and
a semicolon is a stmt separator within stmtlist
The lexical analyzer in lexan.cpp has already been modified to recognize the tokens listed
above. You may want to compile and run testlexan.cpp with lexan.cpp to verify that this
is the case. Use the input file tptxt and create others that you find necessary. It does
not mean that any token that the lexical analyzer recognizes is a valid token for the prog
grammar above. It is the parser's job to flag invalid input due to bad tokens or invalid
statements.
Here are three examples of valid input files they appear in parser.zip and they are tp
txt tptxt and tptxt:
begin
end
begin
;
end
begin
;
;
;
end
The results appear in the file outtxt outtxt and outtxt
Remember, if we can generate a parse tree for an input file, your parser should accept the
input. Anything else should be flagged as an error.
Please see the attached txt files that can be used as input, and the out txt files that
contain the output produced.
Your code should not be limited to handle only these three examples.
Notes to Source Code:
testlexan.cpp calls lexan.cpp and tests whether lexan.cpp properly emits tokens
prog.cpp calls lexan.cpp to get next token from input
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