Sie sind auf Seite 1von 24

Parsing

Algorithm to Build the Table

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Example: The Dangling Else Grammar

Generate the parse table for the following grammar:

Solution

LL(1) Grammar

LL(1) Grammar

LL(1) grammars
Are never ambiguous. Will never have left recursion.

Furthermore...
If we are looking for an A and the next symbol is b, Then only one production must be possible

LL(1) Grammar A grammar G is LL(1) if an only if whenever A a | b are two distinct productions of G the following conditions hold:
1. For no terminal a do both a and b derive strings beginning with a. 2. At most one of a and b can derive the empty string. 3. If then b * e , then a does not derive any string beginning with a terminal in FOLLOW(A).

Error Recovery
When Do Errors Occur? Recall Predictive Parser Function:
a + b $

Input

Stack

X Y Z

Predictive Parsing Program Parsing Table M[A,a]

Output

1. If X is a terminal and it doesnt match input. 2. If M[X, Input] is empty No allowable actions

Error Recovery

Error Recovery: Skip Input Symbols

Error Recovery: Pop The Stack

Error Recovery: Panic Mode

Error Recovery - Table Entries

Das könnte Ihnen auch gefallen