1 / 17

Programming Language Syntax 6

Programming Language Syntax 6. http://flic.kr/p/ zCyMp. Let ’ s pick up where we left off last time: Execute recursive-descent parser on each of these inputs. Create a parse tree as you go Each time a procedure is called, hang a node off the calling procedure

Download Presentation

Programming Language Syntax 6

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. Programming Language Syntax 6 http://flic.kr/p/zCyMp

  2. Let’s pick up where we left off last time: Execute recursive-descent parser on each of these inputs • Create a parse tree as you go • Each time a procedure is called, hang a node off the calling procedure • Be sure to keep track of the call stack

  3. Solution

  4. The tricky part: How to predict? … …

  5. Given input_token, how do you predict the replacement for each rule?

  6. A token X may predict a production P for either of two reasons: • Right-hand side of P yields string that starts with X • Right-hand side of P yields nothing (empty string) and X begins yield of whatever comes after P

  7. More formally Given individual terminal/non-terminal B and concatenation of 1+ terminals/non-terminals A • FIRST(A): Set of tokens that could start A • FOLLOW(A): Set of tokens that could come after A • PREDICT(BA ): Set of tokens that predicts that B will replaced with A We’ll also need: • EPS(A): True if A could yield an empty string; false otherwise But how to compute these?

  8. Which FIRST, FOLLOW, and EPS values can you deduce?Find some “obvious” ones

  9. Here are some obvious ones

  10. Given these, can you deduce more?

  11. Given these, can you deduce more? How about this one Hint

  12. Given these, can you deduce more? {id,read,write} subset of FIRST(stmt_list)

  13. Given these, can you deduce more? How about this one Hint

  14. Given these, can you deduce more? $$ in FIRST(program)

  15. Algorithm for computingEPS values and FIRST sets

  16. Activity: Run algorithm on grammar

  17. What’s next? • Finish activity for next class • Homework 2 due on Tuesday

More Related