Objective Modula-2

Latest Update: February 10, 2010

Overview

Frequently Asked Questions

Other Objective-C Inspired Hybrid Languages

The Modula-2 Webring

Visitor Map

Visitor Map - Click to view visits

Objective Modula-2 Grammar


Formal Syntax Definition for Objective Modula-2 in EBNF notation

last revised February 4, 2010

This grammar is also available as a PDF document.

Compilation Units

compilationUnit

programModule | definitionOfModule | implementationOfModule | protocolModule

programModule

MODULE moduleId ( '['priority']' )? ';'
importList* block moduleId

definitionOfModule

DEFINITION MODULE moduleId ';'
importList* definition*
END moduleId '.'

implementationOfModule

IMPLEMENTATION programModule

protocolModule

PROTOCOL protocolId ( '(' adoptedProtocols ')' )? ';'
importList* ( OPTIONAL? methodHeader )*
END protocolId '.'

moduleId

ident

priority

constExpression

protocolId

ident

adoptedProtocols

identList

Import Lists, Blocks, Declarations, Definitions

importList

( FROM moduleId IMPORT ( identList | '*' ) |
IMPORT ident '+'? ( ',' ident '+'? )* ) ';'

block

declaration* ( BEGIN statementSequence )?
END

declaration

CONST ( constantDeclaration ';' )* |
TYPE ( typeDeclaration ';' )* |
VAR ( variableDeclaration ';' )* |
procedureDeclaration ';' |
methodDeclaration ';'

definition

CONST ( constantDeclaration ';' )* |
TYPE ( ident ( '=' ( type | OPAQUE ) | IS namedType ) ';' )* |
VAR ( variableDeclaration ';' )* |
procedureHeader ';' |
methodHeader ';'

Constant Declarations

constDeclaration

ident '=' ( constExpression | structuredValue )

Type Declarations

typeDeclaration

ident ( '=' type | IS namedType )

type

namedType | anonymousType | enumerationType | setType | classType

namedType

qualident

anonymousType

arrayType | recordType | pointerType | procedureType

enumerationType

'(' identList ')' |
ENUM ( '(' baseType ')' )? identList? END

baseType

qualident

arrayType

ARRAY arrayIndex ( ',' arrayIndex )*
OF ( namedType | recordType | procedureType )

arrayIndex

ordinalConstExpression

ordinalConstExpression

constExpression

recordType

RECORD ( ( '(' baseType ')' )? fieldListSequence? END

fieldListSequence

fieldList ( ';' fieldList )*

fieldList

identList ':' ( namedType | arrayType | recordType | procedureType )

classType

<*QUALIFIED*>? CLASS '(' superClass ( ',' adoptedProtocols )? ')'
( ( PUBLIC | MODULE | PROTECTED | PRIVATE )? fieldListSequence )*
END

superClass

qualident

setType

SET OF ( namedType | '(' identList ')' )

pointerType

POINTER TO IMMUTABLE? namedType

procedureType

PROCEDURE ( '(' formalTypeList ')' )? ( ':' returnedType )?

formalTypeList

attributedFormalType ( ',' attributedFormalType )*

attributedFormalType

IMMUTABLE? VAR? formalType

formalType

( ARRAY OF )? namedType

returnedType

namedType

Variable Declarations

variableDeclaration

ident ( '[' machineAddress ']' | ',' identList )? ':'
( namedType | anonymousType )

machineAddress

constExpression

Procedure Declarations

procedureDeclaration

procedureHeader ';' block ident

procedureHeader

PROCEDURE ( '(' ident ':' receiverType ')' )?
ident ( '(' formalParamList ')' )? ( ':' returnedType )?

receiverType

ident

formalParamList

formalParams ( ';' ( formalParams | variadicParams ) )*

formalParams

IMMUTABLE? VAR? identList ':' formalType

variadicParams

VARIADIC handle ( '[' indexParam ']' )? OF IMMUTABLE? VAR?
ident ( ( '.' ident )* | ( ',' ident )* ':' formalParams )

handle

ident

indexParam

ident

Method Declarations

methodDeclaration

methodHeader ';' block ident

methodHeader

CLASS? METHOD '(' ident ':' ( receiverClass | '*' ) ')'
( ident | methodArg ) methodArg* ( ':' returnedType )?

receiverClass

qualident

methodArg

colonIdent '(' IMMUTABLE? VAR? ident ':' formalType ')'

Statements

statement

( assignmentOrProcedureCall | methodInvocation | ifStatement | caseStatement | whileStatement | repeatStatement | loopStatement | forStatement | tryStatement | criticalStatement | RETURN expression? | EXIT )?

statementSequence

statement ( ';' statement )*

methodInvocation

'[' receiver message ']'

receiver

ident | methodInvocation

message

ident ( colonIdent expression )* | ( colonIdent expression )+

assignmentOrProcedureCall

designator
( ':=' ( expression | structuredValue ) | '++' | '--' | actualParameters )?

ifStatement

IF expression THEN statementSequence
( ELSIF expression THEN statementSequence )*
( ELSE statementSequence )?
END

caseStatement

CASE expression OF case ( '|' case )*
( ELSE statementSequence )?
END

case

caseLabelList ':' statementSequence

caseLabelList

caseLabels ( ',' caseLabels )*

caseLabels

constExpression ( '..' constExpression )?

whileStatement

WHILE expression DO statementSequence END

repeatStatement

REPEAT statementSequence UNTIL expression

loopStatement

LOOP statementSequence END

forStatement

FOR ident ':=' expression TO expression ( BY constExpression )?
DO statementSequence END

tryStatement

TRY statementSequence
ON ident DO statementSequence
CONTINUE statementSequence
END

criticalStatement

CRITICAL '(' classInstance ')'
statementSequence
END

classInstance

qualident

Expressions

constExpression

simpleConstExpr ( relation simpleConstExpr | '::' namedType )?

relation

'=' | '#' | '<' | '<=' | '>' | '>=' | IN | IS

simpleConstExpr

( '+' | '-' )? constTerm ( addOperator constTerm )*

addOperator

'+' | '-' | OR

constTerm

constFactor ( mulOperator constFactor )*

mulOperator

'*' | '/' | DIV | MOD | AND | '&'

constFactor

number | string | qualident |
'(' constExpression ')' |
( NOT | '~' ) constFactor

designator

qualident ( designatorTail )?

designatorTail

( ( '[' ( expressionList ']' | '^' ) ( '.' ident )* )+

expressionList

expression ( ',' expression )*

expression

simpleExpression ( relation simpleExpression | '::' namedType )?

simpleExpression

( '+' | '-' )? term ( addOperator term )*

term

factor ( mulOperator factor )*

factor

number | string | designatorOrProcedureCall | '(' expression ')' |
( NOT | '~' ) factor | methodInvocation

designatorOrProcedureCall

qualident designatorTail? actualParameters?

actualParameters

'(' expressionList? ')'

Value Constructors

structuredValue

'{' ( valueComponent ( ',' valueComponent )* )? '}'

valueComponent

constExpression ( ( BY | '..' ) constExpression )? | structuredValue

Identifiers

qualident

ident ( '.' ident )*

identList

ident ( ',' ident )*

ident

IDENT

colonIdent

COLON_IDENT

Literals

number

NUMBER

string

STRING

Pragmas

pragma

'<*' (
( IF | ELSIF ) constExpression | ELSE | ENDIF |
( INFO | WARN | ERROR | FATAL ) compileTimeMessage |
ALIGN '=' constExpression | FOREIGN ( '=' string )? | MAKE '=' string |
INLINE | NOINLINE | VOLATILE | FRAMEWORK | IBAction | IBOutlet | QUALIFIED |
implementationDefinedPragma ( '+' | '-' | '=' ( ident | number ) )?
) '*>'

compileTimeMessage

string

implementationDefinedPragma

ident

Terminal Symbols

IDENT

( '_' | '$' | LETTER ) ( '_' | '$' | LETTER | DIGIT )*

COLON_IDENT

IDENT ':'

NUMBER

DIGIT+ |
BINARY_DIGIT+ 'B' |
DIGIT SEDECIMAL_DIGIT* ( 'C' | 'H' ) |
DIGIT+ '.' DIGIT+ ( 'E' ( '+' | '-' )? DIGIT+ )?

STRING

"'" ( CHARACTER | '"' )* "'" |
'"' ( CHARACTER | "'" )* '"'

LETTER

'A' .. 'Z' | 'a' .. 'z'

DIGIT

BINARY_DIGIT | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'

BINARY_DIGIT

'0' | '1'

SEDECIMAL_DIGIT

DIGIT | 'A' | 'B' | 'C' | 'D' | 'E' | 'F'

CHARACTER

DIGIT | LETTER | ' ' | '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | '+' | ',' | '-' | '.' | ':' | ';' | '<' | '=' | '>' | '?' | '@' | '[' | ']' | '^' | '_' | '`' | '{' | '|' | '}' | '~' | ESCAPE_SEQUENCE

ESCAPE_SEQUENCE

'\' ( '0' | 'n' | 'r' | 't' | '\' | "'" | '"' )

Whitespace and Comments

WHITESPACE

' ' | ASCII(8)

NESTABLE_COMMENT

'(*' ( ANY_CHAR | END_OF_LINE )* NESTABLE_COMMENT* '*)'

NON_NESTABLE_COMMENT

'/*' ( ANY_CHAR | END_OF_LINE )* '*/'

SINGLE_LINE_COMMENT

'//' ANY_CHAR* END_OF_LINE

ANY_CHAR

\u0000 .. \uffff

END_OF_LINE

ASCII(10) ASCII(13)? | ASCII(13) ASCII(10)?

Tokens

Reserved Words

AND ARRAY BEGIN BY BYCOPY BYREF CASE CLASS CONST CONTINUE CRITICAL DEFINITION DIV DO ELSE ELSIF END ENUM EXIT FOR FROM IF IMMUTABLE IMPLEMENTATION IMPORT IN INOUT IS LOOP METHOD MOD MODULE NOT OF ON OPAQUE OPTIONAL OR OUT POINTER PRIVATE PROCEDURE PROTECTED PROTOCOL PUBLIC RECORD REPEAT RETURN SET SUPER THEN TO TRY TYPE UNTIL VAR VARIADIC WHILE

Reserved Symbols

:= + - * / ++ -- & ~ = # < <= > >= ' " ( ) [ ] { } ^ | . , : ; .. :: <* *>

Built-in Identifiers

Pervasive Identifiers

NIL TRUE FALSE YES NO BOOLEAN BITSET CHAR UNICHAR OBJECT PROC CARDINAL INTEGER REAL LONGCARD LONGINT LONGREAL ABS NEG ODD PRED SUCC INRANGE TMIN TMAX TSIZE CHR ORD HIGH LENGTH NEXTV MIN MAX HALT VAL NEW DISPOSE READ WRITE WRITEF

Pragma Identifiers

IF ELSIF ELSE ENDIF INFO WARN ERROR FATAL ALIGN FOREIGN MAKE INLINE NOINLINE VOLATILE FRAMEWORK IBAction IBOutlet QUALIFIED

The Modula-2 Webring


Web sites and web pages related to the Modula-2 programming language.

List all sites | Previous site | Next site | Random site | Join this webring