SlideShare a Scribd company logo
Parsing Methods
Parsing
Top down parsing Bottom up parsing (Shift reduce)
Back tracking
Parsing without
backtracking (predictive
Parsing)
LR parsing
Operator precedence
LALR
CLR
SLR
Recursive
descent
LL(1)
Operator precedence parsing
• Operator Grammar: A Grammar in which there is no Є in RHS of any production
or no adjacent non terminals is called operator grammar.
• Example: E EAE | (E) | id
A + | * | -
• Above grammar is not operator grammar because right side EAE has
consecutive non terminals.
• In operator precedence parsing we define following disjoint relations:
Relation Meaning
a<.b a “yields precedence to” b
a=b a “has the same precedence as” b
a.>b a “takes precedence over” b
Precedence & associativity of operators
Operator Precedence Associative
↑ 1 right
*, / 2 left
+, - 3 left
Steps of operator precedence parsing
1. Find Leading and trailing of non terminal
2. Establish relation
3. Creation of table
4. Parse the string
Leading & Trailing
Leading:- Leading of a non terminal is the first terminal or operator in production
of that non terminal.
Trailing:- Trailing of a non terminal is the last terminal or operator in production
of that non terminal.
Example: EE+T | T
TT*F | F
Fid
Non terminal Leading Trailing
E {+,*,id} {+,*,id}
T {*,id} {*,id}
F {id} {id}
Rules to establish a relation
1. For a = b, ⇒ 𝑎𝐴𝑏, where 𝐴 is 𝜖 or a single non terminal [e.g : (E)]
2. a <.b ⇒ 𝑂𝑝 . 𝑁𝑇 𝑡ℎ𝑒𝑛 𝑂𝑝 <. 𝐿𝑒𝑎𝑑𝑖𝑛𝑔 𝑁𝑇 [e.g : +T]
3. a .>b ⇒ 𝑁𝑇 . 𝑂𝑝 𝑡ℎ𝑒𝑛 𝑇𝑟𝑎𝑖𝑙𝑖𝑛𝑔(𝑁𝑇 ) . > 𝑂𝑝 [e.g : E+]
4. $ <. Leading (start symbol)
5. Trailing (start symbol) .> $
Example: Operator precedence parsing
1. a <.b
2. 𝑂𝑝 . 𝑁𝑇 𝑂𝑝 <. 𝐿𝑒𝑎𝑑𝑖𝑛𝑔 𝑁𝑇
3. +𝑇 + <. ∗, 𝑖𝑑
4. ∗ 𝐹 ∗ <. {𝑖𝑑}
Nonterminal Leading Trailing
E {+,*,id} {+,*,id}
T {*,id} {*,id}
F {id} {id}
Step 1: Find Leading & Trailing of NT
Step 2: Establish Relation
E E
Step3: Creation of Table
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
+T| T
T T *F| F
F id
Example: Operator precedence parsing
1. a .>b
2. 𝑁𝑇 . 𝑂𝑝 𝑇𝑟𝑎𝑖𝑙𝑖𝑛𝑔(𝑁𝑇 ). > 𝑂𝑝
3. 𝐸 + +,∗, 𝑖𝑑 . > +
4. 𝑇 ∗ {∗, 𝑖𝑑}. >∗
Nonterminal Leading Trailing
E {+,*,id} {+,*,id}
T {*,id} {*,id}
F {id} {id}
Step2: Establish Relation
E
Step3: Creation of Table
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
E+ T| T
T T* F| F
F id
Step 1: Find Leading & Trailing of NT
Example: Operator precedence parsing
Nonterminal Leading Trailing
E {+,*,id} {+,*,id}
T {*,id} {*,id}
F {id} {id}
Step 2: Establish Relation
E
Step 3: Creation of Table
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
E+ T| T
T T* F| F
F id
Step 1: Find Leading & Trailing of NT
1. $<. Leading (start symbol)
2. $ <. +,∗, 𝑖𝑑
3. Trailing (start symbol).> $
4. +,∗, 𝑖𝑑
.
> $
Example: Operator precedence parsing
Assign precedence operator between terminals
String: id+id*id
$ id+id*id $
$ <. id+id*id$
$ <. id .> +id*id$
$ <. id .> + <. id*id$
$ <. id .> + <. id .> *id$
$ <. id .> + <. id .> *<. id$
$ <. id .> + <. id .> *<. id .> $
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
Step 4: Parse the string using precedence table
Example: Operator precedence parsing
$ <. Id .> + <. Id .> * <. Id .> $ Handle id is obtained between <. and .>
Reduce this by Fid
$ F + <. Id .> * <. Id .> $ Handle id is obtained between <. and .>
Reduce this by Fid
$ F + F * <. Id .> $ Handle id is obtained between <. and .>
Reduce this by Fid
$ F + F * F $ Perform appropriate reductions of all nonterminals.
$ E + T * F $ Remove all non terminals.
$ + * $ Place relation between operators
$ <. + <. * >$ The * operator is surrounded by <. and .>. This
indicates * becomes handle so reduce by TT*F.
$ <. + >$ + becomes handle. Hence reduce by EE+T.
$ $ Parsing Done
Step 4: Parse the string using precedence table
1. Scan the input string until first .> is encountered.
2. Scan backward until <. is encountered.
3. The handle is string between <. and .>
Operator precedence function
Algorithm for constructing precedence functions
1. Create functions 𝑓𝑎 and 𝑔𝑎 for each a that is terminal or $.
2. Partition the symbols in as many as groups possible, in such a way that 𝑓𝑎 and 𝑔𝑏 are in the
same group if 𝑎 = 𝑏.
3. Create a directed graph whose nodes are in the groups, next for each symbols 𝑎 𝑎𝑛𝑑 𝑏 do:
a) if 𝑎 <· 𝑏, place an edge from the group of 𝑔𝑏 to the group of 𝑓𝑎
b) if 𝑎 ·> 𝑏, place an edge from the group of 𝑓𝑎 to the group of 𝑔𝑏
4. If the constructed graph has a cycle then no precedence functions exist. When there are no
cycles collect the length of the longest paths from the groups of 𝑓𝑎 and 𝑔𝑏 respectively.
Operator precedence function
1. Create functions fa and ga for each a that is terminal or $.
𝑎 = {+,∗, 𝑖𝑑} 𝑜𝑟 $
E E+T | T
T T*F | F
F id
f+
f* fid f$
g+
g* gid g$
Operator precedence function
• Partition the symbols in as many as groups possible, in such a way that fa and gb
are in the same group if a = b.
f+
f*
fid
f$
g+
g*
gid
g$
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
.
Operator precedence function
3. if a <· b, place an edge from the group of gb to the group of fa
if a ·> b, place an edge from the group of fa to the group of gb
f+
f*
fid
f$
g+
g*
gid
g$
f+
.> g+ f+  g+
f*
.> g+ f*  g+
fid
.> g+ fid  g+
f$ <. g+ f$  g+
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
f
g
Operator precedence function
3. if a <· b, place an edge from the group of gb to the group of fa
if a ·> b, place an edge from the group of fa to the group of gb
f+
f*
fid
f$
g+
g*
gid
g$
f+ <. g* f+  g*
f*
.> g* f*  g*
fid
.> g* fid  g*
f$ <. g* f$  g*
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
f
g
Operator precedence function
3. if a <· b, place an edge from the group of gb to the group of fa
if a ·> b, place an edge from the group of fa to the group of gb
f+
f*
fid
f$
g+
g*
gid
g$
f+ <. gid f+  gid
f* <. gid f*  gid
f$ <. gid f$  gid
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
f
g
Operator precedence function
3. if a <· b, place an edge from the group of gb to the group of fa
if a ·> b, place an edge from the group of fa to the group of gb
f+
f*
fid
g+
g*
gid
+ * id $
+ .> <. <. .>
* .> .> <. .>
id .> .> .>
$ <. <. <.
f+ <. g$ f+  g$
f* <. g$ f*  g$
fid <. g$ fid  g$
f
g
f$ g$
Operator precedence function
+ * id $
f 2
g
f+
f*
fid
f$
g+
g*
gid
g$
4. If the constructed graph
has a cycle then no
precedence functions
exist. When there are no
cycles collect the length of
the longest paths from the
groups of fa and gb
respectively.
Operator precedence function
+ * id $
f 2
g 1
f+
f*
fid
f$
g+
g*
gid
g$
Operator precedence function
+ * id $
f 2 4
g 1
f+
f*
fid
f$
g+
g*
gid
g$
Operator precedence function
+ * id $
f 2 4
g 1 3
f+
f*
fid
f$
g+
g*
gid
g$
Operator precedence function
+ * id $
f 2 4 4
g 1 3
f+
f*
fid
f$
g+
g*
gid
g$
Operator precedence function
+ * id $
f 2 4 4
g 1 3 5
f+
f*
fid
f$
g+
g*
gid
g$
Operator precedence function
+ * id $
f 2 4 4 0
g 1 3 5 0
f+
f*
fid
f$
g+
g*
gid
g$

More Related Content

What's hot

Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
Dr Sandeep Kumar Poonia
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Kuppusamy P
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
Vipul Naik
 
Python recursion
Python recursionPython recursion
Python recursion
Prof. Dr. K. Adisesha
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
Mohammad Imam Hossain
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
Abdul Rahman Sherzad
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
 
Ford Fulkerson Algorithm
Ford Fulkerson AlgorithmFord Fulkerson Algorithm
Ford Fulkerson Algorithm
Adarsh Rotte
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Kiran K
 
Travelling Salesman
Travelling SalesmanTravelling Salesman
Travelling Salesman
Shuvojit Kar
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
Md. Shafiuzzaman Hira
 
Pop operation
Pop operationPop operation
Pop operation
Rajesh K Shukla
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
Mohammed Sikander
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
jayavignesh86
 
Discrete Mathematics in Real Life ppt.pdf
Discrete Mathematics in Real Life ppt.pdfDiscrete Mathematics in Real Life ppt.pdf
Discrete Mathematics in Real Life ppt.pdf
rushikeshchaudhari43
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
Prankit Mishra
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Algorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms IIAlgorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms II
Mohamed Loey
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 

What's hot (20)

Shortest Path in Graph
Shortest Path in GraphShortest Path in Graph
Shortest Path in Graph
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
Python recursion
Python recursionPython recursion
Python recursion
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity CheckTOC 8 | Derivation, Parse Tree & Ambiguity Check
TOC 8 | Derivation, Parse Tree & Ambiguity Check
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Ford Fulkerson Algorithm
Ford Fulkerson AlgorithmFord Fulkerson Algorithm
Ford Fulkerson Algorithm
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Travelling Salesman
Travelling SalesmanTravelling Salesman
Travelling Salesman
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Pop operation
Pop operationPop operation
Pop operation
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Discrete Mathematics in Real Life ppt.pdf
Discrete Mathematics in Real Life ppt.pdfDiscrete Mathematics in Real Life ppt.pdf
Discrete Mathematics in Real Life ppt.pdf
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Algorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms IIAlgorithms Lecture 5: Sorting Algorithms II
Algorithms Lecture 5: Sorting Algorithms II
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 

Similar to 7-Operator Precedence Parser-23-05-2023.pptx

Operator precedence
Operator precedenceOperator precedence
Operator precedence
Akshaya Arunan
 
Operator Precedence Grammar
Operator Precedence GrammarOperator Precedence Grammar
Operator Precedence Grammar
HarisonFekadu
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
mailmerk
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
Jena Catherine Bel D
 
Team 4
Team 4Team 4
The Ring programming language version 1.7 book - Part 22 of 196
The Ring programming language version 1.7 book - Part 22 of 196The Ring programming language version 1.7 book - Part 22 of 196
The Ring programming language version 1.7 book - Part 22 of 196
Mahmoud Samir Fayed
 
Functions in python
Functions in pythonFunctions in python
Functions in python
Ilian Iliev
 
Ch06
Ch06Ch06
Ch06
Hankyo
 
The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.9 book - Part 25 of 210The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.9 book - Part 25 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 23 of 202
The Ring programming language version 1.8 book - Part 23 of 202The Ring programming language version 1.8 book - Part 23 of 202
The Ring programming language version 1.8 book - Part 23 of 202
Mahmoud Samir Fayed
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
Nitesh Dubey
 
Lec19
Lec19Lec19
C Operators
C OperatorsC Operators
scripting in Python
scripting in Pythonscripting in Python
scripting in Python
Team-VLSI-ITMU
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
Hackraft
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Philip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Philip Schwarz
 

Similar to 7-Operator Precedence Parser-23-05-2023.pptx (20)

Operator precedence
Operator precedenceOperator precedence
Operator precedence
 
Operator Precedence Grammar
Operator Precedence GrammarOperator Precedence Grammar
Operator Precedence Grammar
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
Compiler Design Unit 2
Compiler Design Unit 2Compiler Design Unit 2
Compiler Design Unit 2
 
Team 4
Team 4Team 4
Team 4
 
The Ring programming language version 1.7 book - Part 22 of 196
The Ring programming language version 1.7 book - Part 22 of 196The Ring programming language version 1.7 book - Part 22 of 196
The Ring programming language version 1.7 book - Part 22 of 196
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Ch06
Ch06Ch06
Ch06
 
The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.9 book - Part 25 of 210The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.9 book - Part 25 of 210
 
The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.5.4 book - Part 19 of 185
 
The Ring programming language version 1.8 book - Part 23 of 202
The Ring programming language version 1.8 book - Part 23 of 202The Ring programming language version 1.8 book - Part 23 of 202
The Ring programming language version 1.8 book - Part 23 of 202
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Lec19
Lec19Lec19
Lec19
 
C Operators
C OperatorsC Operators
C Operators
 
scripting in Python
scripting in Pythonscripting in Python
scripting in Python
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
 

More from venkatapranaykumarGa

9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT
venkatapranaykumarGa
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
venkatapranaykumarGa
 
10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx
venkatapranaykumarGa
 
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
venkatapranaykumarGa
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
venkatapranaykumarGa
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
venkatapranaykumarGa
 
11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx
venkatapranaykumarGa
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
venkatapranaykumarGa
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
venkatapranaykumarGa
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
venkatapranaykumarGa
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
venkatapranaykumarGa
 
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
venkatapranaykumarGa
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 

More from venkatapranaykumarGa (14)

9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT9-Query Processing-05-06-2023.PPT
9-Query Processing-05-06-2023.PPT
 
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
5-Introduction to Parsing and Context Free Grammar-09-05-2023.pptx
 
10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx10-SLR parser practice problems-02-06-2023.pptx
10-SLR parser practice problems-02-06-2023.pptx
 
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
13-Applications of Syntax Directed Translation - Syntax Directed Translation ...
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
 
15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf15-CAT-2 answer key discussion-04-07-2023.pdf
15-CAT-2 answer key discussion-04-07-2023.pdf
 
11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx11-SLR input string parsing, CLR introduction-06-06-2023.docx
11-SLR input string parsing, CLR introduction-06-06-2023.docx
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
 
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
 
1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx1-Phases of compiler-26-04-2023.pptx
1-Phases of compiler-26-04-2023.pptx
 
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
9-Removal of ambiguity, precedence and associativity-26-05-2023.docx
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 

Recently uploaded

مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
andagarcia212
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
Kalna College
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
7DFarhanaMohammed
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”
Taste
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
Ch-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdfCh-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdf
lakshayrojroj
 

Recently uploaded (20)

مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
 
Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
Ch-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdfCh-4 Forest Society and colonialism 2.pdf
Ch-4 Forest Society and colonialism 2.pdf
 

7-Operator Precedence Parser-23-05-2023.pptx

  • 1. Parsing Methods Parsing Top down parsing Bottom up parsing (Shift reduce) Back tracking Parsing without backtracking (predictive Parsing) LR parsing Operator precedence LALR CLR SLR Recursive descent LL(1)
  • 2. Operator precedence parsing • Operator Grammar: A Grammar in which there is no Є in RHS of any production or no adjacent non terminals is called operator grammar. • Example: E EAE | (E) | id A + | * | - • Above grammar is not operator grammar because right side EAE has consecutive non terminals. • In operator precedence parsing we define following disjoint relations: Relation Meaning a<.b a “yields precedence to” b a=b a “has the same precedence as” b a.>b a “takes precedence over” b
  • 3. Precedence & associativity of operators Operator Precedence Associative ↑ 1 right *, / 2 left +, - 3 left
  • 4. Steps of operator precedence parsing 1. Find Leading and trailing of non terminal 2. Establish relation 3. Creation of table 4. Parse the string
  • 5. Leading & Trailing Leading:- Leading of a non terminal is the first terminal or operator in production of that non terminal. Trailing:- Trailing of a non terminal is the last terminal or operator in production of that non terminal. Example: EE+T | T TT*F | F Fid Non terminal Leading Trailing E {+,*,id} {+,*,id} T {*,id} {*,id} F {id} {id}
  • 6. Rules to establish a relation 1. For a = b, ⇒ 𝑎𝐴𝑏, where 𝐴 is 𝜖 or a single non terminal [e.g : (E)] 2. a <.b ⇒ 𝑂𝑝 . 𝑁𝑇 𝑡ℎ𝑒𝑛 𝑂𝑝 <. 𝐿𝑒𝑎𝑑𝑖𝑛𝑔 𝑁𝑇 [e.g : +T] 3. a .>b ⇒ 𝑁𝑇 . 𝑂𝑝 𝑡ℎ𝑒𝑛 𝑇𝑟𝑎𝑖𝑙𝑖𝑛𝑔(𝑁𝑇 ) . > 𝑂𝑝 [e.g : E+] 4. $ <. Leading (start symbol) 5. Trailing (start symbol) .> $
  • 7. Example: Operator precedence parsing 1. a <.b 2. 𝑂𝑝 . 𝑁𝑇 𝑂𝑝 <. 𝐿𝑒𝑎𝑑𝑖𝑛𝑔 𝑁𝑇 3. +𝑇 + <. ∗, 𝑖𝑑 4. ∗ 𝐹 ∗ <. {𝑖𝑑} Nonterminal Leading Trailing E {+,*,id} {+,*,id} T {*,id} {*,id} F {id} {id} Step 1: Find Leading & Trailing of NT Step 2: Establish Relation E E Step3: Creation of Table + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. +T| T T T *F| F F id
  • 8. Example: Operator precedence parsing 1. a .>b 2. 𝑁𝑇 . 𝑂𝑝 𝑇𝑟𝑎𝑖𝑙𝑖𝑛𝑔(𝑁𝑇 ). > 𝑂𝑝 3. 𝐸 + +,∗, 𝑖𝑑 . > + 4. 𝑇 ∗ {∗, 𝑖𝑑}. >∗ Nonterminal Leading Trailing E {+,*,id} {+,*,id} T {*,id} {*,id} F {id} {id} Step2: Establish Relation E Step3: Creation of Table + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. E+ T| T T T* F| F F id Step 1: Find Leading & Trailing of NT
  • 9. Example: Operator precedence parsing Nonterminal Leading Trailing E {+,*,id} {+,*,id} T {*,id} {*,id} F {id} {id} Step 2: Establish Relation E Step 3: Creation of Table + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. E+ T| T T T* F| F F id Step 1: Find Leading & Trailing of NT 1. $<. Leading (start symbol) 2. $ <. +,∗, 𝑖𝑑 3. Trailing (start symbol).> $ 4. +,∗, 𝑖𝑑 . > $
  • 10. Example: Operator precedence parsing Assign precedence operator between terminals String: id+id*id $ id+id*id $ $ <. id+id*id$ $ <. id .> +id*id$ $ <. id .> + <. id*id$ $ <. id .> + <. id .> *id$ $ <. id .> + <. id .> *<. id$ $ <. id .> + <. id .> *<. id .> $ + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. Step 4: Parse the string using precedence table
  • 11. Example: Operator precedence parsing $ <. Id .> + <. Id .> * <. Id .> $ Handle id is obtained between <. and .> Reduce this by Fid $ F + <. Id .> * <. Id .> $ Handle id is obtained between <. and .> Reduce this by Fid $ F + F * <. Id .> $ Handle id is obtained between <. and .> Reduce this by Fid $ F + F * F $ Perform appropriate reductions of all nonterminals. $ E + T * F $ Remove all non terminals. $ + * $ Place relation between operators $ <. + <. * >$ The * operator is surrounded by <. and .>. This indicates * becomes handle so reduce by TT*F. $ <. + >$ + becomes handle. Hence reduce by EE+T. $ $ Parsing Done Step 4: Parse the string using precedence table 1. Scan the input string until first .> is encountered. 2. Scan backward until <. is encountered. 3. The handle is string between <. and .>
  • 12. Operator precedence function Algorithm for constructing precedence functions 1. Create functions 𝑓𝑎 and 𝑔𝑎 for each a that is terminal or $. 2. Partition the symbols in as many as groups possible, in such a way that 𝑓𝑎 and 𝑔𝑏 are in the same group if 𝑎 = 𝑏. 3. Create a directed graph whose nodes are in the groups, next for each symbols 𝑎 𝑎𝑛𝑑 𝑏 do: a) if 𝑎 <· 𝑏, place an edge from the group of 𝑔𝑏 to the group of 𝑓𝑎 b) if 𝑎 ·> 𝑏, place an edge from the group of 𝑓𝑎 to the group of 𝑔𝑏 4. If the constructed graph has a cycle then no precedence functions exist. When there are no cycles collect the length of the longest paths from the groups of 𝑓𝑎 and 𝑔𝑏 respectively.
  • 13. Operator precedence function 1. Create functions fa and ga for each a that is terminal or $. 𝑎 = {+,∗, 𝑖𝑑} 𝑜𝑟 $ E E+T | T T T*F | F F id f+ f* fid f$ g+ g* gid g$
  • 14. Operator precedence function • Partition the symbols in as many as groups possible, in such a way that fa and gb are in the same group if a = b. f+ f* fid f$ g+ g* gid g$ + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. .
  • 15. Operator precedence function 3. if a <· b, place an edge from the group of gb to the group of fa if a ·> b, place an edge from the group of fa to the group of gb f+ f* fid f$ g+ g* gid g$ f+ .> g+ f+  g+ f* .> g+ f*  g+ fid .> g+ fid  g+ f$ <. g+ f$  g+ + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. f g
  • 16. Operator precedence function 3. if a <· b, place an edge from the group of gb to the group of fa if a ·> b, place an edge from the group of fa to the group of gb f+ f* fid f$ g+ g* gid g$ f+ <. g* f+  g* f* .> g* f*  g* fid .> g* fid  g* f$ <. g* f$  g* + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. f g
  • 17. Operator precedence function 3. if a <· b, place an edge from the group of gb to the group of fa if a ·> b, place an edge from the group of fa to the group of gb f+ f* fid f$ g+ g* gid g$ f+ <. gid f+  gid f* <. gid f*  gid f$ <. gid f$  gid + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. f g
  • 18. Operator precedence function 3. if a <· b, place an edge from the group of gb to the group of fa if a ·> b, place an edge from the group of fa to the group of gb f+ f* fid g+ g* gid + * id $ + .> <. <. .> * .> .> <. .> id .> .> .> $ <. <. <. f+ <. g$ f+  g$ f* <. g$ f*  g$ fid <. g$ fid  g$ f g f$ g$
  • 19. Operator precedence function + * id $ f 2 g f+ f* fid f$ g+ g* gid g$ 4. If the constructed graph has a cycle then no precedence functions exist. When there are no cycles collect the length of the longest paths from the groups of fa and gb respectively.
  • 20. Operator precedence function + * id $ f 2 g 1 f+ f* fid f$ g+ g* gid g$
  • 21. Operator precedence function + * id $ f 2 4 g 1 f+ f* fid f$ g+ g* gid g$
  • 22. Operator precedence function + * id $ f 2 4 g 1 3 f+ f* fid f$ g+ g* gid g$
  • 23. Operator precedence function + * id $ f 2 4 4 g 1 3 f+ f* fid f$ g+ g* gid g$
  • 24. Operator precedence function + * id $ f 2 4 4 g 1 3 5 f+ f* fid f$ g+ g* gid g$
  • 25. Operator precedence function + * id $ f 2 4 4 0 g 1 3 5 0 f+ f* fid f$ g+ g* gid g$