Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming Language Syntax 6

Similar presentations


Presentation on theme: "Programming Language Syntax 6"— Presentation transcript:

1 Programming Language Syntax 6

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
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 computing EPS values and FIRST sets

16 Activity: Run algorithm on grammar

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


Download ppt "Programming Language Syntax 6"

Similar presentations


Ads by Google