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

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

View Full Document Right Arrow Icon
1 Module 29 Parse/Derivation Trees Leftmost derivations, rightmost derivations Ambiguous Grammars Examples Arithmetic expressions If-then-else Statements Inherently ambiguous CFL’s
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Context-Free Grammars Parse Trees Leftmost/rightmost derivations Ambiguous grammars
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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 ( )
Background image of page 4
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 ( )
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 ( )
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
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 Right Arrow Icon
Ask a homework question - tutors are online