This preview shows pages 1–13. 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 DocumentThis 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 DocumentThis 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: Semantics Elements of a language definition syntax (set of legal elements) semantics (meaning of those elements) Semantics is expressed by defining a semantic domain (some notation for talking about meaning) and a semantic mapping that maps the syntactic elements to the semantic domain. M: L S where L is the language (or syntactic domain), usually abstract syntax and S is the semantic domain. Different kinds of semantics use different sorts of semantic domains. Examples: Translational semantics map programs in a source language to programs in a target language. (In a sense, a compiler is a way of defining semantics.) Axiomatic semantics map programs to sets of Hoare triples (or the related notion of weakest preconditions). { x >= N} precondition x := x+1 statement being defined {x > N} postcondition The mapping M can be expressed in a variety of ways (with a range of completeness, precision, and formality) Natural language A formal specification languages (Z, VDM) Mathematics ... The choice will depend on the audience (language designer, language implementer or tool builder, programmer) and the complexity of the mapping. Denotational Semantics syntactic domain : elements of the abstract syntax of a language semantic domain : abstract mathematical objects (integers, booleans, lists, functions , etc.) semantic functions : map elements of syntactic domain to elements of semantic domain. Important features of denotational semantics based on welldefined mathematical objects (functions) compositional: the semantics of a language obtained from the semantics of its parts. Example: Binary literals Binary literals are sequences of 0 and 1s. The meaning is its value in base 10. Abstract syntax BinLit ::= Digit  BinLit Digit Digit :=  1 Syntactic domain B: BinLit D: Digit We introduce variables B and D that will have the indicated type Semantic domain N = {0,1,2....} Semantic functions val : BinLit > N dval : Digit > N dval [ ] = 0 dval [ 1 ] = 1 val [ B ] = dval [ D ] val [ B D ] = 2 * val [ B ] + dval [ D ] Now, for any binary digit, we can find the meaning by evaluating the semantic functions. val [ 101 ] = 2 * val [ 10 ] + dval [ 1 ] = 2 * (2 * val [ 1 ] + dval [ 0 ]) + dval [ 1 ] .... = 5 SSM (Simple stack machine) language A program is a sequence of the following instructions: load n pushes n on top of the stack + removes the top two elements of the stack, add them together and pushes the result on the stack * removes the top two elements of the stack, multiplies them together and pushes the result on the stack out removes the top element of the stack and sends it to the output. load 5 load 2 load 1 + out load 4 * out This program outputs 3 followed by 20 Denotational Semantics of SSM Abstract syntax Program ::= Instruction Instruction ::= Instruction Instruction ::= load Number ::= + ::= * ::= out Syntactic domain P: Program I: Instruction N: Number...
View
Full
Document
This note was uploaded on 12/09/2009 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.
 Fall '08
 Staff

Click to edit the document details