Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

10. In class we studied a top-down parser for the following grammar: < S > < assignment > | < block > < assignment

10. In class we studied a top-down parser for the following grammar:

< S > → < assignment > | < block >
< assignment > → < id > = < E > ;
< block > → "{" < S List > "}"
< S List > → { < S > } +

Let us extend < S > by while-loops and conditionals:

< S > → < assignment > | < block > | < while > | < cond >
< while > → while "(" < B > ")" < S >
< cond > → if "(" < B > ")" < S > [ else < S > ]

Give pseudo code for a top-down parser for the extended < S >, < while >, < cond >, and < S List >. Presume that you are given the function B( ) to parse Boolean expressions < B >, E( ) to parse arithmetic expressions < E >, and getToken( ) to extract the next token and assign it to the string variable t . The tokens are: <id>, while , if , else , "{", "}", "(", ")", "=", ";". The top-down parser, if correctly constructed according to this grammar, should automatically build implicit parse trees in which each else matches the closest preceding unmatched if .

Step by Step Solution

3.51 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

Enter device blockh Enter Enter include Enter device ideh Enter theme malloch Block the device Structural Block list listelem listelem Items in all bl... 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

Fundamentals of Physics

Authors: Jearl Walker, Halliday Resnick

8th Extended edition

471758019, 978-0471758013

More Books

Students also viewed these Programming questions

Question

d. In what sports does the person consult?

Answered: 1 week ago

Question

How can NAFTA be beneficial to suppliers of Walmart?

Answered: 1 week ago