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

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

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 different questions on different 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 FIRST and FOLLOW 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).
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern