Non- Recursive Predictive Parsing.pptx

1,124 views 9 slides Apr 24, 2023
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

Compiler Design


Slide Content

Non- Recursive Predictive Parsing  

Non- Recursive Predictive Parsing   Non-Recursive predictive parsing uses a parsing table that shows which production rule to select from several alternatives available for expanding a given non-terminal and the first terminal symbol that should be produced by that non-terminal . The parsing table consists of rows and columns where there are row for each non-terminal and a column for each terminal symbol including S, the end marker for the input string.  

non-recursive parser  Components This non-recursive parser looks up which product to be applied in a parsing table. A LL(1) parser has the following components: (1) buffer: an input buffer which contains the string to be passed (2) stack: a pushdown stack which contains a sequence of grammar symbols (3) A parsing table: a 2d array M[A, a] where A->non-terminal, a->terminal or $ (4) output stream: end of the stack and an end of the input symbols are both denoted with $

Algorithm for non recursive Predictive Parsing:   The main Concept ->With the help of  FIRST() and FOLLOW() sets , this parsing can be done using just a stack that avoids the recursive calls . For each rule, A->x in grammar G:  For each terminal ‘a’ contained in  FIRST(A)  add A->x to M[A, a] in the parsing table if x derives ‘a’ as the first symbol.    If FIRST(A) contains null production for each terminal ‘b’ in  FOLLOW(A) , add this production (A->null) to M[A, b] in the parsing table. 

LR Parser

LR Parser LR parsing is one type of bottom up parsing. It is used to parse the large class of grammars. In the LR parsing, "L" stands for left-to-right scanning of the input. "R" stands for constructing a right most derivation in reverse. "K" is the number of input symbols of the look ahead used to make number of parsing decision.

Types of LR Parser LR parsing is divided into four parts: LR (0) parsing, SLR parsing, CLR parsing and LALR parsing.

LR algorithm The LR algorithm requires stack, input, output and parsing table. In all type of LR parsing, input, output and stack are same but parsing table is different .

Input buffer is used to indicate end of input and it contains the string to be parsed followed by a $ Symbol. A stack is used to contain a sequence of grammar symbols with a $ at the bottom of the stack. Parsing table is a two dimensional array. It contains two parts: Action part and Go To part.
Tags