Com S 641 meeting -*- Outline -*- * Setting the Scene (1.2) ** The While Language *** abstract syntax ------------------------------------------ ABSTRACT SYNTAX OF THE WHILE LANGUAGE a \in AExp "arithmetic expressions" b \in BExp "Boolean expressions" S \in Stmt "statements" x,y \in Var "variables" n \in Num "numeric literals" l \in Lab "labels" opa \in Op_a "arithmetic operators" opb \in Op_b "Boolean operators" opr \in Op_r "relational operators" S ::= [x:= a]^l | [skip]^l | S1 ; S2 | if [b]^l then S1 else S2 | while [b]^l do S a ::= x | n | a1 opa a2 b ::= true | false | not b | b1 opb b2 | a1 opr a2 ------------------------------------------ There is an index of notations at the end of the book! Q: What's the difference between abstract and concrete syntax? ------------------------------------------ EXAMPLE [y := x]^1; [z := 1]^2; while [y>1]^3 do ([z := z*y]^4; [y := y-1]^5); [y := 0]^6 ------------------------------------------ Q: Why are the labels only attached to certain places in the abstract syntax trees? These are the places in statements where execution actually happens, the rest is plumbing. Q: Which blocks are elementary? Q: What is used to disambiguate different parse trees? () *** semantics Q: What does the example above do? Q: What does skip do? Q: What kind of numeric literals? integers Q: What would be some reasonable arithmetic operators? +, -, *, / Q: One would be some reasonable relational operators? <, >, <=, >=, ==, != Q: What would be some reasonable Boolean operators? and, or Q: What's the type of the relational operators? Q: Can the labels be repeated? Q: What's missing? *** variations I'd like to have some variations to consider in class on this language... ------------------------------------------ VARIATION 1: CONTROL FEATURES S ::= ... | break | for x in a1 .. a2 do S | throw | try S1 catch S2 VARIATION 2: SPECIFICATION FEATURES S ::= ... | assert b | assume b | choose S1 or S2 VARIATION 3: PARALLELISM S ::= ... | S1 `||' S2 VARIATION 4: FUNCTIONALS a ::= ... | fn x => a | a1 a2 | let d in a d ::= x = a | d1; d2 ------------------------------------------ Q: Which of these need labels, and where do the labels go? 1. on break, throw on a1 and a2 in for, 2. on the b's in assert and assume 3. no new ones 4. on each subexpression? We'll leave procedures, methods, and object-oriented stuff for later... ** reaching definitions analysis This is just an example of a data flow analysis used in Chapter 1. *** definition ------------------------------------------ REACHING DEFINITIONS (ASSIGNMENTS) def: Let P be a program. An assignment [x := a]^l *may reach* a program point in P if in some execution of P, when execution reaches that point, the last assignment to x was done at l. ------------------------------------------ *** examples ------------------------------------------ EXAMPLE [y := x]^1; [z := 1]^2; while [y>1]^3 do ([z := z*y]^4; [y := y-1]^5); [y := 0]^6 (y,1) reaches entry to 2 ------------------------------------------ Q: What definitions reach the entry for label 3? (y,1), (y,5), (z,2), (z,4) Q: How do we talk about uninitialized variables? use ? for the label, as in (x,?) See table 1.1 for RDentry and RDexit for this example Q: In table 1.1, what if we add (y,1) to RDentry(5)? Q: In table 1.1, what if we remove (y,5) from RDentry(6)? ------------------------------------------ FOR YOU TO DO Compute a table like table 1.1 for: [t := x]^1; [x := y]^2; [y := t]^3 if [y>x]^4 then [r := y]^5 else [r := x]^6; assert [r >= x and r >= y]^7 ------------------------------------------ l RDentry(l) RDexit(l) ============================================================ 1 (r,?),(t,?),(x,?),(y,?) (r,?),(t,1),(x,?),(y,?) 2 (r,?),(t,1),(x,?),(y,?) (r,?),(t,1),(x,2),(y,?) 3 (r,?),(t,1),(x,2),(y,?) (r,?),(t,1),(x,2),(y,3) 4 (r,?),(t,1),(x,2),(y,3) (r,?),(t,1),(x,2),(y,3) 5 (r,?),(t,1),(x,2),(y,3) (r,5),(t,1),(x,2),(y,3) 6 (r,?),(t,1),(x,2),(y,3) (r,6),(t,1),(x,2),(y,3) 7 (r,5),(r,6),(t,1),(x,2),(y,3) (r,5),(r,6),(t,1),(x,2),(y,3) *** variations Q: What would the analysis look like if we only wanted to keep track of which variables were assigned? Q: What would the analysis look like if we want to keep track of what variables could influence the values of other variables?