L Rparser Edos
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

L Rparser Edos

on

  • 882 views

 

Statistics

Views

Total Views
882
Views on SlideShare
867
Embed Views
15

Actions

Likes
0
Downloads
8
Comments
0

2 Embeds 15

http://cursotec.blogspot.com 14
http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

L Rparser Edos Presentation Transcript

  • 1. LR Parsers Canonical Collection LR
  • 2. LR Parser 1
    • Tokens
    • Driver Routine
    S T A C K Prg Ejem1 ; Real X2 Fig. 6.2 Aho, Ullman. “Principles of Compiler Design” pág. 199 Parsing Table eof …
  • 3. Driver Routine
    • Determines S n , the state on top of stack
    • Uses the current token a i
    • Consults Table[S n , a i ]  Edo .
      • Shift s
      • Reduce
      • Accept
      • Error
  • 4. Shift
    • The parser executes a shift move:
      • Stack  Edo
      • Shifts the current token
  • 5. Reduce
    • Consults the specific production: A  ß
    • If n is the lenght of ß
    • Pop n symbols off the stack
    • Push A onto the stack
    • Note : the current token is not changed in a reduce move
  • 6. Accept
    • IF Table[S n , a i ] = accept, parsing is completed
  • 7. Error
    • IF Table[S n , a i ] = error, the parser has discovered an error and calls an error recovery routine
  • 8. How to construct a simple LR 2
    • Procedure Closure(P)
    • Begin
    • repeat
    • for each item A  @♥Bß in P and each production
    • B  ¥ in G such that B  ♥ ¥ is not in P
    • do add B  ♥ ¥ to P
    • until no more items can be aded to P;
    • return P;
    • end
    IBID. Fig. 6.5 pág. 207
  • 9. How to construct a simple LR 2
    • Procedure ITEMS(G’)
    • Begin
    • C := {CLOSURE(S’  ♥S)};
    • repeat
    • for each set of items P in C and each grammar symbol X
    • such that GOTO(P,X) is not empty and is not in C
    • do add GOTO(P,X) to C
    • until no more sets of items can be added to C
    • end
    IBID. Fig. 6.5 pág. 207
  • 10. Example: G is a grammar with start symbol E E  E + T E  T T  T/F T  F F  (E) F  id
  • 11. G’ is the augmented grammar with a new start symbol E’ E’  E E  E + T E  T T  T/F T  F F  (E) F  id Blue nucleous
  • 12. Closure(E’) E’  ♥E Blue nucleous
  • 13. Closure(E) E’  ♥E E  ♥ E + T E  ♥ T
  • 14. Closure(T) E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F
  • 15. Closure(F) E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id
  • 16. State 1 E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id
  • 17. State 2=GoTo(1,E) E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T
  • 18. State 3 =GoTo(1,T) E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F
  • 19. State 4=GoTo(1,F) E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥
  • 20. State 5: from state 1 with ( E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥ F  (♥E) E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id
  • 21. State 6:from state1 with id E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥ F  (♥E) E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id F  id ♥
  • 22. States 1,2 ,3,4,5,6 E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥ F  (♥E) E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id F  id ♥
  • 23. States 7,8,9 E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥ F  (♥E) E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id F  id ♥ E’  E+♥T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id T’  T/♥F F  ♥ (E) F  ♥ id F  (E♥) E  E♥+T
  • 24. States 10,11,12 E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥ F  (♥E) E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id F  id ♥ E’  E+♥T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id T’  T/♥F F  ♥ (E) F  ♥ id F  (E♥) E  E♥+T E’  E+T♥ T  T ♥ /F T’  T/F♥ F  (E)♥
  • 25. States 1,2,3,4,... 12 E’  ♥E E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id E’  E♥ E  E♥ + T E’  T♥ T  T♥ /F T  F ♥ F  (♥E) E  ♥ E + T E  ♥ T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id F  id ♥ E’  E+♥T T  ♥ T/F T  ♥ F F  ♥ (E) F  ♥ id T’  T/♥F F  ♥ (E) F  ♥ id F  (E♥) E  E♥+T E’  E+T♥ T  T ♥ /F T’  T/F♥ F  (E)♥
  • 26. END Canonical Collection LR