Consider the following LL(1) grammar for a simplified subset of Lisp: P E $$ E
Question:
Consider the following LL(1) grammar for a simplified subset of Lisp:
P → E $$
E → atom
→ ’ E
→ ( E Es )
Es → E Es
→
(a) What is FIRST(Es)? FOLLOW(E)? PREDICT(Es → ∈)?
(b) Give a parse tree for the string (cdr ‚(a b c)) $$.
(c) Show the left-most derivation of (cdr ‚(a b c)) $$.
(d) Show a trace, in the style of Figure 2.21, of a table-driven top-down parse of this same input.
(e) Now consider a recursive descent parser running on the same input.
At the point where the quote token (’) is matched, which recursive descent routines will be active (i.e., what routines will have a frame on the parser’s run-time stack)?
Figure 2.21:
Transcribed Image Text:
Parse stack Input stream Comment program read A read B ... initial stack contents predict program stmt list $$ predict stmtJist stmt stmt list stmt list $$ read A read B stmt stmt list $$ read A read B read id stmnt Jist $$ read A read B predict stmt + read id id stmt-list $$ A read B... match read stmt list $$ read B sum : match id stmt stmt Jist $$ predict stmt Jist – stmt stmt Jist read B sum: read id stmtlist $$ read B sum : predict stmt + read id id stmtlist $$ B sum :=... match read stmtlist $$ sum := A + B match id ... stmt stmt list $$ id := expr stmt_list $$ predict stmt Jist → stmt stmtlist predict stmt - id := expr sum := A + B sum := A + B := expr stmtlist $$ expr stmt list $$ term term_tail stmt list $$ factor factor_tail term.tail stmt.list $$ id factor_tail term_tail stmtlist $$ factor_tail term tail stmt list $$ := A + B... match id A + B... match := A + B predict expr + term term_tail predict term factor factor.tail predict factor id ... A + B A + B + B write sum match id + B write sum + B write sum + B write sum predict factor_tail € predict term tail + add_op term term tail predict add_op -+ term tail stmt list $$ add_op term term.tail stmt list $$ + term term tail stmtlist $$ term term_tail stmt.list $$ B write sum match + factor factor_tail term tail stmt.list $$ id factor_tail term_tail stmtlist $$ factor_tail term tail stmtlist $$ term tail stmt list $$ predict term + factor factor.tail predict factor +id B write sum B write sum write sum. write sum write .. predict factor_tail € match id predict term tail € predict stmtJist stmt stmt list predict stmt write expr stmtlist $$ write sum write ... write sum write... write sum write... stmt stmtlist $$ write expr stmt Jist $$ expr stmt list $$ term term_tail stmt.list $$ factor factor_tail term_tail stmt list $$ id factor_tail term tail stmt list $$ factor_tail term tail stmtlist $$ termtail stmt.list $$ sum write sum / 2 match write predict expr - term term tail predict term factor factor.tail predict factor id sum write sum / 2 sum write sum / 2 sum write sum / 2 write sum / 2 write sum / 2 write sum / 2 match id predict factor_tail € predict term tail € stmt list $$
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 63% (11 reviews)
a atom atom b c P E E Es cdr Es cdr E Es cdr E Es cdr E Es Es cdr ...View the full answer
Answered By
Gaurav Soni
Teaching was always an area where I can pursue my passion. I used to teach my friends and junior during my school and college life. After completing my professional qualification (chartered accountancy) and before joining my job, I also joined an organization for teaching and guidance to my juniors. I had also written some articles during my internship which later got published. apart from that, I have also given some presentations on certain amendments/complex issues in various forms.
Linkedin profile link:
https://www.linkedin.com/in/gaurav-soni-38067110a
5.00+
7+ Reviews
13+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Consider the grammar S-ABCI DcA A a AdlEIc E ele C- cle D-dDlE 1. Show that the grammar has a predictive recursive descent parser. You should show that the conditions of predictive parsing apply for...
-
Consider the case study presented in Section 15.5 involving the Texago Corp. site selection problem. Texago management has tentatively chosen St. Louis as the site of the new refinery. However,...
-
Consider the grammar S A b C| D c A A a A d | E | f E e | C c | D d D | 3.1. Show that the grammar has a predictive recursive descent parser. You should show that the conditions of predictive...
-
9. Let x = (1.11... 111000...) 26, in which the fractional part has 26 1's followed by O's. For the Marc-32, determine x, x+, f(x), x-xx-x, xx, and lx-fl(x)/x.
-
Explain the behavioral and cognitive approaches to learning. Which is most relevant to training? Explain your answer.
-
Required information The Foundational 15 (Algo) [LO14-2, LO14-3, LO14-4, LO14-5, LO14-6] [The following information applies to the questions displayed below.] Markus Company's common stock sold for...
-
When using guideline public company multiples, should appraisers apply control premiums to the resulting marketable minority value indications?
-
How does budgeting provide important information to managers and operating personnel?
-
eBook Calculator Production data show 35,980 units were transferred out of a stage of production and 6,000 units remained in ending WIP inventory that was 100% complete to material and 35% complete...
-
2. You are given a 2 M stock NaCl solution. In your own words, write a brief description of the procedure required to make 10 mL each of the following NaCl concentrations: 1.5 M, 1 M, and 0.5 M....
-
Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples: abs := n if n < 0 then abs := 0 - abs fi sum := 0 read count while...
-
Write top-down and bottom-up grammars for the language consisting of all well-formed regular expressions. Arrange for all operators to be left associative. Give Kleene closure the highest precedence...
-
The matrix A is given as a. Find A 2 and A 3 . b. Determine An. (you do not need to prove your result. 2. 0 A = -1 0 -1 0 1,
-
How do you manage global and international teams? What would you do different?
-
Your friend is super excited about the results of their study! They examined whether different parenting styles [A] resulted in differences in anxiety levels among children. The different levels (a)...
-
Test the series for convergence or divergence. n=1 e1/n 78 O convergent O divergent
-
How do employees perceive the organization's vision and mission, and to what extent do these perceptions influence their commitment to the organization ?
-
In the table below which shows class taken and grade achieved, find the probability that a student selected takes Stat or receives a B grade. Round your answer to three decimal places 40 70 70 50 40...
-
A $200,000 mortgage loan at 6.6% compounded semiannually has a 25-year amortization period. a. Calculate the monthly payment b. If the interest rate were 1% lower (that is, 5.6% compounded...
-
Federated Shipping, a competing overnight delivery service, informs the customer in Problem 65 that they would ship the 5-pound package for $29.95 and the 20-pound package for $59.20. (A) If...
-
One queue implementation discussed in this chapter dedicated an unused cell before the front of the queue to distinguish between a full queue and an empty queue. Write another queue implementation...
-
Implement the following specification for an integer function in the client program that returns the number of items in a queue. The queue is unchanged. int GetLength(QueType queue) Function:...
-
Implement the following specification for a Boolean function in the client program that returns true if two queues are identical and false otherwise. You may use any of the member functions of...
-
You are evaluating a new project for the firm you work for, a publicly listed firm. The firm typically finances new projects using the same mix of financing as in its capital structure, but this...
-
state, "The subscription price during a rights offering is normally r; lower ; lower r; higher er; higher than the rights-on price and
-
Arnold inc. is considering a proposal to manufacture high end protein bars used as food supplements by body builders. The project requires an upfront investment into equipment of $1.4 million. This...
Study smarter with the SolutionInn App