# Module29 - Module 29 Parse/Derivation Trees Leftmost...

This preview shows pages 1–8. Sign up to view the full content.

1 Module 29 Parse/Derivation Trees Leftmost derivations, rightmost derivations Ambiguous Grammars Examples Arithmetic expressions If-then-else Statements Inherently ambiguous CFL’s

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Context-Free Grammars Parse Trees Leftmost/rightmost derivations Ambiguous grammars
3 Parse Tree Parse/derivation trees are structured derivations The structure graphically illustrates semantic information about the string Formalization of concept we encountered in regular languages unit Note, what we saw before were not exactly parse trees as we define them now, but they were close

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Parse Tree Example Parse tree for string ( )(( )) and grammar BALG BALG = (V, Σ, S, P) V = {S}, Σ = {(, )}, S = S P = S SS | (S) | λ One derivation of ( )(( )) S ==> SS ==> (S)S ==> ( )S ==> ( )(S) ==> ( )((S)) ==> ( )(( )) Parse tree λ S S S S S ( ( ) ) λ S ( )
5 Comments about Example * Syntax: draw a unique arrow from each variable to each character that is a direct child of that variable A line instead of an arrow is ok The derived string can be read in a left to right traversal of the leaves Semantics The tree graphically illustrates the nesting structure of the string of parentheses λ S S S S S ( ( ) ) λ S ( )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Leftmost/Rightmost Derivations There is more than one derivation of the string ( )(( )). S ==> S S ==> ( S )S ==>( )S ==> ( )(S) ==> ( )((S)) ==> ( )(( )) S ==> S S ==> (S) S ==> ( S )(S) ==> ( )(S) ==> ( )((S)) ==> ( )(( )) S ==> S S ==> S( S ) ==> S(( S )) ==> S(( )) ==> (S)(( )) ==>( )(( )) Leftmost derivation Leftmost variable is always expanded Which one of the above is leftmost? Rightmost derivation Rightmost variable is always expanded Which one of the above is rightmost? λ S S S S S ( ( ) ) λ S ( )
7 Comments Fix a string and a grammar Any derivation corresponds to a unique parse tree Any parse tree can correspond to many different derivations Example The one parse tree corresponds to all three derivations Unique mappings For any parse tree, there is a unique leftmost/rightmost

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 07/25/2008 for the course CSE 460 taught by Professor Torng during the Fall '07 term at Michigan State University.

### Page1 / 24

Module29 - Module 29 Parse/Derivation Trees Leftmost...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online