r eusable s emant ic s pecif icat ions of p rogramming
play

R eusable S emant ic S pecif icat ions of P rogramming Languages - PDF document

R eusable S emant ic S pecif icat ions of P rogramming Languages Jose Emilio Labra Gayo Department of Computer Science University of Oviedo - Spain April - 2002 1 This talk in 1 We need formal techniques to specify the semantics of


  1. R eusable S emant ic S pecif icat ions of P rogramming Languages Jose Emilio Labra Gayo Department of Computer Science University of Oviedo - Spain April - 2002 1 This talk in 1’ • We need formal techniques to specify the semantics of programming languages, but... – Traditional existing techniques lack modularity and reusability • In my PhD, I proposed a technique that combines: – Monads (...inspired from Haskell...) – Generic programming (...catamorphisms...) • I specified – Simple functional, imperative, object-oriented and logic programming languages 2 1

  2. Introduction Programming Languages • Programming Language – Notation used by a programmer (person) to transmit to the computer (machine) an intended behaviour Program program Sum int x, y; Programmer Computer begin read x; read y; write x+y Intended behaviour: end Add 2 integers Trade-off between the needs of humans and computers Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 3 Introduction Lenguage Processors • Language Processor – Analizes the intended behaviour of programs written in a language – Either executes the instructions ( interpreter ) or builds an equivalent program in a different language ( compiler ) Data Interpreter Program Programmer Results • The language processor is obtained from the specification of the programming language – That specification must describe useful computations – And it should be architecture independent Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 4 2

  3. Introduction Language Processors Traditional Modular decomposition of a language processor – Identifies processes Execution/ Lexical Syntax Static Program Code analysis analysisr analysis Generation Problem Given a language processor formed by Arithmetic expressions, loops and conditionals • Where is the code corresponding to arithmetic expressions? • Which modules do we have to modify to add boolean expressions? • Is it possible to reuse the source code of this processor to build the processor of a new language? GNU C++ compiler gcc 1.0 278949 lines of code 168 separate files Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 5 Introduction Language Processors • A different kind of modular decomposition... Language A Language B Modularity Arithmetic Abstractions Expressions Local While declarations loops Objects Conditionals Arithmetic Expressions Boolean Expressions Reusability Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 6 3

  4. Introduction Semantic Specification ...A labeled st at ement is execut ed by execut ing t he immediat ely cont ained St at ement . I f t he st at ement is labeled by an I dent if ier and t he cont ained St at ement complet es abr upt ly because of a br eak wit h t he same I dent if ier , t hen t he labeled st at ement complet es nor mally. I n all ot her cases of abr upt complet ion of t he St at ement , t he labeled st at ement complet es abr upt ly f or t he same r eason.... (J ava Language Specif icat ion 2nd. Ed) • Semantic specification = Description of program behaviour • Usually made in natural language ? It is flexible and there is experience in its application ? Modular, reusable, readable (well…, at least, in principle) ? It is also ambiguous and poorly rigorous ? It is not possible: • Prove properties of programs • Check correctness of a given language processor • Automatically obtain a language processor • Ideal requisites of a semantic specification technique � Non ambiguity � Prove properties � Modularity � Reusability � Automatically generate language processor (or prototype) � Flexibility � Experience � Readability Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 7 Comparison of Specification Techniques • Introduction • Comparison of semantic specification techniques – Structured operational semantics – Natural semantics – Denotational semantics – Axiomatic semantics – Algebraic semantics – Abstract State Machines (ASM) – Action Semantics • Modular Monadic Semantics • Generic Programming • Reusable Monadic Semantics • Conclusions 8 4

  5. Comparison of techniques Structured Operational Semantics [Plotkin, 81] • Operations are defined using inference rules eval : Expr ? Int eval eval ? e 1 ? ? e 2 ? v 1 v 2 eval eval ? Const n ? ? Add e 1 e 2 ? v 1 + v 2 n If we add variables... eval : (Expr, Env ) ? Int eval eval ? e 1 , ? ? ? e 2 , ? ? v 1 v 2 eval eval ? Const n, ? ? ? Add e 1 e 2 , ? ? ? Var x, ? ? eval lkp x ? n v 1 + v 2 Assessment ? Flexibility ? Proof ? Modularity ? Experience ? Prototype ? Reusability Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 9 Comparison of techniques Natural Semantics [Kahn, 87] • Similar to structured operational semantics but it just describes the relationship between the initial and final state • Several tools to develop prototypes from natural semantic specifications (Centaur, RML, etc.) • Several real languages specified using this approach (e.g. ML) • Same modularity and reusability problems as structured operational semantics Assessment ? Flexibility ? Proof ? Modularity ? Experience ? Reusability ? Prototype Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 10 5

  6. Comparison of techniques Denotational Semantics [Strachey , Scott, 69] • Each component of the language = mathematical entity defined using ambda calculus and domain theory • Facilitates proof of properties ? _ ? : Term ? I nt If we add variables ... ? _ ? : Ter m ? Env ? I nt ? Add e 1 e 2 ? = ? e 1 ? + ? e 2 ? ? Const n ? = n ? Add e 1 e 2 ? ? = ? e 1 ? ? + ? e 2 ? ? ? Const n ? ? = n ? Var x ? ? = lkp ? x Assessment ? Flexibility ? Prototype ? Modularity ? Proof ? Experience ? Reusability Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 11 Comparison of techniques Axiomatic Semantics [Floyd 67, Hoare 69] • Language properties are described using axioms in a logical system with assertions, preconditions and postconditions • Facilitates the proof of properties • Experience in its application to imperative languages Several implementations can follow the axioms ? • Difficult automatization of prototype generation Assessment ? Flexibility ? Modularity ? Proof ? Reusability ? Experience ? Prototype Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 12 6

  7. Comparison of techniques Algebraic Semantics • Roots: Algebraic specification techniques • Algebraic specification: – Signature (sorts and operations) – Axioms (properties) using logical equations • Algebra = sets + functions (implements an specification) • Combines denotational, operational and axiomatic semantics • Several specification systems (Obj, ASL, ...) • In [Goguen 96] the specifications are monolithic Assessment ? Proof ? Modularity ? Reusability ? Prototype ? Experience ? Flexibility Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 13 Comparison of techniques Abstract State Machines • Roots: Evolving Algebra and Operational Semantics • Algorithm = state abstraction + transition rules between elements of that state • Modularity is achieved by specializing the abstract state • Several industrial applications in the specification of languages and protocols • Tools for prototype generation Assessment ? Prototype ? Proof ? Experience ? Flexibility ? Modularity ? Reusability Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 14 7

  8. Comparison of techniques Action Semantics [Mosses 92] • Assigns actions to language constructions • Primitive actions and action combinators • Types of actions are described using facets that represent computational aspects ? semantic modularity • Emphasis on readability • Action notation uses operational semantics • Recent developments trying to add reusability [Doh,Mosses 01] Assessment ? Modularity ? Proof ? Prototype ? Experience ? Readability ? Flexibility ? Reusability Reusable Monadic S emant ics of P rogramming Languages - J . E. Labra 15 Modular Monadic Semantics • Introduction • Comparison of techniques • Modular Monadic Semantics – Monads – Monad transformers – Extensible domains – Assessment • Generic Programming • Reusable Monadic Semantics • Conclusions 16 8

Recommend


More recommend