HM8-Ambiguity-NormalForms

# HM8-Ambiguity-NormalForms - • and • concatenation •...

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

CS 341 Automata Theory Elaine Rich Homework 8 Due: Thursday, March 8, 2007 This assignment covers Sections 11.7 - 11.8. 1) Let G be the ambiguous expression grammar of Example 11.14. Show at least three different parse trees that can be generated from G for the string id + id * id * id . 2) Consider the unambiguous expression grammar G of Example 11.19. a) Trace the derivation of the string id + id * id * id in G . b) Add exponentiation ( ) and unary minus (-) to G , assigning the highest precedence to unary minus, followed by exponentiation, multiplication, and addition, in that order. 3) Let L = { w { a , b , , ε , (, ), *, + }* : w is a syntactically legal regular expression}. a) Write an unambiguous context-free grammar that generates L . Your grammar should have a structure similar to the arithmetic expression grammar G that we presented in Example 11.19. It should create parse trees that: Associate left given operators of equal precedence, and Correspond to assigning the following precedence levels to the operators (from highest to lowest):
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • * and + • concatenation • ∪ b) Show the parse tree that your grammar will produce for the string ( a ∪ b ) ba *. 4) In C Section 40.3.1, we present a simplified grammar for URIs (Uniform Resource Identifiers), the names that we use to refer to objects on the Web. a) Using that grammar, show a parse tree for: b) Write a regular expression that is equivalent to the grammar that we present. 5) Consider the grammar G = ({ S , A , B, T , a , c }, { a , c }, R , S ), where R = { S → AB , S → BA , A → a A , A → ac , B → T c , T → a T , T → a }. a) Show that G is ambiguous. b) Find an equivalent grammar that is not ambiguous. 6) Consider the fragment of a Java grammar that is presented in Example 11.20. How could it be changed to force each else clause to be attached to the outermost possible if statement? 7) Convert the following grammar to Chomsky Normal Form: S → a TV a T → a T a | b T b | ε | V V → c V c | ε...
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