Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7.3. Top-Down Syntax-Directed Translation 249 procedure START switch (.. case ts.PEEK) Enum, lparen ans VALUE( ) call MATCH($) call PRINT(ans) end function Value) returns int

image text in transcribed image text in transcribed

7.3. Top-Down Syntax-Directed Translation 249 procedure START switch (.. case ts.PEEK) Enum, lparen ans VALUE( ) call MATCH($) call PRINT(ans) end function Value) returns int switch ...) Chapter 7. Syntax-Directed Translation case ts.PEEK) Enum call MATCH(num) ans num. VALUEF( ) return (ans) 1 Start Value $ 2 Value-, num 4 Expr plus Value Value 6 Values Value Values I Iparen Expr rparen case ts. PEEK) E (Iparen] I prod Values call MATCH Iparen) ans EXPR( call MATCH(rparen) return (ans) Figure 7.9: Grammar for Lisp-like expressions end function ExpR() returns int Exercises switch .) 273 case ts.PEEK) Eplus] call MATCH(plus) op1 VALUE( ) 2 VALUE( ) return (opl+ op2) case ts.PEEK) E fprod) call MATCH(prod) ans VALUES( 1 ) 4. Consider the addition of the the rule Expr sum values to the grammar in Figure 7.9 (a) Does this change make the grammar ambiguous? (b) Is the grammar still LL(1) parseable? (c) Show how the semantic actions in Figure 7.10 must be changed to accommod necessary but avoid use of global variables. ate this new language construct; modify the grammar if return (ans) end function Values(thus far) returns int case ts. PEEK) E Inum, Iparen next VALUE( ) ans VALUES(thusfarx next) return (ans) case ts. PEEK) Erparen return (thus far) end Figure 7.10: Recursive-descent parser with semantic actions. The variable ts is the token stream produced by the sca PiC.COLLAGE 7.3. Top-Down Syntax-Directed Translation 249 procedure START switch (.. case ts.PEEK) Enum, lparen ans VALUE( ) call MATCH($) call PRINT(ans) end function Value) returns int switch ...) Chapter 7. Syntax-Directed Translation case ts.PEEK) Enum call MATCH(num) ans num. VALUEF( ) return (ans) 1 Start Value $ 2 Value-, num 4 Expr plus Value Value 6 Values Value Values I Iparen Expr rparen case ts. PEEK) E (Iparen] I prod Values call MATCH Iparen) ans EXPR( call MATCH(rparen) return (ans) Figure 7.9: Grammar for Lisp-like expressions end function ExpR() returns int Exercises switch .) 273 case ts.PEEK) Eplus] call MATCH(plus) op1 VALUE( ) 2 VALUE( ) return (opl+ op2) case ts.PEEK) E fprod) call MATCH(prod) ans VALUES( 1 ) 4. Consider the addition of the the rule Expr sum values to the grammar in Figure 7.9 (a) Does this change make the grammar ambiguous? (b) Is the grammar still LL(1) parseable? (c) Show how the semantic actions in Figure 7.10 must be changed to accommod necessary but avoid use of global variables. ate this new language construct; modify the grammar if return (ans) end function Values(thus far) returns int case ts. PEEK) E Inum, Iparen next VALUE( ) ans VALUES(thusfarx next) return (ans) case ts. PEEK) Erparen return (thus far) end Figure 7.10: Recursive-descent parser with semantic actions. The variable ts is the token stream produced by the sca PiC.COLLAGE

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

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions