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 | protocolModuleprogramModule
MODULE moduleId ('['priority']' )?
';'importList* block moduleId
definitionOfModule
DEFINITION MODULE moduleId';'importList* definition*
END moduleId
'.'
implementationOfModule
IMPLEMENTATION programModuleprotocolModule
PROTOCOL protocolId ('(' adoptedProtocols ')' )?
';' importList* ( OPTIONAL? methodHeader )*
END protocolId
'.'
moduleId
identpriority
constExpressionprotocolId
identadoptedProtocols
identListImport 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 | classTypenamedType
qualidentanonymousType
arrayType | recordType | pointerType | procedureTypeenumerationType
'(' identList ')' | ENUM (
'(' baseType ')' )?
identList? END
baseType
qualidentarrayType
ARRAY arrayIndex ( ',' arrayIndex )*OF ( namedType | recordType | procedureType )
arrayIndex
ordinalConstExpressionordinalConstExpression
constExpressionrecordType
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
qualidentsetType
SET OF ( namedType |'(' identList ')' )
pointerType
POINTER TO IMMUTABLE? namedTypeprocedureType
PROCEDURE ('(' formalTypeList ')' )?
( ':' returnedType )?
formalTypeList
attributedFormalType (',' attributedFormalType )*
attributedFormalType
IMMUTABLE? VAR? formalTypeformalType
( ARRAY OF )? namedTypereturnedType
namedTypeVariable Declarations
variableDeclaration
ident ('[' machineAddress ']' |
',' identList )? ':' ( namedType | anonymousType )
machineAddress
constExpressionProcedure Declarations
procedureDeclaration
procedureHeader';'
block ident
procedureHeader
PROCEDURE ('(' ident ':'
receiverType ')' )? ident (
'(' formalParamList ')' )?
( ':' returnedType )?
receiverType
identformalParamList
formalParams (';' ( formalParams |
variadicParams ) )* formalParams
IMMUTABLE? VAR? identList':' formalType
variadicParams
VARIADIC handle ('[' indexParam ']' )? OF
IMMUTABLE? VAR?ident ( (
'.' ident )* |
( ',' ident )* ':'
formalParams )
handle
identindexParam
identMethod Declarations
methodDeclaration
methodHeader';'
block ident
methodHeader
CLASS? METHOD'(' ident ':'
( receiverClass | '*' ) ')' ( ident | methodArg ) methodArg* (
':' returnedType )?
receiverClass
qualidentmethodArg
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 | methodInvocationmessage
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 ENDrepeatStatement
REPEAT statementSequence UNTIL expressionloopStatement
LOOP statementSequence ENDforStatement
FOR ident ':=' expression TO expression ( BY constExpression )?DO statementSequence END
tryStatement
TRY statementSequenceON ident DO statementSequence
CONTINUE statementSequence
END
criticalStatement
CRITICAL'(' classInstance ')' statementSequence
END
classInstance
qualidentExpressions
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
IDENTcolonIdent
COLON_IDENTLiterals
number
NUMBERstring
STRINGPragmas
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
stringimplementationDefinedPragma
identTerminal 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
