1 / 15

Chapter 4: Language Semantics

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. Semantics.

chavez
Download Presentation

Chapter 4: Language Semantics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 descriptionsof 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 Rule Attribute E  E + T value (E1) = value (E2) + value(T) E  T value (E) = value (T) T  T * P value (T1) = value (T2) * value (P) T  P value (T) = value (P) P  I value (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: INPUT OUTPUT 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

More Related