Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(20) Parsing Consider the CFG for in the slides (of L6) for parsing (Page 16), and an input program sum := A + B write

image text in transcribed

image text in transcribed

image text in transcribed

(20) Parsing Consider the CFG for in the slides (of L6) for parsing (Page 16), and an input program sum := A + B write sum. (a) Trace the table driven parser as done in the class discussion. You can use a table for tracing as we did in L6 slides. (b) Trace the recursive descent parser (starting from the main function in P29 of L6 slides). You may write the function call sequences (and changes of global variable input_token) in executing the parser on the input program as shown below. If any function is missing, you can create your own following the problem decomposi- tion method we used during class. Note. To design the recursive descent parser, the best way is still the use of problem decomposition method following each pro- duction. This tracing just help you to see that it does work. program () | --stmt_list() // input_token: sum | ----stmt () // input_token: ? -stmt_list() // input_token: ? | --match ($$) outputs true/false which is returned LL(1): example grammar 1. $ $ 2. 3. id : = | read id | write 4. + E 6. * 7. | 8. ( ) | id | number 9. 10. - Main function input_token: current token of the input program. A global variable main () { // get the first token input_token = scan () ; return (program () ); } 29 (20) Parsing Consider the CFG for in the slides (of L6) for parsing (Page 16), and an input program sum := A + B write sum. (a) Trace the table driven parser as done in the class discussion. You can use a table for tracing as we did in L6 slides. (b) Trace the recursive descent parser (starting from the main function in P29 of L6 slides). You may write the function call sequences (and changes of global variable input_token) in executing the parser on the input program as shown below. If any function is missing, you can create your own following the problem decomposi- tion method we used during class. Note. To design the recursive descent parser, the best way is still the use of problem decomposition method following each pro- duction. This tracing just help you to see that it does work. program () | --stmt_list() // input_token: sum | ----stmt () // input_token: ? -stmt_list() // input_token: ? | --match ($$) outputs true/false which is returned LL(1): example grammar 1. $ $ 2. 3. id : = | read id | write 4. + E 6. * 7. | 8. ( ) | id | number 9. 10. - Main function input_token: current token of the input program. A global variable main () { // get the first token input_token = scan () ; return (program () ); } 29

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

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

define EFFECTIVE PARTICIPATION

Answered: 1 week ago