SlideServe
Menu
Préférences
© SlideServe · v2026

Test 2 Post Mortem

yanka avatar
23 diapositives · 388 Views · Sep 10, 2014

This document provides an in-depth post-mortem analysis of LR(1) and LALR(1) parsing techniques, detailing the construction of parse tables, closure operations, and action/goto matrices. It addresses common programming errors and dynamic/static issues in grammar extensions, augmented with illustrative examples. Additionally, it outlines the distribution of grades based on evaluations and offers structured responses to specific questions raised during the April 2006 exam. The material serves as a comprehensive review for students in Compiler Construction (CSCE 531).

Test 2 Post Mortem - slide 1
01 / 23Test 2 Post Mortem
1 / 17

Télécharger la présentation

Test 2 Post Mortem
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Test 2 Post Mortem CSCE 531 Compiler Construction • Topics • Questions and points • Grade Distribution • Answers April, 2006

  2. Questions and Point Evaluations • 1. LR(1) sets of items (14) • LR(1) Parse Table (12) • LALR(1) Parse Table (8) • Do alternatingly (16) • Boolean (20) • Markers • Grammar extensions • Attributes • Quadruples • Annotated Parse Tree (14) • Activation Records (14)

  3. Grade Distribution

  4. LR(1) functions: Closure fig 4.38 • Closure (I) • Add I to Closure (I) • repeat • for each item [Aα •Bβ, a] in Closure (I) • for each production B γ and • each token b in FIRST*(βa) • add [B •γ , b] to closure(I) if it is new • until no new items can be added to closure(I) • Note error in text

  5. S  T T  y T y T  x T x T  ε Augment with S’  S J0 = closure({[S’  ● S, $]}) = {[S’  ● S, $], [S ● T, $], [T ● y T y , $], [T ● x T x , $], [T ● , $], } J1 = GOTO(J0, S) = closure({[S’  S ●, $]}) = { [S’  S ●, $] } J2 = GOTO(J0, T) = closure({[S  T ●, $]}) = { [S  T ●, $] } J3 = GOTO(J0, y) = closure({[T  y ● T y, $]}) (details on next page) J4 = GOTO(J0, x) = closure({[T  x ● T x, $]}) (details on next page) 1. LR(1) Sets of Items

  6. 1. LR(1) Sets of Items continued • J3 = GOTO(J0, y) • = closure({[T  y ● T y, $]}) • = { [T  y ● T y , $], First*(y$) = {y} • [T  ● y T y , y], • [T  ● x T x , y], • [T  ● , y], • }

  7. 1. LR(1) Sets of Items continued • J4 = GOTO(J0, x) • = closure({[T  x ● T x, $]}) • = { [T  x ● T x , $], First*(x$) = {x} • [T  ● y T y , x], • [T  ● x T x , x], • [T  ● , x], • } • Now that handles all of the GOTOs from J0 . • The GOTOs from J1 and J2 are empty so we proceed to J3 and then J4 .

  8. 1. Continued – See Figure

  9. Question 2. LR(1) Parse Table action goto

  10. Question 2. LR(1) Parse Table action goto

  11. Question 3. LALR(1) Parse Table action goto

  12. 4. Do alternatingly • S  do T M1 L1 N alternatingly M2 L2 until M3 B { • } • T ε { tmp = newtemp(); emit(tmp := 0;) $$=tmp; }

  13. Do Alternatingly Picture Common errors -5 backpatch(B.false, M2.quad); -2 backpatch(B.true, xxx); -7 backpatch(B.false, …); twice -5 wrong markers -10 static/dynamic problem (slide after the next slide) T57 := 0 • M1 • M2 • M3 • S  do T M1 L1 N alternatingly M2 L2 until M3 B L1 L1.next N.next goto L2 L2.next B.true B B.false T57 := 1- T57 If t57 == 0 goto M1.quad goto M2.quad

  14. 4. Do alternatingly • S  do T M1 L1 N alternatingly M2 L2 until M3 B { • backpatch(L1.next, M3.quad); • backpatch(L2.next, M3.quad); • backpatch(N.next, M3.quad); • backpatch(B.false, nextquad); • emit( T57 := 1 - T57); • emit( if t57 == 0 goto M1.quad); • emit( goto M2.quad); • S.next = B.true; • } • Attribute Checklist • L1.next • L2.next • M1.quad • M2.quad • M3.quad • N.next • B.false • B.true • S.next

  15. 4. Most Illustrative Error Award • S  do T M1 L1 N alternatingly M2 L2 until M3 B { • … • if ( t != 0) { • backpatch ( B.false, M2.quad ); • } else { • backpatch ( B.false, M5.quad ); • } • t = 1 – t ; • … • } What’s dynamic? What’s static?

  16. Question 5 Booleans • Add Markers • easy • Extend the grammar sufficiently • Bid GT id // to handle r > s • Bid LT intconst // to handle r < 0 • B  E relop E with Eid | intconst and relopLT | GT | EQ is better • Attributes needed • Usual suspects • T needs T.place

  17. Parse Tree • Parse Tree for: • while t < s or r > s and s > t do • x = x + 1 ; • r = r/3 ; • endloop ; • y = r + s ; L • Notes • To allow it to fit: • I left out the semicolons • I left out the body of the loop. • Also I assume that the reduction of the while will emit(goto, M1) L M S id = E S id + id while M1 B do M2 endloop L B1 or M1 B2 L M S id LT id B1 and M1 B2 id GT id id GT id

  18. Pre-Annotation Comments • Attributes • B.t • B.f • id.place • M.quad • S.next • L.next • E.place • Now we will annotate each node with the value of its attributes L L M S id = E S id + id while M1 B do M2 endloop L B1 or M1 B2 L M S id LT id B1 and M1 B2 id GT id id GT id

  19. Semi-Annotated Parse Tree • Notes • I left off the M1.quads. • It is just too crowded. B.T ={41, 45} B.F ={44, 46} B.T ={45} B.F ={44, 46} B.T ={43} B.F ={44} B.T ={41} B.F ={42} B B1 or M1 B2 B.T ={45} B.F ={46} id.place =“t” id.place =“t” id LT id B1 and M1 B2 id GT id id GT id id.place =“s” id.place =“r” id.place =“s” id.place =“s”

  20. func: • pushl %ebp ___save old frame pointer • movl %esp, %ebp ___set ebp to point to “old ebp” • subl $8, %esp __allocate space for 8 bytes of local variables • movl $0, -4(%ebp) __set local1 = 0 • movl 12(%ebp), %eax __move arg2 into eax • movl 8(%ebp), %edx __move arg1 into edx • subl %eax, %edx __arg1-arg2 now in edx • movl %edx, %eax __also in eax • movl %eax, -8(%ebp) __also stored in local2 • cmpl $0, 16(%ebp) __compare arg3 with 0 • jne .L3 __if not equal goto L3 • movl 12(%ebp), %eax __move arg2 to eax • addl 8(%ebp), %eax __ add arg1 to eax

  21. movl %eax, -4(%ebp) ___local1 = eax • .L3: • movl -8(%ebp), %eax ___move local2 to eax • addl -4(%ebp), %eax ____ add local1 to eax • movl %ebp, %esp ___delete everything on the stack below the frame pointer • pop %ebp ___ restore previous frame pointer • ret

  22. What I should have also asked !