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: 60% (10 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.
-
Describe how the class enrollment application at your university could benefit from a mobile application that uses the cloud.
-
A vertical plate \(3 \mathrm{~m}\) long is at a temperature of \(400 \mathrm{~K}\) and exposed to air at \(300 \mathrm{~K}\). Calculate the thickness of the boundary layer and the value of the local...
-
1. What are some key differences between the JetBlue and West Jet software implementations? 2. What are the advantages and disadvantages of communicating a major project in advance? 3. What are the...
-
E 4 . 1 7 ( LO 4 ) These financial statement items are for Basten Company at year - end, July 3 1 , 2 0 2 2 . Salaries and wages payable $ 2 , 0 8 0 Notes payable ( due after 2 0 2 3 ) $ 1 , 8 0 0...
-
What characteristics of an airplane would you attribute to the system as a whole rather than to a collection of its parts? Explain why.
-
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...
-
When do you use the hypergeometric distribution instead of the binomial distribution?
-
What is the impact of behavioral Financial biases and demographic factors with financial risk tolerance with the moderating role of personality traits in a Pakistan stock market?
-
Student Bank is an online bank focused on students. In 2022, Student Bank had $100 million in loans it retained and $50 million in pass-through loans. It earned 19% interest and 3% origination fee on...
-
Considering that the relationship between employee and company is a fair exchange, make a list of what I can give your company (beyond spending time), and what my company might give me in return...
-
How do businesses account for at least two long-term liabilities?
-
Explain how a deviation from a cash-flow budget could lead to larger interest charges for a nonrevolving line of credit, even if the loan was originally designed at the beginning of the year to be...
-
Heat Publishing Ltd. completed the following transactions during 2013 and 2014. 2013 Dec. 6 Purchased 1,000 shares of Georgian Graphics Inc. at a price of $41.00 per share, intending to sell the...
-
Outline a general process applicable to most control situations. Using this, explain how you would develop a system to control home delivery staff at a local pizza shop.
-
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...
-
Factory overhead of $44,700 consists of Indirect labor of $21,900, Depreciation expense-Factory of $16,900, and Factory utilities of $5,900. a. Compute total manufacturing costs. b. Prepare a...
-
In Giannakakos et al. (2016), titled Using Video Modeling with voiceover Instruction plus feedback to train staff to implement direct teaching procedures, why do you think collecting data on the...
-
Presidio, Inc., produces one model of mountain bike. Partial information for the company follows: Required: 1. Complete Presidios cost data table. 2. Calculate Presidios contribution margin ratio and...
Study smarter with the SolutionInn App