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...83% of Computer Science Students Improved their GPA!
Step: 2Unlock detailed examples and clear explanations to master concepts
Step: 3Unlock to practice, ask, and learn with real-world examples
See step-by-step solutions with expert insights and AI powered tools for academic success
- Access 30 Million+ textbook solutions.
- Ask unlimited questions from AI Tutors.
- 24/7 Expert guidance tailored to your subject.
- 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