Super Prev Next

Collected Modula-2 Concrete Syntax


Super Prev Next

Programs, Program Modules, and Separate Modules


Super Prev Next

Programs and Compilation Modules

compilation module=
program module | definition module | implementation module ;


Super Prev Next

Program Modules

program module=
"MODULE", module identifier, [ interrupt protection ], ";",
import lists,
module block, module identifier, "." ;

module identifier= identifier ;


Super Prev Next

Definition Modules

definition module=
"DEFINITION", "MODULE", module identifier, ";",
import lists,
definitions,
"END", module identifier, "." ;


Super Prev Next

Implementation Modules


Super Prev Next

Sourced Implementation Modules

implementation module=
"IMPLEMENTATION", "MODULE", module identifier, [ interrupt protection ], ";",
import lists,
module block, module identifier, "." ;


Super Prev Next

Import Lists

import lists= { import list } ;

import list= simple import | unqualified import ;

simple import= "IMPORT", identifier list, ";" ;

unqualified import= "FROM", module identifier, "IMPORT", identifier list, ";" ;


Super Prev Next

Export Lists

export list= unqualified export | qualified export ;

unqualified export= "EXPORT", identifier list, ";" ;

qualified export= "EXPORT", "QUALIFIED", identifier list, ";" ;


Super Prev Next

Protected Modules

interrupt protection= "[", protection expression, "]" ;

protection expression= constant expression ;


Super Prev Next

Definitions and Declarations


Super Prev Next

Qualified Identifiers

qualified identifier= { qualifying identifier, "." }, identifier ;

qualifying identifier= module identifier ;


Super Prev Next

Definitions

definitions= { definition } ;

definition=
"CONST", { constant declaration, ";" } |
"TYPE", { type definition, ";" } |
"VAR", { variable declaration, ";" } |
procedure heading, ";" ;


Super Prev Next

Type Definitions

type definition= type declaration | opaque type definition ;

opaque type definition= identifier ;


Super Prev Next

Procedure Headings

procedure heading= proper procedure heading | function procedure heading ;


Super Prev Next

Proper Procedure Headings

proper procedure heading=
"PROCEDURE", procedure identifier, [ formal parameters ] ;

formal parameters= "(", [ formal parameter list ], ")" ;

formal parameter list= formal parameter, { ";", formal parameter } ;


Super Prev Next

Function Procedure Headings

function procedure heading=
"PROCEDURE", procedure identifier, formal parameters, ":", function result type ;

function result type= type identifier ;


Super Prev Next

Formal Parameters

formal parameter=
value parameter specification | variable parameter specification ;

value parameter specification= identifier list, ":", formal type ;

variable parameter specification= "VAR", identifier list, ":", formal type ;


Super Prev Next

Declarations

declarations= { declaration } ;

declaration=
"CONST", { constant declaration, ";" } |
"TYPE", { type declaration, ";" } |
"VAR", { variable declaration, ";" } |
procedure declaration, ";" |
local module declaration, ";" ;


Super Prev Next

Constant Declarations

constant declaration= identifier, "=", constant expression ;


Super Prev Next

Type Declarations

type declaration= identifier, "=", type denoter ;


Super Prev Next

Variable Declarations

variable declaration= variable identifier list, ":", type denoter ;

variable identifier list=
identifier, [ machine address ], { ",", identifier, [ machine address ] } ;

machine address= "[", value of address type, "]" ;

value of address type= constant expression ;


Super Prev Next

Procedure Declarations

procedure declaration=
proper procedure declaration | function procedure declaration ;

proper procedure declaration=
proper procedure heading, ";",
( proper procedure block, procedure identifier | "FORWARD" ) ;

procedure identifier= identifier ;

function procedure declaration=
function procedure heading, ";",
( function procedure block, procedure identifier | "FORWARD" ) ;


Super Prev Next

Local Module Declarations

local module declaration=
"MODULE", module identifier, [ interrupt protection ], ";",
import lists, [ export list ],
module block, module identifier ;


Super Prev Next

Data Types


Super Prev Next

Type Denoters and Ordinal Type Denoters

type denoter= type identifier | new type ;

ordinal type denoter= ordinal type identifier | new ordinal type ;


Super Prev Next

Type Identifiers

type identifier= qualified identifier ;

ordinal type identifier= type identifier ;


Super Prev Next

New Types

new type=
new ordinal type | set type |
packedset type | pointer type |
procedure type | array type |
record type ;

new ordinal type= enumeration type | subrange type ;


Super Prev Next

Enumeration Types

enumeration type= "(", identifier list, ")" ;

identifier list= identifier, { ",", identifier } ;


Super Prev Next

Subrange Types

subrange type=
[0 pt] [ range type ], "[", constant expression, "..", constant expression, "]" ;

range type= ordinal type identifier ;


Super Prev Next

Set Types

set type= "SET", "OF", base type ;

base type= ordinal type denoter ;


Super Prev Next

Packedset Types

packedset type= "PACKEDSET", "OF", base type ;


Super Prev Next

Pointer Types

pointer type= "POINTER", "TO", bound type ;

bound type= type denoter ;


Super Prev Next

Procedure Types

procedure type= proper procedure type | function procedure type ;

proper procedure type=
"PROCEDURE", [ "(", [ formal parameter type list ], ")" ] ;

function procedure type=
"PROCEDURE", "(", [ formal parameter type list ], ")", ":", function result type ;


Super Prev Next

Formal Parameter Type Lists

formal parameter type list=
formal parameter type, { ",", formal parameter type } ;

formal parameter type=
variable formal type | value formal type ;

variable formal type= "VAR", formal type ;

value formal type= formal type ;


Super Prev Next

Formal Types

formal type= type identifier | open array formal type ;

open array formal type= "ARRAY", "OF", open array component type ;

open array component type= formal type ;


Super Prev Next

Array Types

array type= "ARRAY", index type, { ",", index type }, "OF", component type ;

index type= ordinal type denoter ;

component type= type denoter ;


Super Prev Next

Record Types

record type= "RECORD", field list, "END" ;

field list= fields, { ";", fields } ;

fields= [ fixed fields | variant fields ] ;


Super Prev Next

Fixed Fields

fixed fields= identifier list, ":", field type ;

field type= type denoter ;


Super Prev Next

Variant Fields

variant fields= "CASE", tag field, "OF", variant list, "END" ;

tag field= [ tag identifier ], ":", tag type ;

tag identifier= identifier ;

tag type= ordinal type identifier ;

variant list= variant, { "|", variant }, [ variant else part ] ;

variant else part= "ELSE", field list ;

variant= [ variant label list, ":", field list ] ;

variant label list= variant label, { ",", variant label } ;

variant label= constant expression, [ "..", constant expression ] ;


Super Prev Next

Blocks


Super Prev Next

Proper Procedure Blocks

proper procedure block= declarations, [ procedure body ], "END" ;

procedure body= "BEGIN", block body ;


Super Prev Next

Function Procedure Blocks

function procedure block= declarations, function body, "END" ;

function body= "BEGIN", block body ;


Super Prev Next

Module Blocks

module block= declarations, [ module body ], "END" ;

module body= initialization body, [ finalization body ] ;

initialization body= "BEGIN", block body ;

finalization body= "FINALLY", block body ;


Super Prev Next

Block Bodies and Exception Handling

block body= normal part, [ "EXCEPT", exceptional part ] ;

normal part= statement sequence ;

exceptional part= statement sequence ;


Super Prev Next

Statements

statement=
empty statement | assignment statement | procedure call |
return statement | retry statement | with statement |
if statement | case statement | while statement |
repeat statement | loop statement | exit statement |
for statement ;


Super Prev Next

Statement Sequences

statement sequence= statement, { ";", statement } ;


Super Prev Next

Empty Statements

empty statement= ;


Super Prev Next

Assignment Statements

assignment statement= variable designator, ":=", expression ;


Super Prev Next

Procedure Calls

procedure call= procedure designator, [ actual parameters ] ;

procedure designator= value designator ;


Super Prev Next

Return Statements

return statement= simple return statement | function return statement ;

simple return statement= "RETURN" ;

function return statement= "RETURN", expression ;


Super Prev Next

Retry Statements

retry statement= "RETRY" ;


Super Prev Next

With Statements

with statement= "WITH", record designator, "DO", statement sequence, "END" ;

record designator= variable designator | value designator ;


Super Prev Next

If Statements

if statement= guarded statements, [ if else part ], "END" ;

guarded statements=
"IF", boolean expression, "THEN", statement sequence,
{ "ELSIF", boolean expression, "THEN", statement sequence } ;

if else part= "ELSE", statement sequence ;

boolean expression= expression ;


Super Prev Next

Case Statements

case statement= "CASE", case selector, "OF", case list, "END" ;

case selector= ordinal expression ;

case list= case alternative, { "|", case alternative }, [ case else part ] ;

case else part= "ELSE", statement sequence ;


Super Prev Next

Case Alternatives

case alternative= [ case label list, ":", statement sequence ] ;

case label list= case label, { ",", case label } ;

case label= constant expression, [ "..", constant expression ] ;


Super Prev Next

While Statements

while statement=
"WHILE", boolean expression, "DO", statement sequence, "END" ;


Super Prev Next

Repeat Statements

repeat statement=
"REPEAT", statement sequence, "UNTIL", boolean expression ;


Super Prev Next

Loop Statements

loop statement= "LOOP", statement sequence, "END" ;


Super Prev Next

Exit Statements

exit statement= "EXIT" ;


Super Prev Next

For Statements

for statement=
"FOR", control variable identifier, ":=", initial value,
"TO", final value, [ "BY", step size ], "DO",
statement sequence, "END" ;

control variable identifier= identifier ;

initial value= ordinal expression ;

final value= ordinal expression ;

step size= constant expression ;


Super Prev Next

Variable Designators

variable designator=
entire designator | indexed designator |
selected designator | dereferenced designator ;


Super Prev Next

Entire Designators

entire designator= qualified identifier ;


Super Prev Next

Indexed Designators

indexed designator=
array variable designator, "[", index expression, { ",", index expression }, "]" ;

array variable designator= variable designator ;

index expression= ordinal expression ;


Super Prev Next

Selected Designators

selected designator= record variable designator, ".", field identifier ;

record variable designator= variable designator ;

field identifier= identifier ;


Super Prev Next

Dereferenced Designators

dereferenced designator= pointer variable designator, " " ;

pointer variable designator= variable designator ;


Super Prev Next

Expressions

expression= simple expression, [ relational operator, simple expression ] ;

simple expression= [ sign ], term, { term operator, term } ;

term= factor, { factor operator, factor } ;

factor=
"(", expression, ")" |
logical negation operator, factor |
value designator | function call |
value constructor | constant literal ;


Super Prev Next

Ordinal Expressions

ordinal expression= expression ;


Super Prev Next

Infix Expressions and Operations

relational operator=
equals operator | inequality operator |
less than operator | greater than operator |
less than or equal operator | subset operator |
greater than or equal operator | superset operator |
set membership operator ;

term operator=
plus operator | set union operator |
minus operator | set difference operator |
logical disjunction operator | string catenate symbol ;

factor operator=
multiplication operator | set intersection operator |
division operator | symmetric set difference operator |
rem operator | div operator |
mod operator | logical conjunction operator ;


Super Prev Next

Value Designators

value designator=
entire value | indexed value |
selected value | dereferenced value ;


Super Prev Next

Entire Values

entire value= qualified identifier ;


Super Prev Next

Indexed Values

indexed value= array value, "[", index expression, { ",", index expression }, "]" ;

array value= value designator ;


Super Prev Next

Selected Values

selected value= record value, ".", field identifier ;

record value= value designator ;


Super Prev Next

Dereferenced Values

dereferenced value= pointer value, dereferencing operator ;

pointer value= value designator ;


Super Prev Next

Function Calls

function call= function designator, actual parameters ;

function designator= value designator ;


Super Prev Next

Value Constructors

value constructor= array constructor | record constructor | set constructor ;


Super Prev Next

Array Constructors

array constructor= array type identifier, array constructed value ;

array type identifier= type identifier ;

array constructed value=
"{", repeated structure component, { ",", repeated structure component }, "}" ;

repeated structure component=
structure component, [ "BY", repetition factor ] ;

repetition factor= constant expression ;

structure component=
expression | array constructed value |
record constructed value | set constructed value ;


Super Prev Next

Record Constructors

record constructor= record type identifier, record constructed value ;

record type identifier= type identifier ;

record constructed value=
"{", [ structure component, { ",", structure component } ], "}" ;


Super Prev Next

Set Constructors

set constructor= set type identifier, set constructed value ;

set type identifier= type identifier ;

set constructed value= "{", [ member, { ",", member } ], "}" ;

member= interval | singleton ;

interval= ordinal expression, "..", ordinal expression ;

singleton= ordinal expression ;


Super Prev Next

Constant Literals

constant literal= whole number literal | real literal | string literal ;


Super Prev Next

Constant Expressions

constant expression= expression ;


Super Prev Next

Parameter Compatibility and Argument Binding


Super Prev Next

Actual Parameters

actual parameters= "(", [ actual parameter list ], ")" ;

actual parameter list= actual parameter, { ",", actual parameter } ;

actual parameter= variable designator | expression | type parameter ;


Super Prev

Type Parameters

type parameter= type identifier ;