1 / 23

Test 2 Post Mortem

Test 2 Post Mortem. CSCE 531 Compiler Construction. Topics Questions and points Grade Distribution Answers. April, 2006. 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

yanka
Download Presentation

Test 2 Post Mortem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 !

More Related