This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Grammars and Semantics Programming languages are used to specify computations – that is, computations are the meaning/semantics of programs. Read Chap 3 Grammars and Semantics G: <Exp>* ::= <Exp> + <Exp>  <Exp> * <Exp>  a  b  c Consider the simple language of expressions: When we write the sentence a + b we can build the parse tree: <Exp>* <Exp> <Exp> + a b We can say that this parse tree represents the computation a + b . If we let a and b be variables, then the parse tree gives us a procedure to compute a + b by starting at the leaves of the tree: (1) lookup the values of the variables (2) pass the values up along the parse tree branches (3) use the values to compute the value of the + operator. Grammars and Semantics Now consider the sentence a + b * c , for this sentence we can construct two parse trees: <Exp>* <Exp> + a <Exp> <Exp> <Exp> * b c <Exp>* <Exp> * c <Exp> <Exp> <Exp> + b a The grammar G is ambiguous Even though both parse trees derive the same terminal string, the computations they represent are...
View
Full
Document
This note was uploaded on 10/03/2011 for the course CSC 301 taught by Professor Hamel during the Spring '08 term at Rhode Island.
 Spring '08
 HAMEL

Click to edit the document details