TopDown ParsingPredictive Parsing dokkaras com Agenda of the









- Slides: 9

Top-Down Parsing-Predictive Parsing dokkaras. com

Agenda of the Lecture • Details of Predictive Parser (Non recursive) Introduction to the non recursive predictive parser The different components of the non recursive Predictive Parser • Procedure of Predictive Parser (Non recursive) Role played by each of the component Example

Predictive Parser-Non Recursive: Details Introduction • The predictive parser is a top-down parser and it follows a leftmost derivation. • The key problem during predictive parsing is that of determining the production to be applied for a non-terminal. Example: A α|β|γ • This is done by using a parsing table. 3

Predictive Parser-Non Recursive: Details There are four important components of a non recursive predictive parser: 1. The parsing program 2. The parsing table 3. An input buffer 4. A Stack

Predictive Parser-Non Recursive: Details • The parsing program is the one which controls the predictive parser. • A parsing table is a two-dimensional array M[A, a] where A is a nonterminal, and a is a terminal or the symbol $, meaning “end of input string”. • The input buffer, which contains the string to be parsed followed by $. • The stack which contains a sequence of grammar symbols with, initially, $S (the first symbol in the stack followed by the start symbol) in it.

Non-Recursive Predictive Parser 6

Predictive Parser: Procedure The predictive parser considers X, the symbol on top of the stack, and a, the current input symbol. If X is a terminal and If X=a=$ halt and return success If X=a≠$ pop X off the stack and advance input pointer to the next symbol If X ≠a halt and return failure If X is a non-terminal we consult the parsing table Check M[X, a] • If the entry is a production rule, then replace X on the stack by the Right Hand Side of the production • If the entry is blank, then halt and return failure 7

Predictive Parser : An Example Grammar: E TE’ E’ +TE’|ϵ T FT’ T’ *FT’|ϵ F (E)|id Consult the parsing table at M[X, a] id E E is the start symbol of the grammar The input string is Id+id*id T’ F * E TE’ ( ) $ E TE’ E’ +T E’ E’ T + E’ E’ є є T FT’ T’ є T’ *FT ’ T’ T’ є є Stack Input Output $E id+id*id$ $E’T id+id*id$ E TE’ $E’T’F id+id*id$ T FT’ $E’T’id id+id*id$ F id $E’T’ +id*id$ $E’ +id*id$ T’ є $E’T+ +id*id$ E’ +TE’ $E’T id*id$ $E’T’F id*id$ T FT’ $E’T’id id*id$ F id $E’T’ *id$ $E’T’F* *id$ $E’T’F id$ $E’T’id id$ $E’T’ F F id Parsing Table (E) $E’ Algorithm Trace $ T’ *FT’ F id $ $ T’ є $ E’ 8 є

Thank You dokkaras. com