Definitions of Dynamic Semantics
Total Page:16
File Type:pdf, Size:1020Kb
Institut für Technische Informatik und Kommunikationsnetze Computer Engineering and Networks Laboratory TIK-SCHRIFTENREIHE NR. XXX Philipp W. Kutter Montages — Engineering of Computer Languages Eidgenössische Technische Hochschule Zürich Swiss Federal Institute of Technology Zurich A dissertation submitted to the Swiss Federal Institute of Technology Zurich for the degree of Doctor of Technical Sciences Diss. ETH No. 13XXX Prof. Dr. Lothar Thiele, examiner Prof. Dr. Martin Odersky, co-examiner Examination date: xxxxx xx, 2003 I would like to thank to my father, Gerhard R¨udiger Kutter, whose answers to my questions about his work with fourth generation languages in banking software have been a seed from my childhood, which has grown to this thesis. To my marvelous wife, Enza, to my children, Nora-Manon Alma Stella and Ana¨el Gerhard Victor-Maria, to my mother and my sister. To the Montages team, Alfonso Pierantonio and Matthias Anlauff, to Florian Haussman, who was there when everything started, and to my scientific advisors, Lothar Thiele, Yuri Gurevich, and Martin Odersky. For various comments on content and form of the thesis I am thanksfull mainly to Chuck Wallace, but as well to Marjan Mernik, Welf L¨owe, Asuman S¨unb¨ul, Arnd Poetzsch-Heffter, and Dimidios Spinellis. For inspiring discussions on related areas, thanks to Craig Cleaveland, David Weiss, Grady Campbell, Erich Gamma, Peter Mosses, Dusko Pavlovic. For helpfull insight in the business aspects of Montages, I would like to thank Denis McQuade and Hans-Peter Dieterich. Contents 1 Introduction 1 I Engineering of Computer Languages 7 2 Requirements for Language Engineering 9 2.1 Problem Statement . ...................... 11 2.2 Typical Application Scenario . .................. 14 2.2.1 Situation . ...................... 14 2.2.2 Problem . ...................... 15 2.2.3 DSL Solution . ...................... 16 2.2.4 Conclusions and Related Applications . .... 17 2.3 Designing Domain Specific Languages . ........... 19 2.4 Reusing Existing Language Designs . ........... 23 2.5 Safety, Progress, and Security .................. 26 2.6 Splitting Development Cycles .................. 28 2.7 Requirements for a Language Description Formalism . .... 31 2.8 Related Work . ...................... 32 3 Montages 37 3.1 Introduction . ...................... 38 3.2 From Syntax to Abstract Syntax Trees (ASTs) . .... 48 3.2.1 EBNF rules . ...................... 48 3.2.2 Abstract syntax trees . .................. 48 3.3 Dynamic Semantics with Tree Finite State Machines (TFSMs) . 51 3.3.1 Example Language Ë ................... 53 3.3.2 Transition Specifications and Paths ........... 57 3.3.3 Construction of the TFSM . ........... 60 3.3.4 Simplification of TFSM . ........... 63 3.3.5 Execution of TFSMs . .................. 64 3.4 Lists, Options, and non-local Transitions . ........... 65 3.4.1 List and Options . .................. 65 3.4.2 Extension of InstantiateTransitions . ........... 67 3.4.3 Global Paths . ...................... 69 3.4.4 Algorithm InstantiateTransition . ........... 70 iv Contents 3.4.5 The Goto Language . .................. 72 3.5 Related Work and Results . .................. 75 3.5.1 Influence of Natural Semantics and Attribute Grammars 75 3.5.2 Relation to subsequent work on semantics using ASM . 76 3.5.3 The Verifix Project . .................. 76 3.5.4 The mpC Project . .................. 77 3.5.5 Active Libraries, Components, and UML . .... 78 3.5.6 Summary of Main Results . ........... 79 II Montages Semantics and System Architecture 85 4 eXtensible Abstract State Machines (XASM)93 4.1 Introduction to ASM . ...................... 95 4.1.1 Properties of ASMs . .................. 95 4.1.2 Programming Constructs of ASMs . ........... 97 4.2 Formal Semantics of ASMs . ..................102 4.3 The XASM Specification Language . ...........106 4.3.1 External Functions . ..................107 4.3.2 Semantics of ASM run and Environment Functions . 110 4.3.3 Realizing External Functions with ASMs . ....112 4.4 Constructors, Pattern Matching, and Derived Functions . ....116 4.4.1 Constructors . ......................116 4.4.2 Pattern Matching . ..................116 4.4.3 Derived Functions . ..................117 4.4.4 Relation of Function Kinds . ...........118 4.4.5 Formal Semantics of Constructors . ...........118 4.5 EBNF and Constructor Mappings . ...........120 4.5.1 Basic EBNF productions . ...........120 4.5.2 Repetitions and Options in EBNF . ...........122 4.5.3 Canonical Representation of Arbitrary Programs ....123 4.6 Related Work and Results . ..................126 5 Parameterized XASM 129 5.1 Motivation .............................131 5.2 The $, Apply, and Update Features . ...........133 5.2.1 The $ Feature . ......................133 5.2.2 The Apply and Update Features . ...........134 5.3 Generating Abstract Syntax Trees from Canonical Representa- tions . .............................135 5.3.1 Constructing the AST ..................135 5.3.2 Navigation in the Parse Tree . ...........137 5.3.3 Examples: Abrupt Control Flow and Variable Scoping . 138 5.4 The PXasm Self-Interpreter . ..................141 5.4.1 Grammar and Term-Representation of PXasm . ....141 Contents v 5.4.2 Interpretation of symbols . ...........143 5.4.3 Definition of INTERP( ).................143 5.5 The PXasm Partial Evaluator . ..................147 5.5.1 The Partial Evaluation Algorithm . ...........147 5.5.2 The do-if-let transformation for sequentiality in ASMs . 154 5.6 Related Work and Conclusions ..................156 6 TFSM: Formalization, Simplification, Compilation 159 6.1 TFSM Interpreter . ......................159 6.1.1 Interpreter for Non-Deterministic TFSMs . ....160 6.1.2 Interpreter for Deterministic TFSMs ...........162 6.2 Simplification of TFSMs . ..................164 6.3 Partial Evaluation of TFSM rules and transitions . ....164 6.4 Compilation of TFSMs ......................166 6.5 Conclusions and Related Work ..................169 7 Attributed XASM 171 7.1 Motivation and Introduction . ..................172 7.1.1 Object-Oriented versus Procedural Programming ....172 7.1.2 Functional Programming versus Attribute Grammars . 174 7.1.3 Commonalities of Object Oriented Programming and Attribute Grammars . ..................175 7.1.4 AXasm = XASM + dynamic binding ...........175 7.1.5 Example . ......................177 7.2 Definition of AXasm . ......................179 7.2.1 Derived Functions Semantics . ...........179 7.2.2 Denotational Semantics . ...........180 7.2.3 Self Interpreter Semantics . ...........184 7.3 Related Work and Results . ..................193 8 Semantics of Montages 195 8.1 Different Kinds of Meta-Formalism Semantics . ....196 8.2 Structure of the Montages Semantics . ...........198 8.2.1 Informal Typing . ..................198 8.2.2 Data Structure ......................198 8.2.3 Algorithm Structure . ..................200 8.3 XASM definitions of Static Semantics . ...........201 8.3.1 The Construction Phase . ...........201 8.3.2 The Attributions and their Collection . ....201 8.3.3 The Static Semantics Condition . ...........202 8.4 XASM definitions of Dynamic Semantics . ...........204 8.4.1 The States . ......................204 8.4.2 The Transitions ......................205 8.4.3 The Transition Instantiation . ...........205 8.4.4 Implicit Transitions . ..................211 vi Contents 8.4.5 The Decoration Phase ..................211 8.4.6 Execution . ......................212 8.5 Conclusions and Related Work ..................214 III Programming Language Concepts 217 9 Models of Expressions 223 9.1 Features of ExpV1 . ......................223 9.1.1 The Atomar Expression Constructs ...........224 9.1.2 The Composed Expression Constructs . ....224 9.2 Reuse of ExpV1 Features . ..................231 10 Models of Control Flow Statements 233 10.1 The Example Language ImpV1 ..................234 10.2 Additional Control Statements ..................236 11 Models of Variable Use, Assignment, and Declaration 241 11.1 ImpV2: A Simple Name Based Variable Model . ....242 11.2 ImpV3: A Refined Tree Based Variable Model . ....244 11.3 ObjV1: Interpreting Variables as Fields of Objects . ....248 12 Classes, Instances, Instance Fields 251 12.1 ObjV2 Programs . ......................252 12.2 Primitive and Reference Type . ..................253 12.3 Classes and Subtyping ......................254 12.4 Object Creation and Dynamic Types . ...........255 12.5 Instance Fields . ......................255 12.6 Dynamic Binding . ......................256 12.7 Type Casting . ......................262 13 Procedures, Recursive-Calls, Parameters, Variables 263 13.1 ObjV3 Programs . ......................263 13.2 Call Incarnations . ......................265 13.3 Semantics of Call and Return . ..................265 13.4 Actualizing Formal Parameters ..................269 14 Models of Abrupt Control 271 14.1 The Concept of Frames ......................272 14.2 FraV1: Models of Iteration Constructs . ...........275 14.3 FraV2: Models of Exceptions . ..................281 14.4 FraV3: Procedure Calls Revisited . ...........286 Contents vii IV Appendix 291 A Kaiser’s Action Equations 293 A.1 Introduction . ......................294 A.2 Control Flow in Action Equations . ...........295 A.3 Examples of Control Structures ..................296 A.4 Conclusions . ......................301 B Mapping Automata 303 B.1 Introduction . ......................304 B.2 Static structures . ......................304 B.2.1 Abstract structure of the state . ...........304 B.2.2 Locations