Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago