1 / 8

Error Recovery & Bottom Up Parsing

Error Recovery & Bottom Up Parsing. Chainate, W. Recovery. หากเกิด error() ขึ้น แสดงว่า ข้อมูลเข้าไม่เป็นประโยค คอมไพเลอร์ที่ดี... ไม่ควรหยุดเมื่อพบความผิดพลาดครั้งแรก ควรรายงานความผิดพลาด และ recovery เพื่อให้สามารถดำเนินการตรวจสอบต่อไปได้ Panic mode recovery

hollye
Download Presentation

Error Recovery & Bottom Up Parsing

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. Error Recovery& Bottom Up Parsing Chainate, W.

  2. Recovery • หากเกิด error() ขึ้น แสดงว่า ข้อมูลเข้าไม่เป็นประโยค • คอมไพเลอร์ที่ดี... • ไม่ควรหยุดเมื่อพบความผิดพลาดครั้งแรก • ควรรายงานความผิดพลาด และ recovery เพื่อให้สามารถดำเนินการตรวจสอบต่อไปได้ • Panic mode recovery • ก่อนอื่น ให้จัดการกับ “ช่องว่าง” ใน parsing table • หาก M[A, a] = {empty} และ a เป็นสมาชิกของ FOLLOW(A) แล้วให้ใส่ค่าใน M[A, a] = sync • Sync อ้างถึง synchronize symbol

  3. INPUT SYMBOL Non-terminal id + * ( ) $ E ETA ETA A A+TA A A T TFB TFB B B B*FB B B F Fid F(E) Recovery • Recovery strategyfor M[A, a]: • ถ้า A เป็น NT และ M[A, a]={empty} แล้ว ให้ข้าม (skip) a ไปยังข้อมูลเข้าถัดไป • ถ้า A เป็น NT และ M[A, a]={sync} แล้ว ให้ pop A ออกจาก stack • ถ้า A เป็น T และ A  a แล้ว ให้ pop token sync sync sync sync sync sync sync sync sync

  4. Try this • +id*+id$

  5. Bottom Up Parsing • เป็นการพยายามสร้างต้นไม้วิเคราะห์กระจายจากข้อมูลเข้า โดยเริ่มจากปลายกิ่งขึ้นไปยังโหนดราก • อาจจกล่าวได้ว่าเป็นการลดทอน (reduce) ข้อมูลเข้าให้เป็นสัญลักษณ์เริ่มต้น • ในแต่ละขั้นของการลดทอน จะแทนสายอักขระย่อยที่ตรงกับสายอักขระทางขวาของกฏ ด้วยสัญลักษณ์ไม่สิ้นสุดที่อยู่ทางซ้าย • ข้อมูลเข้าคือ aaabc • ไวยากรณ์ได้แก่ • (1) S  aABc • (2-3) A  Aa | a • (4) B  b

  6. Bottom Up (cont) • aaabc • ข้อมูลเข้าจะเป็นประโยค ถ้าสุดท้ายแล้วเหลือเพียงสัญลักษณ์เริ่มต้นใน stack และสิ้นสุดข้อมูลเข้า มิฉะนั้น จะไม่ถือว่าข้อมูลเข้านี้เป็นประโยชน์

  7. ตัววิเคราะห์กระจาย SLR(1) • Simple Left to Right, Right derivation (1 lookahead symbol) • General parser behavior: s : top of stack a : current input • 1. If action[s, a]=“accept” halt, accept, success • If action[s, a]= r# “reduce by production A  (rule #)” do the following:2a. Pop 2*|| elements from the stack. (after that assume t = top symbol in stack)2b. Push A2c. Push a value in goto[t, A] • If action[s, a]= s# “shift and goto state s*”Shift; push a and # then read next lookahead

  8. SLR(1) • (1-2) E  E+T | T(3-4) T  T*F | F(5-6) F  (E) | id • ข้อมูลเข้า: id+id*id

More Related