Balanced Parentheses G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\}

Slides:



Advertisements
Similar presentations
Early Math OrdinalandCardinalNumbers. Ordinal Numbers Early Math Move one.
Advertisements

Ordinal Numbers. Order 1,2,3,4,5,6,7,8 These numbers are in order. 1,2,4,6,5,8,7 These numbers are not in order.
Let’s repeat the ordinal numbers!
1 Parse Trees Definitions Relationship to Left- and Rightmost Derivations Ambiguity in Grammars.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Type Title Here for Tic-Tac-Toe Type names of students in group here.
1 Introduction to Computability Theory Lecture5: Context Free Languages Prof. Amos Israeli.
1 Module 28 Context Free Grammars –Definition of a grammar G –Deriving strings and defining L(G) Context-Free Language definition.
Costas Busch - RPI1 Context-Free Languages. Costas Busch - RPI2 Regular Languages.
Courtesy Costas Busch - RPI1 Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Fall 2004COMP 3351 Context-Free Languages. Fall 2004COMP 3352 Regular Languages.
1 Lecture 27 Parse/Derivation Trees –Leftmost derivations, rightmost derivations Ambiguous Grammars –Examples Arithmetic expressions If-then-else Statements.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
Fall 2005Costas Busch - RPI1 Context-Free Languages.
The Solar System. Mercury Mercury is the closest planet to the sun. Mercury is the closest planet to the sun. Mercury is the eighth largest planet. Mercury.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2005.
CMSC 330: Organization of Programming Languages
Syntax Analysis The recognition problem: given a grammar G and a string w, is w  L(G)? The parsing problem: if G is a grammar and w  L(G), how can w.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 Mälardalen University 2010.
1 Parse Trees Definitions Relationship to lm and rm Derivations Ambiguity in Grammars.
Classification of grammars Definition: A grammar G is said to be 1)Right-linear if each production in P is of the form A  xB or A  x where A and B are.
Context-Free Grammars – Derivations Lecture 15 Section 2.1 Mon, Sep 24, 2007.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
CS 3240: Languages and Computation Context-Free Languages.
Homework #3 J. H. Wang Nov. 1, Homework #3 Chap. 4 –4.1 (c) –4.7 (c) –4.8 (a)(b)(c) –4.11.
CMSC 330: Organization of Programming Languages
Degraded Photo Project Rebecca Brown. First Step:  Take cardboard, write “These are words”  Pin them to a tree  Take a photo-  Print photo off.
Multiplying Common Fractions Multiplying next Using the Corn Bread © Math As A Second Language All Rights Reserved.
Happy New Year 2012 The top ten New Year’s Resolutions.
1 Parse Trees Definitions Relationship to Left- and Rightmost Derivations Ambiguity in Grammars.
11 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 7 School of Innovation, Design and Engineering Mälardalen University 2012.
Module 29 Parse/Derivation Trees Ambiguous Grammars
Context-Free Languages. Regular Languages Context-Free Languages.
Syntax Analysis – Part I EECS 483 – Lecture 4 University of Michigan Monday, September 17, 2006.
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
By: Keaton Linford.  The moon phases start with the New Moon.  The side of the moon that is facing us is not illuminated.  A New Moon takes place when.
Stoichiometry Project Pd5 3/18/10. Problem If 4.1 grams of Cr is heated with 9.3 grams of Cl 2, what mass of CrCl 3 will be produced? next.
Example 1 Writing Powers Write the product as a power and describe it in words. a. 44= to the second power, or 4 squared 9 to the third power,
Fractions Part Two. How many halves are in a whole? 2 1/2.
Compiler Construction Lecture Five: Parsing - Part Two CSC 2103: Compiler Construction Lecture Five: Parsing - Part Two Joyce Nakatumba-Nabende 1.
CS 461 – Sept. 23 Context-free grammars Derivations Ambiguity Proving correctness.
MAP Mathematics Spring 2015 % Proficient and Advanced.
The Solar System. Mercury Mercury is the closest planet to the sun. Mercury is the closest planet to the sun.
5. Context-Free Grammars and Languages
In the Beginning God Created…
Zoom In Game.
G. Pullaiah College of Engineering and Technology
Fall Compiler Principles Context-free Grammars Refresher
Adding Like Fractions Adding Like Fractions
Use the Binomial Theorem
Use the Binomial Theorem
Relationship to Left- and Rightmost Derivations
Context Free Grammar: Parse Tree
Context-Free Grammars
Number Words 1st Grade.
Use the Binomial Theorem
Student #7 starts with Locker 7 and changes every seventh door
Context-Free Grammars 1
Relationship to Left- and Rightmost Derivations
Theory of Computation Lecture #
CFGs: Formal Definition
Fall Compiler Principles Context-free Grammars Refresher
Ms. Lindsey’s Kindergarten Class 11/1/16
Decision Maths Unit 7 Sorting Algorithms 3. Shell Sort.
Which fraction does correspond to the coloured part?
The Solar System.
The Solar System.
Presentation transcript:

Balanced Parentheses G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\}

One Derivation Tree for ()(())() G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S

First Expansion Phase G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS

Second Expansion Phase G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS SS()S

Third Expansion Phase G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S

Fourth Expansion Phase G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S

Final Expansion Phase G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S

Leftmost/Rightmost Derivations G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost:S ==> SS Leftmost: S ==> SS

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS Leftmost: S ==> SS

Second Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) Leftmost: S ==> SS ==> SSS

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) Leftmost: S ==> SS ==> SSS

Third Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S(/\) Leftmost: S ==> SS ==> SSS ==> (S)SS

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() Leftmost: S ==> SS ==> SSS ==> (S)SS

Fourth Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> (/\)SS

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS

Fifth Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S

Sixth Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S

Seventh Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() ==> S((/\))() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S ==> ()((/\))S

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() ==> S(())() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S ==> ()(())S

Eighth Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() ==> S(())() ==> (S)(())() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S ==> ()(())S ==> ()(())(S)

Leftmost/Rightmost Variables G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() ==> S(())() ==> (S)(())() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S ==> ()(())S ==> ()(())(S)

Final Derivation Steps G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S Rightmost: S ==> SS ==> S(S) ==> S() ==> SS() ==> S(S)() ==> S((S))() ==> S(())() ==> (S)(())() ==> (/\)(())() Leftmost: S ==> SS ==> SSS ==> (S)SS ==> ()SS ==> ()(S)S ==> ()((S))S ==> ()(())S ==> ()(())(S) ==> ()(())(/\)

Ambiguous Grammar G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S SS ()S /\ S ()S S ()S ()S S S ()S S S ()S S ()S ()S We’ll show a second derivation tree for the string ()(())(). This proves the grammar G is ambiguous.

Unambiguous Grammar G = (V, , S, P) V = {S}  = {(,)} Start variable is S P = { S --> (S) | SS | /\} S’ T () /\() G’ = (V’, , S’, P’) V = {S’,T}  = {(,)} Start variable is S’ P = { S’ --> S’T | /\ T --> (S’)} S’ /\ T ()S’ /\ S’ /\ T ()S’ /\ T