parsing

24
Parsing

Upload: loving-heart

Post on 29-Nov-2015

6 views

Category:

Documents


0 download

DESCRIPTION

Parsing (Lecture - 12)Lecturer: Nawshin Tabassum

TRANSCRIPT

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) 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

LL(1) Grammar

• A grammar G is LL(1) if an only if whenever A are two distinct productions of G the following conditions hold:1. For no terminal a do both and derive strings

beginning with a.

2. At most one of and can derive the empty string.

3. If then * then does not derive any string beginning with a terminal in FOLLOW(A).

Error Recovery

a + b $

Y

X

$

Z

Input

Predictive Parsing Program

Stack Output

Parsing Table M[A,a]

When Do Errors Occur? Recall Predictive Parser Function:

1. If X is a terminal and it doesn’t 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