midterm1

midterm1 - 2. Consider the grammar A ::= x B | C z B ::= A...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 132, Jens Palsberg Nov 2, 2005 Midterm Exam Each of the three questions is worth five points, for a total of 15 points. Write your name and id number at the top of the first page you submit. Write the solutions for diFerent questions on diFerent sheets of paper. Don’t submit this handout. 1. Consider the grammar A ::= B x | B y B ::= A y | x where { A,B } is the set of nonterminal symbols, A is the start symbol, and { x,y } is the set of terminal symbols. Give an LL(1) grammar which generates the same language as the one above, show the ±IRST and ±OLLOW sets for each nonterminal symbol in the LL(1) grammar, and the show predictive parsing table for the LL(1) grammar. Argue that the grammar is LL(1).
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2. Consider the grammar A ::= x B | C z B ::= A x C C ::= y B | where { A,B,C } is the set of nonterminal symbols, A is the start symbol, { x,y,z } is the set of terminal symbols, and denotes the empty string. Is the grammar LL(1)? Justify your answer. As part of your answer, show the IRST and OLLOW sets for each nonterminal symbol. 3. Consider the grammar A ::= x C | z B ::= y A C ::= B x | A y B where { A,B,C } is the set of nonterminal symbols, A is the start symbol, and { x,y,z } is the set of terminal symbols. The grammar is LL(1). Sketch Java code in reasonable detail for a recursive-descent parser based on the grammar. 1...
View Full Document

Ask a homework question - tutors are online