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 Unlock smart solutions to boost your understanding

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

83% of Computer Science Students Improved their GPA!

Step: 2Unlock detailed examples and clear explanations to master concepts

blur-text-image_2

Step: 3Unlock to practice, ask, and learn with real-world examples

blur-text-image_3

See step-by-step solutions with expert insights and AI powered tools for academic success

  • tick Icon Access 30 Million+ textbook solutions.
  • tick Icon Ask unlimited questions from AI Tutors.
  • tick Icon 24/7 Expert guidance tailored to your subject.
  • tick Icon Order free textbooks.

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 explore these related Programming questions

Question

d. In what sports does the person consult?

Answered: 3 weeks ago