SlideShare uma empresa Scribd logo
1 de 24
Syntax Analysis
LL Parser
Objectives:
• Be able to understand LL parsing methods
• Be able to find First sets and Follow sets parsing
• Be able to check LL Parsing properties
Hierarchy of grammar classes
© Oscar Nierstrasz Parsing
LL(k):
— Left-to-right, Leftmost
derivation, k tokens
lookahead
LR(k):
— Left-to-right, Rightmost
derivation, k tokens
lookahead
SLR:
— Simple LR (uses “follow
sets”)
LALR:
— LookAhead LR (uses
“lookahead sets”)
Top-down versus bottom-up
• Top-down parser:
– starts at the root of derivation tree and fills in
– picks a production and tries to match the input
– may require backtracking
– some grammars are backtrack-free (predictive)
• Bottom-up parser:
– starts at the leaves and fills in
– starts in a state valid for legal first tokens
– as input is consumed, changes state to encode possibilities
(recognize valid prefixes)
– uses a stack to store both state and sentential forms
Predictive Parsing
• If a top down parser picks the wrong production, it
may need to backtrack
• Alternative is to look ahead in input and use
context to pick correctly
• Fortunately, large classes of CFGs can be parsed
with limited lookahead
• Most programming languages constructs fall in
those subclasses
4
Predictive Parsing
• Eliminate left recursion from grammar
• Left factor the grammar
• Compute FIRST and FOLLOW
• Two variants:
– Recursive (recursive-descent parsing)
– Non-recursive (table-driven parsing)
5
LL Parsing Methods
• LL parsing methods read the tokens from Left
to right and parse them top-down according
to a Leftmost derivation.
• To build the parsing table, we need the notion
of nullability and the two functions
– FIRST
– FOLLOW
Nullability
• A nonterminal A is nullable if
A * .
• Clearly, A is nullable if it has a production
A  .
• But A is also nullable if there are, for example,
productions
A  BC.
B  A | aC | .
C  aB | Cb | .
Nullability
• In other words, A is nullable if there is a
production
A  ,
or there is a production
A  B1B2…Bn,
where B1, B2, ..., Bn are nullable.
Nullability
• In the grammar
E  T E'
E'  + T E' | .
T  F T'
T'  * F T' | .
F  (E) | id | num
E' and T' are nullable.
• E, T, and F are not nullable.
Nullability
• In the grammar
S → aBDh
B → cC
C → bC / ∈
D → EF
E → g / ∈
F → f / ∈
Which symbol/s is/are null-able?
Predictive Parsing
FIRST Sets:
For some rhs a  G, define
FIRST(a) as the set of tokens
that appear as the first symbol
in some string that derives
from a.
11
Predictive Parsing
That is,
x  FIRST(a)
iff a * x g, for some g.
12
FIRST Set
• FIRST(a) = { the set of terminals that begin all
strings derived from a }
FIRST(a) = {a} if a  T
FIRST() = {}
FIRST(A) = Aa FIRST(a)
for Aa  P
FIRST(X1X2…Xk) =
if for all j = 1, …, i-1 :   FIRST(Xj) then
add non- in FIRST(Xi) to FIRST(X1X2…Xk)
if for all j = 1, …, k :   FIRST(Xj) then
add  to FIRST(X1X2…Xk)
13
Example: FIRST
• Let the grammar be
E  T E'
E'  + T E' | .
T  F T'
T'  * F T' | .
F  (E) | id | num
Predictive Parsing
FOLLOW(a)
is the set of all words in the
grammar that can legally
appear after an a.
15
FOLLOW
• FOLLOW(A) = { the set of terminals that can
immediately follow nonterminal A }
FOLLOW(A) =
for all (B  a A )  P do
add FIRST()-{} to FOLLOW(A)
for all (B  a A )  P and   FIRST() do
add FOLLOW(B) to FOLLOW(A)
for all (B  a A)  P do
add FOLLOW(B) to FOLLOW(A)
if A is the start symbol S then
add $ to FOLLOW(A)
16
Find First and Follow sets
CFG
expr  expr + term | term
term  term * factor | factor
factor  number | ( expr )
Reformed
EE+T/T
TT*F/F
F(E)/id
Left-recursion/Left-factoring removed
?
1-SAa
2-ABD
3-Bb
4- B 
5-Dd
6-D
First sets
First (S)={}
First(A)= {}
First(B)= {}
First(D)={}
Follow(S)={}
Follow(A)={}
Follow(B)={}
Follow(D)={}
N/T a b d $
S
A
B
D
1. CPF class id XY
2. Ppublic
3. P 
4. Ffinal
5. F 
6. Xextends id
7. X 
8. Yimplements I
9. Y 
10.Iid J
11.JI
12.J 
First©={ public, final,class }
First(P)={public, }
First(F)={final , }
First(X)={extends, }
First(Y)={implements, }
First(I)={id}
First(J)={id, }
Follow(C)={}
Follow(P)={}
Follow(F)={}
Follow(X)={}
Follow(Y)={}
Follow(I)={}
Follow(J)={}
class id publi
c
final ext impl
e
$
C
P
F
X
Y
I
J
LL(1) Grammar
• A grammar G is LL(1) if it is not left recursive and for
each collection of productions
A  a1 | a2 | … | an
for nonterminal A the following holds:
1. FIRST(ai)  FIRST(aj) =  for all i  j
2. if ai *  then
2.a. aj *  for all i  j
2.b. FIRST(aj)  FOLLOW(A) = 
for all i  j
20
Sif C then S else S | if C then S
Non-LL(1) Examples
21
Grammar Not LL(1) because:
S  S a | a Left recursive
S  a S | a FIRST(a S)  FIRST(a)  
S  a R | 
R  S |  For R: S *  and  * 
S  a R a
R  S | 
For R:
FIRST(S)  FOLLOW(R)  
Example Table
22
E  T ER
ER  + T ER | 
T  F TR
TR  * F TR | 
F  ( E ) | id
A  a
FIRST(
a)
FOLLOW(
A)
E  T ER ( id $ )
ER  + T
ER
+
$ )
ER   
T  F TR ( id + $ )
TR  * F
TR
*
+ $ )
TR   
F  ( E ) ( * + $ )
F  id id * + $ )
Example Table
23
E  T ER
ER  + T ER | 
T  F TR
TR  * F TR | 
F  ( E ) | id
id + * ( ) $
E E  T ER
E  T
ER
ER
ER  + T
ER
ER   ER  
T T  F TR
T  F
TR
TR TR  
TR  * F
TR
TR   TR  
F F  id
F  ( E
)
Summary
• Predictive parsing requires
– Removal of Left Recursion
– Left factored CFG
• LL 1 Parsing requires
– First sets
– Follow sets

Mais conteúdo relacionado

Semelhante a compiler-lecture-6nn-14112022-110738am.ppt

Semelhante a compiler-lecture-6nn-14112022-110738am.ppt (20)

PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
 
Left factor put
Left factor putLeft factor put
Left factor put
 
Ch4a
Ch4aCh4a
Ch4a
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Lecture11 syntax analysis_7
Lecture11 syntax analysis_7Lecture11 syntax analysis_7
Lecture11 syntax analysis_7
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
LR-Parsing.ppt
LR-Parsing.pptLR-Parsing.ppt
LR-Parsing.ppt
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
 
Lecture8 syntax analysis_4
Lecture8 syntax analysis_4Lecture8 syntax analysis_4
Lecture8 syntax analysis_4
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
Lecture7 syntax analysis_3
Lecture7 syntax analysis_3Lecture7 syntax analysis_3
Lecture7 syntax analysis_3
 
Lecture10 syntax analysis_6
Lecture10 syntax analysis_6Lecture10 syntax analysis_6
Lecture10 syntax analysis_6
 
Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.
 
Ch8b
Ch8bCh8b
Ch8b
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Parsing
ParsingParsing
Parsing
 
UNIT 2 (1).pptx
UNIT 2 (1).pptxUNIT 2 (1).pptx
UNIT 2 (1).pptx
 
lr parsers bottom up parsers slr parser.pptx
lr parsers bottom up parsers slr parser.pptxlr parsers bottom up parsers slr parser.pptx
lr parsers bottom up parsers slr parser.pptx
 

Último

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 

Último (20)

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 

compiler-lecture-6nn-14112022-110738am.ppt

  • 1. Syntax Analysis LL Parser Objectives: • Be able to understand LL parsing methods • Be able to find First sets and Follow sets parsing • Be able to check LL Parsing properties
  • 2. Hierarchy of grammar classes © Oscar Nierstrasz Parsing LL(k): — Left-to-right, Leftmost derivation, k tokens lookahead LR(k): — Left-to-right, Rightmost derivation, k tokens lookahead SLR: — Simple LR (uses “follow sets”) LALR: — LookAhead LR (uses “lookahead sets”)
  • 3. Top-down versus bottom-up • Top-down parser: – starts at the root of derivation tree and fills in – picks a production and tries to match the input – may require backtracking – some grammars are backtrack-free (predictive) • Bottom-up parser: – starts at the leaves and fills in – starts in a state valid for legal first tokens – as input is consumed, changes state to encode possibilities (recognize valid prefixes) – uses a stack to store both state and sentential forms
  • 4. Predictive Parsing • If a top down parser picks the wrong production, it may need to backtrack • Alternative is to look ahead in input and use context to pick correctly • Fortunately, large classes of CFGs can be parsed with limited lookahead • Most programming languages constructs fall in those subclasses 4
  • 5. Predictive Parsing • Eliminate left recursion from grammar • Left factor the grammar • Compute FIRST and FOLLOW • Two variants: – Recursive (recursive-descent parsing) – Non-recursive (table-driven parsing) 5
  • 6. LL Parsing Methods • LL parsing methods read the tokens from Left to right and parse them top-down according to a Leftmost derivation. • To build the parsing table, we need the notion of nullability and the two functions – FIRST – FOLLOW
  • 7. Nullability • A nonterminal A is nullable if A * . • Clearly, A is nullable if it has a production A  . • But A is also nullable if there are, for example, productions A  BC. B  A | aC | . C  aB | Cb | .
  • 8. Nullability • In other words, A is nullable if there is a production A  , or there is a production A  B1B2…Bn, where B1, B2, ..., Bn are nullable.
  • 9. Nullability • In the grammar E  T E' E'  + T E' | . T  F T' T'  * F T' | . F  (E) | id | num E' and T' are nullable. • E, T, and F are not nullable.
  • 10. Nullability • In the grammar S → aBDh B → cC C → bC / ∈ D → EF E → g / ∈ F → f / ∈ Which symbol/s is/are null-able?
  • 11. Predictive Parsing FIRST Sets: For some rhs a  G, define FIRST(a) as the set of tokens that appear as the first symbol in some string that derives from a. 11
  • 12. Predictive Parsing That is, x  FIRST(a) iff a * x g, for some g. 12
  • 13. FIRST Set • FIRST(a) = { the set of terminals that begin all strings derived from a } FIRST(a) = {a} if a  T FIRST() = {} FIRST(A) = Aa FIRST(a) for Aa  P FIRST(X1X2…Xk) = if for all j = 1, …, i-1 :   FIRST(Xj) then add non- in FIRST(Xi) to FIRST(X1X2…Xk) if for all j = 1, …, k :   FIRST(Xj) then add  to FIRST(X1X2…Xk) 13
  • 14. Example: FIRST • Let the grammar be E  T E' E'  + T E' | . T  F T' T'  * F T' | . F  (E) | id | num
  • 15. Predictive Parsing FOLLOW(a) is the set of all words in the grammar that can legally appear after an a. 15
  • 16. FOLLOW • FOLLOW(A) = { the set of terminals that can immediately follow nonterminal A } FOLLOW(A) = for all (B  a A )  P do add FIRST()-{} to FOLLOW(A) for all (B  a A )  P and   FIRST() do add FOLLOW(B) to FOLLOW(A) for all (B  a A)  P do add FOLLOW(B) to FOLLOW(A) if A is the start symbol S then add $ to FOLLOW(A) 16
  • 17. Find First and Follow sets CFG expr  expr + term | term term  term * factor | factor factor  number | ( expr ) Reformed EE+T/T TT*F/F F(E)/id Left-recursion/Left-factoring removed ?
  • 18. 1-SAa 2-ABD 3-Bb 4- B  5-Dd 6-D First sets First (S)={} First(A)= {} First(B)= {} First(D)={} Follow(S)={} Follow(A)={} Follow(B)={} Follow(D)={} N/T a b d $ S A B D
  • 19. 1. CPF class id XY 2. Ppublic 3. P  4. Ffinal 5. F  6. Xextends id 7. X  8. Yimplements I 9. Y  10.Iid J 11.JI 12.J  First©={ public, final,class } First(P)={public, } First(F)={final , } First(X)={extends, } First(Y)={implements, } First(I)={id} First(J)={id, } Follow(C)={} Follow(P)={} Follow(F)={} Follow(X)={} Follow(Y)={} Follow(I)={} Follow(J)={} class id publi c final ext impl e $ C P F X Y I J
  • 20. LL(1) Grammar • A grammar G is LL(1) if it is not left recursive and for each collection of productions A  a1 | a2 | … | an for nonterminal A the following holds: 1. FIRST(ai)  FIRST(aj) =  for all i  j 2. if ai *  then 2.a. aj *  for all i  j 2.b. FIRST(aj)  FOLLOW(A) =  for all i  j 20 Sif C then S else S | if C then S
  • 21. Non-LL(1) Examples 21 Grammar Not LL(1) because: S  S a | a Left recursive S  a S | a FIRST(a S)  FIRST(a)   S  a R |  R  S |  For R: S *  and  *  S  a R a R  S |  For R: FIRST(S)  FOLLOW(R)  
  • 22. Example Table 22 E  T ER ER  + T ER |  T  F TR TR  * F TR |  F  ( E ) | id A  a FIRST( a) FOLLOW( A) E  T ER ( id $ ) ER  + T ER + $ ) ER    T  F TR ( id + $ ) TR  * F TR * + $ ) TR    F  ( E ) ( * + $ ) F  id id * + $ )
  • 23. Example Table 23 E  T ER ER  + T ER |  T  F TR TR  * F TR |  F  ( E ) | id id + * ( ) $ E E  T ER E  T ER ER ER  + T ER ER   ER   T T  F TR T  F TR TR TR   TR  * F TR TR   TR   F F  id F  ( E )
  • 24. Summary • Predictive parsing requires – Removal of Left Recursion – Left factored CFG • LL 1 Parsing requires – First sets – Follow sets