1 / 18

PARSING

PARSING. Lecture # 14 Naveen Z Quazilbash. Overview. Parsing Simple grammars-if time permits Reading assignment Quiz no.2. Parsing. Given a string w and a grammar, determine whether the grammar generates w. Finding a derivation of w is called Parsing. E.g. S aSb|bSa|SS | ε

selena
Download Presentation

PARSING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PARSING Lecture # 14 Naveen Z Quazilbash

  2. Overview • Parsing • Simple grammars-if time permits • Reading assignment • Quiz no.2

  3. Parsing • Given a string w and a grammar, determine whether the grammar generates w. • Finding a derivation of w is called Parsing. • E.g. SaSb|bSa|SS|ε w=aabb • Parsing: S=>aSb=>aaSbb=>aabb

  4. Parsing • Brute-force Technique (Exhaustive Search): • Determine everything that can be generated in one production (first “round”). • In two productions (second “round”). • In three productions….. • Terminate after generating w • We can discard intermediate results that do not match w.

  5. Example: • On board

  6. Parsing • Problems: • Very slow • May go in cycles: S=>SS=>S=>SS=>S=>…. • If w is not in the language, may not terminate. • To avoid cycles, get rid of the following types of productions: • Aε (empty string) • AB (replacing a variable with another variable)

  7. Parsing • If the language does not include empty string, then we can get rid of these production types. • E.g. for the language above: • SaSb|bSa|SS|ab|ba • It no longer includes ε

  8. Parsing • Example without undesirable productions: SaC|bD CbC|a DbD|b • If we use a grammar without undesirable productions, then at each step either: • The string gets longer or • We reduce the number of variables and the string (still) does not get shorter Instruction: Copy this grammar

  9. Parsing • Example: • S=>aC=>abC=>aba • Thus, we cannot get into a cycle. Longer string Longer string Fewer variables

  10. Parsing • Very slow • To avoid infinite search for a derivation of w: • Terminate when the string has more than |w| characters. • If we have no undesirable productions, the string does not get shorter, so it is a “safe termination”.

  11. Parsing • Example: w=aaa • On board • Can this be derived or not?

  12. Parsing • Remarks: • The time of this exhaustive search is exponential • There is a more efficient algorithm with running time proportional to |w|2- still too slow. • Some special cases allow faster parsing. E.g. simple grammars( aka s-grammars).

  13. Simple Grammars-if time permits • Lets first have a look at the assignment and quiz!! • 

  14. Reading Assignment • Explore 5.2, 5.2.1, 5.2.2 from Ullman. • Reference Book: • Peter Linz, An introduction to formal languages and automata, Third edition • Motivation: the final term paper might include terminologies and concepts from this assignment.

  15. Assignment # 3-Redo • Explore “Rightmost” and “Leftmost” derivations. • Explore “Parse Trees”. • Give one example of each. • Total points=6

  16. Quiz # 2 Q1: Consider the following grammar: (3 points) SSA | A AaAb | ε • Show a left-most derivation, right-most derivation, and derivation tree for the string abaabb

  17. Q2: the following grammar generates the language of RE 0*1(0+1)*: (3 points) SA1B A0A|ε B0B|1B| ε • Give leftmost and rightmost derivations of the string 00101. • Also draw parse trees for the derivation.

  18. BONUS Qn: Design a context-free grammar for the following language: The set {0n1n|n≥1}, that is, the set of all strings of one or more 0’s followed by an equal number of 1’s. 5 points

More Related