Tutorial Elegant
210 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
210 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

An Introduction to ElegantSecond EditionPaul JansenLex AugusteijnHarm MunkPhilips Research LaboratoriesProf. Holstlaan 45656 AA EindhovenThe NetherlandsFirst Published 1993 byPhilips Research LaboratoriesPO Box 800005600 JA EindhovenThe NetherlandsPrinted in the Netherlands.Table of ContentsPreface 1Tutorial Overview 2Acknowledgments 2Preface to the Second Edition 3Preface to the Third Edition 3CHAPTER 1 Introduction 51.1 What is Elegant? 51.2 The Programming Language Elegant 81.3 The Compiler Generator Elegant 10CHAPTER 2 Getting Started 132.1 Installing Elegant 132.2 The Elegant Environment 142.3 A Very Simple Program 15CHAPTER 3 Programming in Elegant 173.1 The Elegant Type System 173.1.1 Introduction 173.1.2 Predefined Types 183.1.2.1 Basic Types 183.1.2.2 Structured Types 193.1.2.3 Empty Types 203.1.3 User Defined Types 213.1.3.1 Enumerated Types 213.1.3.2 Record Types 213.2 Functions 273.2.1 Introduction 273.2.2 Rules 293.2.3 Patterns 293.2.4 Conditions 313.2.5 Local Section 323.2.6 Statements 333.2.7 Expressions 343.2.7.1 The Iteration Expression 363.2.8 Special Use of Functions 383.2.8.1 Operators 383.2.8.2 Polymorphic Functions 403.2.8.3 Higher Order Functions* 413.2.9 Statements and their Types* 433.2.9.1 Coercion and Nameless Functions 433.2.9.2 Statements as Expressions 443.2.9.3 Empty Types and Output 453.3 Evaluation 493.3.1 Eager Evaluation 503.3.2 Lazy Evaluation* 503.3.3 Recurring Evaluation* 533 ...

Informations

Publié par
Nombre de lectures 11
Langue English

Extrait

An Introduction to Elegant
Second Edition
Paul Jansen
Lex Augusteijn
Harm Munk
Philips Research Laboratories
Prof. Holstlaan 4
5656 AA Eindhoven
The NetherlandsFirst Published 1993 by
Philips Research Laboratories
PO Box 80000
5600 JA Eindhoven
The Netherlands
Printed in the Netherlands.Table of Contents
Preface 1
Tutorial Overview 2
Acknowledgments 2
Preface to the Second Edition 3
Preface to the Third Edition 3
CHAPTER 1 Introduction 5
1.1 What is Elegant? 5
1.2 The Programming Language Elegant 8
1.3 The Compiler Generator Elegant 10
CHAPTER 2 Getting Started 13
2.1 Installing Elegant 13
2.2 The Elegant Environment 14
2.3 A Very Simple Program 15CHAPTER 3 Programming in Elegant 17
3.1 The Elegant Type System 17
3.1.1 Introduction 17
3.1.2 Predefined Types 18
3.1.2.1 Basic Types 18
3.1.2.2 Structured Types 19
3.1.2.3 Empty Types 20
3.1.3 User Defined Types 21
3.1.3.1 Enumerated Types 21
3.1.3.2 Record Types 21
3.2 Functions 27
3.2.1 Introduction 27
3.2.2 Rules 29
3.2.3 Patterns 29
3.2.4 Conditions 31
3.2.5 Local Section 32
3.2.6 Statements 33
3.2.7 Expressions 34
3.2.7.1 The Iteration Expression 36
3.2.8 Special Use of Functions 38
3.2.8.1 Operators 38
3.2.8.2 Polymorphic Functions 40
3.2.8.3 Higher Order Functions* 41
3.2.9 Statements and their Types* 43
3.2.9.1 Coercion and Nameless Functions 43
3.2.9.2 Statements as Expressions 44
3.2.9.3 Empty Types and Output 45
3.3 Evaluation 49
3.3.1 Eager Evaluation 50
3.3.2 Lazy Evaluation* 50
3.3.3 Recurring Evaluation* 53
3.3.4 Incremental Ev 54
3.3.5 An Application of Incremental Evaluation 57
3.3.6 Evaluation in Practice* 60
3.4 Units 61
3.4.1 Import and Export 62
3.4.2 Global Variables 63
3.4.3 Constants 64
3.4.4 Predefined Units: Preludes 64
CHAPTER 4 Constructing a Compiler 67
4.1 Introduction 67
4.1.1 Compilers and Compiler Generators 67
4.1.2 Using the Tools 69
4.1.3 How to Read this Chapter 71
4.1.4 The Programming Language RPL 72
4.2 Syntax Analysis 74
4.2.1 The Parser 74
4.2.1.1 Basic Concepts 74
4.2.1.2 The Bnf Tool 77
4.2.1.3 The RPL Grammar 77
4.2.2 The Scanner Generator 794.2.2.1 Basic Concepts 79
4.2.2.2 Specifying Terminals 80
4.2.2.3 The SCAN File 82
4.2.2.4 The RPL Scanner 83
4.2.3 Integrating Parser and Scanner 84
4.2.4 The Complete RPL Grammar 88
4.3 Syntax Diagrams 90
4.3.1 Generating Diagrams 90
4.3.2 Smoothing Diagrams 91
4.3.3 Using the Diagrams Tool 94
4.3.4 The RPL Syntax Diagrams 95
4.4 The Abstract Syntax Graph 97
4.4.1 Basic Concepts 97
4.4.2 Static Semantics 100
4.4.2.1 Designing the Static Semantics 101
4.4.2.2 The Static Semantics of RPL 104
4.4.3 Basic Symbol Tables 105
4.4.3.1 Why Symbol Tables? 105
4.4.3.2 Symbol Tables in Elegant 106
4.4.4 Integrating Static Semantics and the Symbol Table 108
4.4.4.1 Attribute Grammars in Elegant 108
4.4.4.2 Building an Abstract Syntax Graph Generator 111
4.4.4.3 Synchronization 116
4.4.4.4 Cutting Cycles 118
4.4.5 More Complex Symbol Table Systems 121
4.4.5.1 Scopes 121
4.4.5.2 Name Spaces 126
4.4.5.3 Cycle Detection 130
4.4.5.4 Declare before Use 131
4.5 Code Generation 132
4.5.1 Introduction 132
4.5.2 The Definition of Characteristic Concepts 133
4.5.3 Implementing a Code Generator 134
4.5.3.1 Sequenced Translations 136
4.5.3.2 Distributed Translations and Relations 136
4.5.4 Layout of the Generated Code 139
4.5.5 Code Optimization 140
Appendices 143
A Programming Language Inquiry 143
B Command Line Switches and Arguments 145
C Cross Generation 146
C.1 Generating an Elegant 7.0 Executable for a PC under MS-DOS 146
C.1.1 Required PC software and hardware 146
C.1.2 Assumed knowledge 146
C.1.3 Preparing your PC 147
C.1.4ing Your Files Under Unix 150
C.1.5 Building Your Application on MS-DOS 151
C.1.6 Long File Names 152
D Elegant Make Facilities 152
E The ASCII Character Set 154
F Elegant Syntax Diagrams 156G RPL Compiler Source Code 165
File: Grammar/RPL.agdl 165ammar/RPL.bnf 172
File: Grammar/RPL.dbnf 172
File: Grammar/RPL.scan 173
Module: CGN/Bindings 174
Module: CGN/CodeGen 175
Module: CGN/Finit 182
Module: CGN/Init 182
Module: CGN/Operators 183
Module: CGN/StaticSemantics 185
Module: CGN/Switches 186
Module: CGN/SymbolTable 187
Bibliography 191Preface
Elegant is a compiler generator system which is supported by a high level programming
language. In december 1992 version 6 of the compiler generator Elegant was released.
The public domain version (7.0) was released in june 1997.
Due to the lacking of proper introductory documentation, Elegant has been only a local
success until now. The Elegant reference manual [2] which is available is meant for
computer scientists who are already experienced in the field of compiler generation.
Unexperienced compiler builders who were not in the neighborhood of an Elegant
expert were left to their devices. This tutorial tries to guide people who are relatively
new to the subject of compiler generation. It is meant to get people acquainted with the
compiler generator Elegant and its supporting programming language without outside
help. It does not give an entire overview of the programming language and the compiler
generation tool set. Only those parts are explained which encourage the use of the so-
called Elegant house style. The Elegant house style is a sound and trusty way of con-
structing compilers and writing programs in Elegant.
Unexperienced Elegant users may skip the (sub)sections which are marked with an
asterisk on first reading. Sometimes readers are referred to the reference manual for
more information about some topic. To save forests, references to the reference manual
are encrypted by the code “chxpy” which means “see chapter x page y of the reference
manual”.
The latest major release of Elegant is available on the most frequently used platforms of
today. These are Sun4, Solaris, HP700, Silicon Graphics, Linux and PC-DOS. For the
latter two platforms only a so-called cross generation version exists. Elegant is available
on the World Wide Web as a public domain tool. It is subject to the Gnu General Public
License [4].
TitleBook 1Preface
Tutorial Overview
In this subsection we will give a brief overview of this tutorial by giving a summary of
the contents of each chapter.
Chapter [1] gives an informal introduction to Elegant. The history of the compiler gen-
erator Elegant is described and some basic concepts are defined. Besides the compiler
generator, also its supporting programming language is paid attention to. Both the pro-
gramming language and the compiler generator are compared to other products in the
same field by means of a comparative inquiry.
Chapter 2 deals with practical aspects of Elegant. It describes how one can obtain an
Elegant environment. Furthermore, the primary steps which have to be taken when writ-
ing an Elegant program are explained. A brief sample program is shown in order to
make clear how Elegant programs can be compiled and executed.
The heart of the tutorial consists of the chapters [3] and [4]. In chapter [3] the program-
ming language Elegant is described in detail. First of all, the type system of Elegant is
explained. After that functions and other important language constructs will be clarified.
Subsequently, attention is paid to the demand driven evaluation aspects of the program-
ming language. Finally, we will deal with the notion of compilation units in Elegant.
The subject of chapter [4] is Elegant as a compiler generator. In this chapter a general
sketch of generating a compiler is given. After that each stage of the compiler construc-
tion path is described in detail. As an example we will build a compiler for a program-
ming language which is especially designed for this tutorial. This programming
language is called RPL. It is designed in such a general way that compiler builders may
borrow parts of the implementation of its compiler. The contents of chapter [3] is
assumed to be known when reading chapter [4] (including the sections marked with an
asterisk). In contrast with the more declarative set up of chapter [3], chapter [4] is oper-
ationally oriented. Experienced users may therefore start with chapter [4] reading only
parts of chapter [3] if they need detailed information about some aspect of the program-
ming language.
Acknowledgments
During the creation of this tutorial I was assisted by various people in various ways.
Here, I want to thank especially Lex Augusteijn who extended Elegant faster than I
could possibly write. Fortunately, he went on holidays for two weeks so that I was able
to finish the text. Another person who was very important for bringing about this tutorial
was Herman ter Horst. I hereby declare him Master of Review. His punctuality and
acuteness were embarrassing. I also wish to thank the other reviewers, in particular Frits
Schalij.
Besides this, some social support was vital. Paul Gorissen was in charge of getting in
soft drinks continuously. My wife, Luciënne, capering muse, took the other social tasks
on. Thanks, thanks.
2 TitleBook Preface to the Second Edition
Eind

  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents