Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4: Language Semantics The need for language semantics: a. for the programmer - to know how to use language constructs b. for the implementor -

Similar presentations


Presentation on theme: "Chapter 4: Language Semantics The need for language semantics: a. for the programmer - to know how to use language constructs b. for the implementor -"— Presentation transcript:

1 Chapter 4: Language Semantics The need for language semantics: a. for the programmer - to know how to use language constructs b. for the implementor - to know how to implement the language

2 Semantics Semantics: the study or analysis of the relationships between linguistic symbols and their meanings

3 Semantic descriptions Informal descriptions of language semantics - provided in verbal form in the language manuals. May be ambiguous. Formal description: studied theoretically, no satisfactory models have been produced so far.

4 Formal semantic models Grammatical models Operational (imperative) models Axiomatic models Applicative (functional) models Specification models

5 Grammatical models  grammar rules are paired with semantic rules. Resulting grammars are called attribute grammars RuleAttribute E  E + Tvalue (E1) = value (E2) + value(T) E  Tvalue (E) = value (T) T  T * Pvalue (T1) = value (T2) * value (P) T  Pvalue (T) = value (P) P  Ivalue (P) = value of number I P  (E)value (P) = value (E)

6 Operational models Describe the meaning of the language constructs in terms of machine states, i.e. memory and register contents. Operational semantics – describes what has to be done.

7 Applicative models Treat programs as functions. Denotational semantics (functional semantics) Lambda calculus

8 Denotational semantics Specifies the meaning of expressions by their denotation The domain of interpretation defines the denotation of composite expressions in terms of the denotations of their components. -> Compositional semantics

9 Lambda calculus Formal mathematical system devised by Alonzo Church to investigate functions, function application and recursion

10 Example illustrating lambda calculus A function accepts input and produces an output. Suppose we have a "chocolate-covering" function that produces the following outputs for the corresponding inputs: INPUTOUTPUT peanuts->chocolate-covered peanuts raisins->chocolate-covered raisins ants->chocolate-covered ants

11 Lambda functions We can use Lambda-calculus to describe such a function: Lx. chocolate - covered x If we want to apply the function to an argument, we use the following syntax: (Lx.chocolate-covered x)peanuts -> chocolate-covered peanuts

12 Using Lambda expressions to get new functions Functions can also be the result of applying a lambda-expression Ly.Lx. y - covered x We can use this to create a caramel-covering function: (Ly.Lx.y-covered x) caramel -> Lx. caramel-covered x

13 Functions as inputs Functions can also be the inputs to other functions, as with this "apply-to-ants" function: Lf.(f) ants We can feed the chocolate-covering function to the "apply-to-ants" function: (Lf.(f)ants)Lx.chocolate-covered x -> (Lx.chocolate-covered x)ants -> chocolate-covered ants

14 Axiomatic models Describe the meaning as pre- conditions and post-conditions Used in program verifications

15 Specification models Describe the relationship among various functions that implement a program. Example of a specification model: Algebraic data types - describe the meaning in terms of algebraic operations, e.g. pop(push(S,x)) = S


Download ppt "Chapter 4: Language Semantics The need for language semantics: a. for the programmer - to know how to use language constructs b. for the implementor -"

Similar presentations


Ads by Google