Presentation is loading. Please wait.

Presentation is loading. Please wait.

Instructor: Laura Kallmeyer

Similar presentations


Presentation on theme: "Instructor: Laura Kallmeyer"— Presentation transcript:

1 Instructor: Laura Kallmeyer
Unger's Parser. Course: Parsing 2009/10 Instructor: Laura Kallmeyer Authors: Georgi Boychev Rafał Kała Ildus Mukhametov

2 Outline: Introduction.
Unger's parser without epsilon and loops, examples. Unger's parser with epsilon and loops, examples. Conclusions.

3 Introduction. A parser is a device that accepts a word w and a grammar G as input and that 1. decides whether w is in the language generated by the grammar and 2. if so, it provides a syntactic analysis for w or, if w is ambiguous, a set of analyses.

4 Types of parsing. The task of the parser is to determine how the input can be derived from the start symbol of the grammar. This can be done in two ways: 1. Top-down parsing - search for parse trees using a top-down expansion of the given formal grammar rules. 2. Bottom-up parsing - start with the input and attempt to rewrite it to the start symbol.

5 Unger's parser. Top-down parsing. Non-directional.
We need context-free grammar and input sentence.

6 Why do we partition? The process of Unger parsing is similar to guessing. We want to check whether the input sentence matches the grammar by trying all the possible paths in our derivation tree. This leads us to the table of potential partitions.

7 Partitioning. Firstly we will focus on Unger parsing without ε-productions, because examples with ε- productions can lead to loops, as we will see in the following examples. Loops bring us no production therefore we should avoid them.

8 Partitioning without ε-rules.
Suppose that we have a grammar rule S → ABC|DE|F and an input sentence „pqrs”. We create all possible partitions for right-hand side elements.

9 An example for creating all possible partitions and choosing the correct one.
We choose the correct one by applying recursive Unger parsing to all elements of the input sentence. We stop when no non-terminals are remaining. The grammar: Expr → Expr + Term | Term Term → Term * Factor | Factor Factor → ( Expr ) | i The input sentence: (i + i) * i

10 This path is a failure, because factor has to match only one terminal.

11 Here we try the other right-hand side element for Expr.
Expr → Expr + Term | Term

12 Partitioning with ε-rules.
Introducing ε-rules adds more complexity to the partitioning tables, as illustrated by the following example: The grammar rule is: S → ABC The input sentence is: pqr More partitions will appear, as A,B, and C may derive the empty string (ε) now...

13 Partitioning table with ε-rule:

14 A case involving a loop:
Suppose, there is a rule: B → SD, then we get this table: the last line of the table will cause a trouble, as we can spin off into a loop, asking what the output of S is... If we run into a case where a loop is possible, we need to cut it off by assuming that the search has failed.

15 Cutting off. Grammar: S → LSD | ε L → ε D → d Question: S → d?
Whenever in the course of our derivation we meet the same question more than once, it means we've entered the loop. Being in a loop does not get us anywhere, so we cut that path off.

16 Cutting-off.

17 Conclusion How does Unger's method work:
Generate all partitions of the input Optimize by eliminating all partitions that do not match the terminal symbol on the right side Check if the search succeeds for the rest, ignoring cases of loops


Download ppt "Instructor: Laura Kallmeyer"

Similar presentations


Ads by Google