Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical.
Published byModified over 7 years ago
Presentation on theme: "Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical."— Presentation transcript:
Language Specfication and Implementation - PART II: Semantics of Procedural Programming Languages Lee McCluskey Department of Computing and Mathematical Sciences Web Site: http://scom.hud.ac.uk/scomtlm/cas2545
Aims To give you a DEEP understanding of the meaning and structure of (programming) languages.. So that in the future when you encounter a new one you can analyse and classify it - and hence easily pick it up
Content This Module will concentrate on PROGRAM LANGUAGE SEMANTICS - specifically DENOTATIONAL SEMANTICS.
Last Term’s Work: - Functional PL: Haskell/Gofer - Lambda Calculus - Reductions, Normal forms, Fixed Points, Church - Rosser Theorem.. - Functional PL + Lambda Calculus relationship - Operational Semantics of Functional PL, type checking + type inference - Implementation of FPL’s
This Term’s Work: -- Denotational Semantics of basic Imperative PL Control Structures (using Lambda Calculus) -- Prototyping the Denotational Semantics using Haskell -- Algebraic Semantics of Data Types (Objects)
Kinds of (Programming) Languages GENERAL PLs e.g. C,Java,Haskell, Pascal, Ada, Prolog.. fall into 3 groups depending on their underlying model of computation: Procedural (state change) Functional (function evaluation) Logic (logical inference) SPECIALIST PLs e.g. Maths, Web, Multimedia, Database, Op Sys
SYNTAX..is all about the set of symbols allowed in a language and the order in which they may be written. This is usually specified in a structured, compositional manner, e.g.: sentence := noun verb noun “.” loop := “WHILE” exp “DO” stm This can be very subtle e.g. what is the role of a ‘;’ in Java vs. the role of ‘;’ in Pascal?
SEMANTICS..is all about the relationship between the symbols in a language and their meaning. The meaning of a language is often defined by ascribing meaning to the grammatical components of the language. E.g. semantics(“REPEAT” stm “UNTIL” exp) = execute stm, then check if exp is true; if it is then halt else execute REPEAT again
SEMANTICS- EXAMPLE WHAT CAN YOU SAY ABOUT THE FOLLOWING COMMANDS? X := X+1 (Pascal) X = X+1 ( C ) X++ ( C )
PRAGMATICS..is all about the use or utility of the components of a language. To write complex programs we use decomposition: procedures/methods solve sub-problems of the main problem abstraction: objects encapsulate the representation of a data type, procedures/methods encapsulate the particular algorithm used to solve the sub-problem. Reasoning: documentation, invariants, long variable names all help us to reason about the workings of a program None of these add to the computational power of a PL!
RELATED CONCEPTS Semiotics – the science of SIGNS and SYMBOLS – esp. their form and meaning Linguistics – as semiotics but specific to the SYMBOLS contained in a language Syntax can be broken up into: Morphology – make-up of words Grammar – legal orderings of words, the structure of the phrases and sentences language
SEMANTICS.. WHY?..There are many uses for semantic definitions: compiler specification documentation analysis / classification of a language checking properties of a language standardisation deriving proofs of correctness of programs
Semantics: Different Definitions Natural Language Semantics Axiomatic Semantics Operational Semantics Denotational Semantics
Natural Language Semantics Giving the meaning of (components of) a language in pure natural language form. The meaning may well suffer from ambiguities and inconsistencies typical in such definitions. It has been said that there have been no correct definitions of usable languages completed in natural language
Axiomatic Semantics Commands change states: each command in the language is given a meaning in terms of axioms / inference rules which defines how the command changes a program “state” Commands are defined in terms of pre- and post- conditions on states AS are good for proving the (partial) correctness of programs.
Operational Semantics Language components are defined in terms of a simple, well-defined abstract “machine”. Operational Semantics are good for proving the implementation of a PL correct.
Denotational Semantics Syntax Classes are mapped via “meaning functions” to a mathematical language - typically lambda calculus A denotational definition usually consists of - the (abstract) syntax of the language a set of meaning functions for each of the syntax classes
Denotational Semantics: Revision You will need to revise: sets and functions Functional Programming Syntax Definitions (BNF)
Exercises Look up the definition of some of the key concepts in this lecture on the internet eg Semiotics, linguistics, semantics, meaning, denotation, syntax, grammar, pragmatics, morphology, phrase structure Try to relate the concepts using a diagram. Write down a “one line” definition of each concept.