SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
Understanding Lemon generated Parser.
       When the parser receive the input Token, it also reads previous State number from the Parser stack. Using
this Token and State number Parser process with the pre calculated Tables like yy_action, yy_shift_ofst,
yy_reduce_ofst , Depends upon the values the corresponding action shift or Reduce is performed .

        Current Token with Previous State Number => Action

Parser Action :
          Shift : The Current Token with value is pushed at the top of the stack
         Reduce : The corresponding rule is applied & Parser Stack is poped. Depends upon the rule number of
The number symbols is poped from stack.
Parser Stack:
         it is associated with 4 elements :
Parser Stack Index: It is the parser index value.
State Number : it holds state number ,which is used for the calculating with next State.
Symbol Index: Symbol Index, The integer unique Symbol id.
Token Value: Token Value.
Initially Parser Stack is initializes by $ symbol

Parser Stack Index           State No                     Symbol Index                 Token Value
0                            0                            $                            0

Parser Tables:
        yy_action:      A single table containing all the possible state number
        yy_shift_ofst:  For each state, the offset into yy_action for shifting terminals into the parser stack
        yy_reduce_ofst: For each state, the offset into yy_action holds for the reducing the parse Stack
        yyRuleInfo : From the Rule Index value , we can map this array index value
            a. LHS Symbol Index : Symbol of the LHS of the given Rule Index
            b. NRHS: Number of RHS in that Rule

Algorthim:

                 Get current token ,token value
                 Do {
                    get action value
                 if(value > totalstate){
                 reduce rule of (value –totalstate)
                 }
                 else{
                 push current token with value on stack
                 do the Rule Action
                 }
                 While(push current token);



We will take a simple example of Context free Grammar(CFG) arithmetic calculator
Example1.y
program ::= expr(A) . { printf ("Result=%dn", A); }
expr(A) ::= INTEGER(B) PLUS INTEGER(C). { A = B + C ; }
expr(A) ::= INTEGER(B) TIMES INTEGER(C).{ A = B * C ; }
expr(A) ::= INTEGER(B) .
TotalState = YYNState = 7 (more info can be seen in .out file )
TotalRules = YYNRulee= 4
This CFG rules and symbol index vales as follows

Rule Index Value      Rules
0                     program    ::= expr
1                     expr ::=   expr PLUS expr
2                     expr ::=   expr TIMES expr
3                     expr ::=   INTEGER

Rules Index values are follows :


Symbol Index      Symbol Name
0                 $
1                 INTEGER
2                 PLUS
3                 TIMES
4                 error:
5                 expr: INTEGER
6                 program: INTEGER
The Expression are evaluates as follows
=3+4*5+6
=3 +20+6
=23+6
=29;




This Expression is given in code of 8 steps as follows
           1. Parse(p,INTEGER,3);
           2. Parse(p,PLUS,0);
           3. Parse(p,INTEGER,4);
           4. Parse(p,TIMES,0);
           5. Parse(p,INTEGER,5);
           6. Parse(p,PLUS,0);
           7. Parse(p,INTEGER,6);
           8. Parse(p,0,0);

static const YYACTIONTYPE yy_action[] = {
 /*    0 */    7, 5, 2, 1, 10, 13, 10, 10,          8, 13,
 /* 10 */       8, 1, 9, 13, 9, 9, 6, 12,           4, 13,
 /* 20 */       3,
};
static const signed char yy_shift_ofst[] = {
 /*    0 */ 17, 17, 17, 12, 4, 8, 0,
};

static const signed char yy_reduce_ofst[] = {
/*   0 */   11,   15,   -4,   1,   1,   1,   1,
};

}
yyRuleInfo[] = {
  { 6, 1 }, => program = INTEGER (Total RHS =1)
  { 5, 3 }, => expr = expr +expr (Total RHS =3)
  { 5, 3 },=> expr =expr *expr (Total RHS =3)
  { 5, 1 },   expr = INTEGER(Total RHS =1)
};




1.Parse(p,INTEGER,3);
   Calculate Action :
        Current Token = INTEGER = 1, Previous State = 0

        Action = yy_action[ yy_shift_ofst[Previous State]+Current Token ]
               = yy_action[yy_shift_ofst[0]+1]
               = yy_action[17+1] => 4

4 < 7 then shift Shift this token in Parser stack

Parser Stack Index       State No                  Symbol                        Value
1                        4                         INTEGER                       3
0                        0                         $                             0

2.Parse(p,PLUS,0);

1.Calculate Action
Current Token = PLUS = 2, Previous State = 4
         Action = yy_action[ yy_shift_ofst[4]+2 ]
                 = yy_action[4+2] =>10
Action value > YYNState then Reduce
10 > 7

1.Reduce Action:
   Reduce Rule Index =action value – TotalState => 10-7= 3 => expr ::= INTEGER
        ReduceToken = yyRuleinfo[3].lhs => 5 (expr : integer)
        TotalRHSSymbol = yyRuleinfo[3].nrhs => 1
   Stateno :
        get Previous Stack Index = Current Stack Index – TotalRHSSymbol
                                  = 1-1 => 0
        PreviousStateno = stack[Previous Stack Index].stateno => 0
                         =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
                         =yy_action[yy_reduce_ofst[0] +Token]
                         = yy_action[11+5] => 6

Parser Stack Index       State No                   Symbol                       Value
1                        6                          Expr=INTEGER(5)              3
0                      0                       $                            0

2.Calculate Action
Current Token = PLUS = 2, Previous State = 6

        Action = yy_action[ yy_shift_ofst[6]+2 ]
               = yy_action[0+2] =>2



Action value< yyNState then push to stack push(2,PLUS,0)

Parser Stack Index     State No                Symbol                       Value
2                      2                       PLUS(2)                      0
1                      6                       Expr=INTEGER(5)              3
0                      0                       $                            0




3.Parse(p,INTEGER,4);

Calculate Action:
         Current Token = INTEGER =1, Previous State = 2
                          =yy_action[ yy_shift_ofst[2]+1 ]
                          = yy_action[17+1] =>4
Action value< yyNState then push to stack push(4,INTEGER,4)

Parser Stack Index     State No                Symbol                       Value
3                      4                       INTEGER(1)                   4
2                      2                       PLUS(2)                      0
1                      6                       Expr=INTEGER(5)              3
0                      0                       $                            0

4.Parse(p,TIMES,0);

Calculate Action
Current Token = TIMES =3, Previous State = 4
         Action = yy_action[ yy_shift_ofst[4]+3 ]
                = yy_action[4+3] =>10
1.Reduce Action :
         Reduce Rule Index =action value – TotalState => 10-7= 3 => expr ::= INTEGER
ReduceToken = yyRuleinfo[3].lhs => 5(expr : integer)
TotalRHSSymbol = yyRuleinfo[3].nrhs => 1
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                              =3-1 => 2
PreviousStateno= stack[2].stateno => 2
         =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
         =yy_action[yy_reduce_ofst[2] +5]
         = yy_action[-4+5] => 5
Reduce stack index 3 & apply rule 3
Parser Stack Index      State No               Symbol                        Value
3                     5                        Expr=INTEGER(5)                4
2                     2                        PLUS(2)                        0
1                     6                        Expr=INTEGER(5)                3
0                     0                        $                              0

Calculate Action
Current Token = TIMES =3, Previous State = 5
         =yy_action[ yy_shift_ofst[5]+3 ]
         = yy_action[8+3] =>1
Push stack (1,Times,0);

Parser Stack Index    State No                 Symbol                         Value
4                     1                        TIMES                          0
3                     5                        Expr=INTEGER(5)                4
2                     2                        PLUS(2)                        0
1                     6                        Expr=INTEGER(5)                3
0                     0                        $                              0

5.Parse(p,INTEGER,5);

Calculate Action
Current Token = INTEGER =1, Previous State = 1
          =yy_action[ yy_shift_ofst[1]+1 ]
          = yy_action[17+1] =>4
Action value< yyNState then push to stack push(4,INTEGER,5)

Parser Stack Index    State No                 Symbol                         Value
5                     4                        INTEGER                        5
4                     1                        TIMES                          0
3                     5                        Expr=INTEGER(5)                4
2                     2                        PLUS(2)                        0
1                     6                        Expr=INTEGER(5)                3
0                     0                        $                              0

6.Parse(p,PLUS,0);
1.Calculate Action
Current Token = PLUS =2, Previous State = 4
         =yy_action[ yy_shift_ofst[4]+2 ]
         = yy_action[4+1] =>10
10 > 7 then reduce
1.Reduce Action :
Reduce Rule Index =action value – TotalState => 10-7= 3 => expr ::= INTEGER
ReduceToken = yyRuleinfo[3].lhs => 5
TotalRHSSymbol = yyRuleinfo[3].nrhs => 1
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                             =5-1 => 4
PreviousStateno= stack[4].stateno => 1
          =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
         =yy_action[yy_reduce_ofst[1] +5]
          = yy_action[15+5] => 3



apply rule 3 at stack index 5
Parser Stack Index     State No              Symbol                         Value
5                      3                     Expr=INTEGER(5)                5
4                      1                     TIMES                          0
3                      5                     Expr=INTEGER(5)                4
2                      2                     PLUS(2)                        0
1                      6                     Expr=INTEGER(5)                3
0                      0                     $                              0



2. Calculate Action
Current Token = PLUS =2, Previous State = 3
                  =yy_action[ yy_shift_ofst[3]+2 ]
                 = yy_action[12+2] =>9
9> 7 then
2.Reduce Action :
Reduce Rule Index =action value – TotalState => 9-7= 2 => expr ::= expr TIMES expr
ReduceToken = yyRuleinfo[2].lhs => 5
TotalRHSSymbol = yyRuleinfo[2].nrhs => 3
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                             =5-3 => 2
PreviousStateno= stack[2].stateno => 2
          =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
         =yy_action[yy_reduce_ofst[2] +5]
          = yy_action[-4+5] => 5




Parser Stack Index     State No              Symbol                         Value
3                      5                     Expr=INTEGER(5)                20
2                      2                     PLUS(2)                        0
1                      6                     Expr=INTEGER(5)                3
0                      0                     $                              0

3.Calculate Action

Current Token = PLUS =2,Previous State = 5
                 =yy_action[ yy_shift_ofst[5]+2 ]
                 = yy_action[8+2] =>8
8> 7 then

3.Reduce Action :
Reduce Rule Index =action value – TotalState => 8-7= 1=> expr ::= exprPLUS expr
ReduceToken = yyRuleinfo[2].lhs => 5
TotalRHSSymbol = yyRuleinfo[2].nrhs => 3
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                             =3-3 => 0
PreviousStateno= stack[2].stateno => 2
         =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
        =yy_action[yy_reduce_ofst[0] +5]
         = yy_action[11+5] => 6
Parser Stack Index     State No               Symbol                         Value
1                      6                      Expr=INTEGER(5)                23
0                      0                      $                              0



3.Calculate Action
Current Token = PLUS =2
Previous State = 6
                 =yy_action[ yy_shift_ofst[6]+2 ]
                = yy_action[0+2] =>2
2> 7 then push stack (2,PLUS,0)
Parser Stack Index      State No              Symbol                         Value
2                       2                     PLUS                           0
1                       6                     Expr=INTEGER(5)                23
0                       0                     $                              0

7.Parse(p,INTEGER,6);
Calculate Action :
Current Token = INTEGER =1, Previous State =2
                 =yy_action[ yy_shift_ofst[2]+1 ]
                  = yy_action[17+1] =>4
         Push stack(4,INTEGER,6);

Parser Stack Index     State No               Symbol                         Value
3                      4                      INTEGER                        6
2                      2                      PLUS                           0
1                      6                      Expr=INTEGER(5)                23
0                      0                      $                              0




8.Parse(p,0,0);
Calculate Action :
Current Token = $ =0,Previous State =4
                =yy_action[ yy_shift_ofst[4]+0 ]
               = yy_action[4+0] =>10

1.Reduce Action :
Reduce Rule Index =action value – TotalState => 10-7= 3=> expr ::= INTEGER
ReduceToken = yyRuleinfo[3].lhs => 5
TotalRHSSymbol = yyRuleinfo[3].nrhs => 1
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                             =3-1 => 2
PreviousStateno= stack[2].stateno => 2
         =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
        =yy_action[yy_reduce_ofst[2] +5]
         = yy_action[-4+5] => 5

Parser Stack Index     State No               Symbol                         Value
3                      5                      Expr=INTEGER(5)                6
2                      2                      PLUS                           0
1                      6                      Expr=INTEGER(5)                23
0                      0                      $                             0

1.Calculate Action :
Current Token = $ =0 , Previous State =5
                 =yy_action[ yy_shift_ofst[5]+0 ]
                = yy_action[8+0] =>8
         8-7 => rule 1
Reduce Rule Index =action value – TotalState =>8-7= 1=> expr ::= expr PLUS expr
ReduceToken = yyRuleinfo[1].lhs => 5
TotalRHSSymbol = yyRuleinfo[1].nrhs => 3
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                             =3-3 => 0
PreviousStateno= stack[0].stateno => 0
          =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
         =yy_action[yy_reduce_ofst[0] +5]
          = yy_action[11+5] => 6
Reduce Rule 1
Parser Stack Index      State No              Symbol                         Value
1                       6                     Expr=INTEGER(5)                29
0                       0                     $                              0

2. Calculate Action :
Current Token = $ =0 , Previous State =6
                 =yy_action[ yy_shift_ofst[6]+0 ]
               = yy_action[0+0] =>7
         7>7 =>

1.Reduce Action :
Reduce Rule Index =action value – TotalState => 7-7= 0=> program ::= INTEGER
ReduceToken = yyRuleinfo[0].lhs => 6
TotalRHSSymbol = yyRuleinfo[0].nrhs => 1
Stateno :
get Previous Stack Index: Current Stack Index – TotalRHSSymbol
                             =1-1 => 0
PreviousStateno= stack[0].stateno => 0
         =yy_action[yy_reduce_ofst[PreviousStateno] +Token]
        =yy_action[yy_reduce_ofst[0] +6]
         = yy_action[11+6] =>12
Parser Stack Index     State No             Symbol                         Value
1                      12                   program=INTEGER(5)             29
0                      0                    $                              0



program accept = Totalstate+totalrule+1
                 =7 + 4 +1 =>12
               Hence program accept

Contenu connexe

Tendances

Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptLoïc Knuchel
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with goEleanor McHugh
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)진성 오
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수용 최
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184Mahmoud Samir Fayed
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
 
Property-Based Testing
Property-Based TestingProperty-Based Testing
Property-Based TestingShai Geva
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptjonathanfmills
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughYoshi Watanabe
 
Jquery 13 cheatsheet_v1
Jquery 13 cheatsheet_v1Jquery 13 cheatsheet_v1
Jquery 13 cheatsheet_v1ilesh raval
 
Jquery 1.3 cheatsheet_v1
Jquery 1.3 cheatsheet_v1Jquery 1.3 cheatsheet_v1
Jquery 1.3 cheatsheet_v1Sultan Khan
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZENorvald Ryeng
 
Refactoring 메소드 호출의 단순화
Refactoring 메소드 호출의 단순화Refactoring 메소드 호출의 단순화
Refactoring 메소드 호출의 단순화HyeonSeok Choi
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with ExplainMYXPLAIN
 
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007Damien Seguy
 
Python 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets CheatsheetPython 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets CheatsheetIsham Rashik
 

Tendances (20)

Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
 
Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)Swift에서 꼬리재귀 사용기 (Tail Recursion)
Swift에서 꼬리재귀 사용기 (Tail Recursion)
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 
The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184The Ring programming language version 1.5.3 book - Part 10 of 184
The Ring programming language version 1.5.3 book - Part 10 of 184
 
Into Clojure
Into ClojureInto Clojure
Into Clojure
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
Stacks
Stacks Stacks
Stacks
 
Property-Based Testing
Property-Based TestingProperty-Based Testing
Property-Based Testing
 
A Skeptics guide to functional style javascript
A Skeptics guide to functional style javascriptA Skeptics guide to functional style javascript
A Skeptics guide to functional style javascript
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
 
Jquery 13 cheatsheet_v1
Jquery 13 cheatsheet_v1Jquery 13 cheatsheet_v1
Jquery 13 cheatsheet_v1
 
Jquery 1.3 cheatsheet_v1
Jquery 1.3 cheatsheet_v1Jquery 1.3 cheatsheet_v1
Jquery 1.3 cheatsheet_v1
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
 
Refactoring 메소드 호출의 단순화
Refactoring 메소드 호출의 단순화Refactoring 메소드 호출의 단순화
Refactoring 메소드 호출의 단순화
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with Explain
 
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007
 
Python 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets CheatsheetPython 3.x Dictionaries and Sets Cheatsheet
Python 3.x Dictionaries and Sets Cheatsheet
 

En vedette

Akshar Corporate Profile
Akshar Corporate ProfileAkshar Corporate Profile
Akshar Corporate Profileanoopkumar
 
Museu do Vaticano
Museu do VaticanoMuseu do Vaticano
Museu do Vaticanoguestededef
 
Social Media Week agency2. Be A Leader in Social Media
Social Media Week agency2. Be A Leader in Social MediaSocial Media Week agency2. Be A Leader in Social Media
Social Media Week agency2. Be A Leader in Social MediaJoel Davis
 
Agency2 social data performance social media trends 2016
Agency2 social data performance social media trends 2016Agency2 social data performance social media trends 2016
Agency2 social data performance social media trends 2016Joel Davis
 

En vedette (6)

Akshar Corporate Profile
Akshar Corporate ProfileAkshar Corporate Profile
Akshar Corporate Profile
 
TheRefCheck.com
TheRefCheck.comTheRefCheck.com
TheRefCheck.com
 
Web Presen
Web PresenWeb Presen
Web Presen
 
Museu do Vaticano
Museu do VaticanoMuseu do Vaticano
Museu do Vaticano
 
Social Media Week agency2. Be A Leader in Social Media
Social Media Week agency2. Be A Leader in Social MediaSocial Media Week agency2. Be A Leader in Social Media
Social Media Week agency2. Be A Leader in Social Media
 
Agency2 social data performance social media trends 2016
Agency2 social data performance social media trends 2016Agency2 social data performance social media trends 2016
Agency2 social data performance social media trends 2016
 

Similaire à Understanding Lemon Generated Parser

An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL乐群 陈
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithmspppepito86
 
Frsa
FrsaFrsa
Frsa_111
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data StructureChan Shik Lim
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structureShakil Ahmed
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingPrudhviVuda
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Ra'Fat Al-Msie'deen
 
Brief tour of psp-std
Brief tour of psp-stdBrief tour of psp-std
Brief tour of psp-stdPaul Phillips
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring PatternsNaresha K
 
Pratt Parser in Python
Pratt Parser in PythonPratt Parser in Python
Pratt Parser in PythonPercolate
 
Array data structure
Array data structureArray data structure
Array data structuremaamir farooq
 

Similaire à Understanding Lemon Generated Parser (20)

An Introduction to Part of C++ STL
An Introduction to Part of C++ STLAn Introduction to Part of C++ STL
An Introduction to Part of C++ STL
 
Arrays
ArraysArrays
Arrays
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
Frsa
FrsaFrsa
Frsa
 
Sorting techniques
Sorting techniques Sorting techniques
Sorting techniques
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data Structure
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Python
PythonPython
Python
 
Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"Algorithms - "Chapter 2 getting started"
Algorithms - "Chapter 2 getting started"
 
Brief tour of psp-std
Brief tour of psp-stdBrief tour of psp-std
Brief tour of psp-std
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
Groovy Refactoring Patterns
Groovy Refactoring PatternsGroovy Refactoring Patterns
Groovy Refactoring Patterns
 
Pratt Parser in Python
Pratt Parser in PythonPratt Parser in Python
Pratt Parser in Python
 
Array data structure
Array data structureArray data structure
Array data structure
 

Dernier

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Dernier (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Understanding Lemon Generated Parser

  • 1. Understanding Lemon generated Parser. When the parser receive the input Token, it also reads previous State number from the Parser stack. Using this Token and State number Parser process with the pre calculated Tables like yy_action, yy_shift_ofst, yy_reduce_ofst , Depends upon the values the corresponding action shift or Reduce is performed . Current Token with Previous State Number => Action Parser Action : Shift : The Current Token with value is pushed at the top of the stack Reduce : The corresponding rule is applied & Parser Stack is poped. Depends upon the rule number of The number symbols is poped from stack. Parser Stack: it is associated with 4 elements : Parser Stack Index: It is the parser index value. State Number : it holds state number ,which is used for the calculating with next State. Symbol Index: Symbol Index, The integer unique Symbol id. Token Value: Token Value. Initially Parser Stack is initializes by $ symbol Parser Stack Index State No Symbol Index Token Value 0 0 $ 0 Parser Tables: yy_action: A single table containing all the possible state number yy_shift_ofst: For each state, the offset into yy_action for shifting terminals into the parser stack yy_reduce_ofst: For each state, the offset into yy_action holds for the reducing the parse Stack yyRuleInfo : From the Rule Index value , we can map this array index value a. LHS Symbol Index : Symbol of the LHS of the given Rule Index b. NRHS: Number of RHS in that Rule Algorthim: Get current token ,token value Do { get action value if(value > totalstate){ reduce rule of (value –totalstate) } else{ push current token with value on stack do the Rule Action } While(push current token); We will take a simple example of Context free Grammar(CFG) arithmetic calculator Example1.y program ::= expr(A) . { printf ("Result=%dn", A); } expr(A) ::= INTEGER(B) PLUS INTEGER(C). { A = B + C ; } expr(A) ::= INTEGER(B) TIMES INTEGER(C).{ A = B * C ; } expr(A) ::= INTEGER(B) .
  • 2. TotalState = YYNState = 7 (more info can be seen in .out file ) TotalRules = YYNRulee= 4 This CFG rules and symbol index vales as follows Rule Index Value Rules 0 program ::= expr 1 expr ::= expr PLUS expr 2 expr ::= expr TIMES expr 3 expr ::= INTEGER Rules Index values are follows : Symbol Index Symbol Name 0 $ 1 INTEGER 2 PLUS 3 TIMES 4 error: 5 expr: INTEGER 6 program: INTEGER The Expression are evaluates as follows =3+4*5+6 =3 +20+6 =23+6 =29; This Expression is given in code of 8 steps as follows 1. Parse(p,INTEGER,3); 2. Parse(p,PLUS,0); 3. Parse(p,INTEGER,4); 4. Parse(p,TIMES,0); 5. Parse(p,INTEGER,5); 6. Parse(p,PLUS,0); 7. Parse(p,INTEGER,6); 8. Parse(p,0,0); static const YYACTIONTYPE yy_action[] = { /* 0 */ 7, 5, 2, 1, 10, 13, 10, 10, 8, 13, /* 10 */ 8, 1, 9, 13, 9, 9, 6, 12, 4, 13, /* 20 */ 3, }; static const signed char yy_shift_ofst[] = { /* 0 */ 17, 17, 17, 12, 4, 8, 0, }; static const signed char yy_reduce_ofst[] = {
  • 3. /* 0 */ 11, 15, -4, 1, 1, 1, 1, }; } yyRuleInfo[] = { { 6, 1 }, => program = INTEGER (Total RHS =1) { 5, 3 }, => expr = expr +expr (Total RHS =3) { 5, 3 },=> expr =expr *expr (Total RHS =3) { 5, 1 }, expr = INTEGER(Total RHS =1) }; 1.Parse(p,INTEGER,3); Calculate Action : Current Token = INTEGER = 1, Previous State = 0 Action = yy_action[ yy_shift_ofst[Previous State]+Current Token ] = yy_action[yy_shift_ofst[0]+1] = yy_action[17+1] => 4 4 < 7 then shift Shift this token in Parser stack Parser Stack Index State No Symbol Value 1 4 INTEGER 3 0 0 $ 0 2.Parse(p,PLUS,0); 1.Calculate Action Current Token = PLUS = 2, Previous State = 4 Action = yy_action[ yy_shift_ofst[4]+2 ] = yy_action[4+2] =>10 Action value > YYNState then Reduce 10 > 7 1.Reduce Action: Reduce Rule Index =action value – TotalState => 10-7= 3 => expr ::= INTEGER ReduceToken = yyRuleinfo[3].lhs => 5 (expr : integer) TotalRHSSymbol = yyRuleinfo[3].nrhs => 1 Stateno : get Previous Stack Index = Current Stack Index – TotalRHSSymbol = 1-1 => 0 PreviousStateno = stack[Previous Stack Index].stateno => 0 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[0] +Token] = yy_action[11+5] => 6 Parser Stack Index State No Symbol Value 1 6 Expr=INTEGER(5) 3
  • 4. 0 0 $ 0 2.Calculate Action Current Token = PLUS = 2, Previous State = 6 Action = yy_action[ yy_shift_ofst[6]+2 ] = yy_action[0+2] =>2 Action value< yyNState then push to stack push(2,PLUS,0) Parser Stack Index State No Symbol Value 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 3.Parse(p,INTEGER,4); Calculate Action: Current Token = INTEGER =1, Previous State = 2 =yy_action[ yy_shift_ofst[2]+1 ] = yy_action[17+1] =>4 Action value< yyNState then push to stack push(4,INTEGER,4) Parser Stack Index State No Symbol Value 3 4 INTEGER(1) 4 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 4.Parse(p,TIMES,0); Calculate Action Current Token = TIMES =3, Previous State = 4 Action = yy_action[ yy_shift_ofst[4]+3 ] = yy_action[4+3] =>10 1.Reduce Action : Reduce Rule Index =action value – TotalState => 10-7= 3 => expr ::= INTEGER ReduceToken = yyRuleinfo[3].lhs => 5(expr : integer) TotalRHSSymbol = yyRuleinfo[3].nrhs => 1 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =3-1 => 2 PreviousStateno= stack[2].stateno => 2 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[2] +5] = yy_action[-4+5] => 5 Reduce stack index 3 & apply rule 3 Parser Stack Index State No Symbol Value
  • 5. 3 5 Expr=INTEGER(5) 4 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 Calculate Action Current Token = TIMES =3, Previous State = 5 =yy_action[ yy_shift_ofst[5]+3 ] = yy_action[8+3] =>1 Push stack (1,Times,0); Parser Stack Index State No Symbol Value 4 1 TIMES 0 3 5 Expr=INTEGER(5) 4 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 5.Parse(p,INTEGER,5); Calculate Action Current Token = INTEGER =1, Previous State = 1 =yy_action[ yy_shift_ofst[1]+1 ] = yy_action[17+1] =>4 Action value< yyNState then push to stack push(4,INTEGER,5) Parser Stack Index State No Symbol Value 5 4 INTEGER 5 4 1 TIMES 0 3 5 Expr=INTEGER(5) 4 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 6.Parse(p,PLUS,0); 1.Calculate Action Current Token = PLUS =2, Previous State = 4 =yy_action[ yy_shift_ofst[4]+2 ] = yy_action[4+1] =>10 10 > 7 then reduce 1.Reduce Action : Reduce Rule Index =action value – TotalState => 10-7= 3 => expr ::= INTEGER ReduceToken = yyRuleinfo[3].lhs => 5 TotalRHSSymbol = yyRuleinfo[3].nrhs => 1 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =5-1 => 4 PreviousStateno= stack[4].stateno => 1 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[1] +5] = yy_action[15+5] => 3 apply rule 3 at stack index 5
  • 6. Parser Stack Index State No Symbol Value 5 3 Expr=INTEGER(5) 5 4 1 TIMES 0 3 5 Expr=INTEGER(5) 4 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 2. Calculate Action Current Token = PLUS =2, Previous State = 3 =yy_action[ yy_shift_ofst[3]+2 ] = yy_action[12+2] =>9 9> 7 then 2.Reduce Action : Reduce Rule Index =action value – TotalState => 9-7= 2 => expr ::= expr TIMES expr ReduceToken = yyRuleinfo[2].lhs => 5 TotalRHSSymbol = yyRuleinfo[2].nrhs => 3 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =5-3 => 2 PreviousStateno= stack[2].stateno => 2 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[2] +5] = yy_action[-4+5] => 5 Parser Stack Index State No Symbol Value 3 5 Expr=INTEGER(5) 20 2 2 PLUS(2) 0 1 6 Expr=INTEGER(5) 3 0 0 $ 0 3.Calculate Action Current Token = PLUS =2,Previous State = 5 =yy_action[ yy_shift_ofst[5]+2 ] = yy_action[8+2] =>8 8> 7 then 3.Reduce Action : Reduce Rule Index =action value – TotalState => 8-7= 1=> expr ::= exprPLUS expr ReduceToken = yyRuleinfo[2].lhs => 5 TotalRHSSymbol = yyRuleinfo[2].nrhs => 3 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =3-3 => 0 PreviousStateno= stack[2].stateno => 2 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[0] +5] = yy_action[11+5] => 6
  • 7. Parser Stack Index State No Symbol Value 1 6 Expr=INTEGER(5) 23 0 0 $ 0 3.Calculate Action Current Token = PLUS =2 Previous State = 6 =yy_action[ yy_shift_ofst[6]+2 ] = yy_action[0+2] =>2 2> 7 then push stack (2,PLUS,0) Parser Stack Index State No Symbol Value 2 2 PLUS 0 1 6 Expr=INTEGER(5) 23 0 0 $ 0 7.Parse(p,INTEGER,6); Calculate Action : Current Token = INTEGER =1, Previous State =2 =yy_action[ yy_shift_ofst[2]+1 ] = yy_action[17+1] =>4 Push stack(4,INTEGER,6); Parser Stack Index State No Symbol Value 3 4 INTEGER 6 2 2 PLUS 0 1 6 Expr=INTEGER(5) 23 0 0 $ 0 8.Parse(p,0,0); Calculate Action : Current Token = $ =0,Previous State =4 =yy_action[ yy_shift_ofst[4]+0 ] = yy_action[4+0] =>10 1.Reduce Action : Reduce Rule Index =action value – TotalState => 10-7= 3=> expr ::= INTEGER ReduceToken = yyRuleinfo[3].lhs => 5 TotalRHSSymbol = yyRuleinfo[3].nrhs => 1 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =3-1 => 2 PreviousStateno= stack[2].stateno => 2 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[2] +5] = yy_action[-4+5] => 5 Parser Stack Index State No Symbol Value 3 5 Expr=INTEGER(5) 6 2 2 PLUS 0 1 6 Expr=INTEGER(5) 23
  • 8. 0 0 $ 0 1.Calculate Action : Current Token = $ =0 , Previous State =5 =yy_action[ yy_shift_ofst[5]+0 ] = yy_action[8+0] =>8 8-7 => rule 1 Reduce Rule Index =action value – TotalState =>8-7= 1=> expr ::= expr PLUS expr ReduceToken = yyRuleinfo[1].lhs => 5 TotalRHSSymbol = yyRuleinfo[1].nrhs => 3 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =3-3 => 0 PreviousStateno= stack[0].stateno => 0 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[0] +5] = yy_action[11+5] => 6 Reduce Rule 1 Parser Stack Index State No Symbol Value 1 6 Expr=INTEGER(5) 29 0 0 $ 0 2. Calculate Action : Current Token = $ =0 , Previous State =6 =yy_action[ yy_shift_ofst[6]+0 ] = yy_action[0+0] =>7 7>7 => 1.Reduce Action : Reduce Rule Index =action value – TotalState => 7-7= 0=> program ::= INTEGER ReduceToken = yyRuleinfo[0].lhs => 6 TotalRHSSymbol = yyRuleinfo[0].nrhs => 1 Stateno : get Previous Stack Index: Current Stack Index – TotalRHSSymbol =1-1 => 0 PreviousStateno= stack[0].stateno => 0 =yy_action[yy_reduce_ofst[PreviousStateno] +Token] =yy_action[yy_reduce_ofst[0] +6] = yy_action[11+6] =>12 Parser Stack Index State No Symbol Value 1 12 program=INTEGER(5) 29 0 0 $ 0 program accept = Totalstate+totalrule+1 =7 + 4 +1 =>12 Hence program accept