General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Introduction of specification modulesRunning ExampleIn this section we introduce an example for a language implementation task. It is used in the descriptions of the library modules of this document wherever possible. It shall serve to demonstrate the use of the modules in the context of a complete specification. Of course, such examples can only show certain aspects of the modules. They can not demonstrate their complete functionality and the variety and flexibility of possible applications. Although the example is taken from the area of programming language implementation, similar tasks are to be solved if languages for other purposes than programming, or programming languages with other characteristics are implemented.
Complete executable specifications for this running example
are available in the directories For the purpose of this example we assume that a small artificial programming language is to be implemented. The basic constructs of the language are nested blocks, declarations of variables and of names for values, assignment statements and expressions as specified by the following concrete grammar. The overall program structure is given by Program: Source. Source: Block. Block: Compound. Compound: 'begin' Declaration* Statement* 'end'.Variable declarations specify the types of the declared variables: Declaration: 'var' ObjDecls ';'. ObjDecls: ObjDecl // ','. ObjDecl: TypeDenoter Ident. TypeDenoter: Ident.For the start of this example there is only a set of predefined type identifiers. In the type analysis section the language is extended by introduction of further types and denoters for them. For the time being there are only three forms of statements: Statement: Expression ';'. Statement: Variable '=' Expression ';' Statement: Block.Further statements are added when necessary to explain aspects of module use. The expression syntax is left incomplete here in order to introduce operators of different precedence levels (see Language-defined operators of Type Analysis). If one wants to complete this grammar without adding operators one should add the production Expression: Operand.The basic operands are Operand: IntNumber. Operand: RealNumber. Operand: Variable. Variable: Ident. The non-literal tokens are defined by Ident: PASCAL_IDENTIFIER IntNumber: PASCAL_INTEGER RealNumber: PASCAL_REAL PASCAL_COMMENT The above grammar is chosen such that the solution of language implementation tasks of name analysis, type analysis, and translation by using library modules can be demonstrated. It is also prepared to demonstrate the combination of different module uses. The grammar is extended where necessary in the examples of subsequent sections. |