Question
If someone can help me with the recursive descent parsing, it woule be very helpful. This problem should be completed with only c without using
If someone can help me with the recursive descent parsing, it woule be very helpful.
This problem should be completed with only c without using lex or yacc.
Problem LL(1) Grammars and Recursive Descent Parsing
The Grammar::
<program> ::= program <block> .
<block> ::= begin <stmtlist> end
<stmtlist> ::= <stmt> <morestmts>
<morestmts> ::= ; <stmtlist
<stmt> ::= <assign> | <ifstmt> | <whilestmt> | <block>
<assign> ::= <variable> = <expr>
<ifstmt> ::= if <testexpr> then <stmt> else <stmt>
<whilestmt> ::= while <testexpr> do <stmt>
<testexpr> ::= <variable> <= <expr>
<expr> ::= + <expr> <expr> | <expr> <expr> | <variable> | <digit>
<variable> :: = a | b | c
<digit> :: = 0 | 1 | 2
Write a recursive descent parser for the above grammar.
Modify your recursive descent parser so that it prints the number of assignment statements in the input program after it successfully parsed the program, and the number of variable references. For the program listed below, your parser should print 4 assignments, 13 variable references. Note that a statement such as a = + a a has three references, not just one.
program
begin
if b <= 0 then
while a <= 1 do
begin
a = + a b;
c = + a 1
end
else
begin
a = * a b
end;
c = + a b
end.
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