HM8-Ambiguity-NormalForms

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

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

View Full Document Right Arrow Icon
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):
Background image of page 1
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

This note was uploaded on 12/03/2009 for the course CS 341 taught by Professor Rich during the Fall '08 term at University of Texas.

Ask a homework question - tutors are online