Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: modula/modula-3/dagenais-cordy/extracted
Source used for this grammar: Michel Dagenais, James R. Cordy, Modula-3 Grammar for TXL-3, Adapted to TXL 10. Rev 21.3.01, March 2001 [TGZ]
program
, Interface
, IInterface
, Module
, IModule
, GInterface
, GModule
, Exports
, Import
, AsImport
, ComaImportItem
, FromImport
, Block
, Decl
, EqualBlock
, GenFmls
, GenActls
, ImportItem
, AsId
, ConstDecl
, ColonType
, TypeDecl
, RevealDecl
, ExceptionDecl
, ParenthesizedType
, VariableDecl
, EqualExpr
, ProcedureHead
, Signature
, Raises
, Formals
, SemicolonFormal
, Formal
, EqualConstExpr
, Mode
, RaisesList
, Stmts
, OptStmts
, SemiColonStmt
, Stmt
, AssignStmt
, CallStmt
, CaseStmt
, VerticalCase
, ElseStmts
, ExitStmt
, EvalStmt
, ForStmt
, ByExpr
, IfStmt
, Elsif
, LockStmt
, LoopStmt
, RaiseStmt
, ParenthesizedExpr
, RepeatStmt
, ReturnStmt
, TypecaseStmt
, VerticalTCase
, TryStmt
, ExceptOrFinally
, VerticalHandler
, WhileStmt
, WithStmt
, Case
, Labels
, DotDotConstExpr
, Handler
, ParenthesizedId
, TCase
, Binding
, Actual
, Type
, ArrayType
, PackedType
, EnumerationType
, ObjectType
, ObjectOrTypeName
, TheMethods
, TheOverrides
, ProcedureType
, RecordType
, RefType
, SetType
, SubrangeType
, Brand
, Fields
, FieldList
, SemiColonField
, Field
, Methods
, MethodList
, SemiColonMethod
, Method
, Overrides
, OverrideList
, SemiColonOverride
, Override
, ConstExpr
, Expr
, OrE1
, E1
, AndE2
, E2
, E3
, RelOpE4
, E4
, AddOpE5
, E5
, MulOpE6
, E6
, E7
, E8
, SignOp
, RelOp
, AddOp
, MulOp
, Selector
, ComaExpr
, Constructor
, AnyCons
, SetCons
, SetElt
, DotDotExpr
, RecordCons
, RecordElt
, ArrayCons
, ComaDotDot
, IdList
, QualId
, DotId
, TypeName
), 1 root (program
), 0 top (—), 7 bottom (NL
55, EX
12, Number
, stringlit
, IN
12, charlit
, id
34).program ::= Interface Module GInterface GModule IInterface IModule
Interface ::= "UNSAFE" "INTERFACE" id ";" NL NL Import Decl NL "END" id "." NL
IInterface ::= "UNSAFE" "INTERFACE" id "=" id GenActls "END" id "." NL
Module ::= "UNSAFE" "MODULE" id Exports ";" NL NL Import Block id "." NL
IModule ::= "UNSAFE" "MODULE" id Exports "=" id GenActls "END" id "." NL
GInterface ::= "GENERIC" "INTERFACE" id GenFmls ";" Import Decl NL "END" id "." NL
GModule ::= "GENERIC" "MODULE" id GenFmls ";" NL NL Import Block id "." NL
Exports ::=
"EXPORTS" IdList
Import ::= AsImport FromImportNL NL
AsImport ::= "IMPORT" ImportItem ComaImportItem ";" NL NL
ComaImportItem ::=
"," ImportItem
FromImport ::= "FROM" id "IMPORT" IdList ";" NL NL
Block ::= Decl"BEGIN" Stmts "END"
Decl ::= ProcedureHead EqualBlock";" NL NL "VAR" IN NL VariableDecl EX "TYPE" IN NL TypeDecl EX NL "CONST" IN NL ConstDecl EX NL "EXCEPTION" IN NL ExceptionDecl EX NL "REVEAL" IN NL RevealDecl EX NL
EqualBlock ::= "=" IN NL Block id EX
GenFmls ::= "(" IdList ")"
GenActls ::= "(" IdList ")"
ImportItem ::=
id AsId
AsId ::=
"AS" id
ConstDecl ::= id ColonType"=" ConstExpr ";" NL
ColonType ::=
":" Type
TypeDecl ::= id "=" Type ";" NL id "<:" Type ";" NL
RevealDecl ::= QualId "=" Type ";" NL QualId "<:" Type ";" NL
ExceptionDecl ::= id ParenthesizedType";" NL
ParenthesizedType ::= "(" Type ")"
VariableDecl ::= IdList ColonType";" NLEqualExpr
EqualExpr ::=
":=" Expr
ProcedureHead ::=
"PROCEDURE" id Signature
Signature ::= "(" Formals ")" ColonType Raises
Raises ::=
"RAISES" RaisesList
Formals ::= Formal SemicolonFormal";"
SemicolonFormal ::=
";" Formal
Formal ::= ModeIdList ColonType EqualConstExpr
EqualConstExpr ::=
":=" ConstExpr
Mode ::= "VALUE" "VAR" "READONLY"
RaisesList ::= "{" QualId "," "}" "ANY"
Stmts ::=IN NL OptStmts EX
OptStmts ::= Stmt SemiColonStmt";" NL
SemiColonStmt ::=
";" NL Stmt
Stmt ::= IfStmt ForStmt ReturnStmt WhileStmt AssignStmt CallStmt Block CaseStmt ExitStmt EvalStmt LockStmt LoopStmt RaiseStmt RepeatStmt TypecaseStmt TryStmt WithStmt
AssignStmt ::=
Expr ":=" Expr
CallStmt ::= Expr "(" Actual "," ")"
CaseStmt ::= "CASE" Expr "OF" NL Case VerticalCase ElseStmts "END"
VerticalCase ::=
"|" Case
ElseStmts ::=
"ELSE" Stmts
ExitStmt ::=
"EXIT"
EvalStmt ::=
"EVAL" Expr
ForStmt ::= "FOR" id ":=" Expr "TO" Expr ByExpr "DO" Stmts "END"
ByExpr ::=
"BY" Expr
IfStmt ::= "IF" Expr "THEN" Stmts Elsif ElseStmts "END"
Elsif ::= "ELSIF" Expr "THEN" Stmts
LockStmt ::= "LOCK" Expr "DO" Stmts "END"
LoopStmt ::= "LOOP" Stmts "END"
RaiseStmt ::= "RAISE" QualId ParenthesizedExpr
ParenthesizedExpr ::= "(" Expr ")"
RepeatStmt ::= "REPEAT" Stmts "UNTIL" Expr
ReturnStmt ::= "RETURN" Expr
TypecaseStmt ::= "TYPECASE" Expr "OF" NL TCase VerticalTCase ElseStmts "END"
VerticalTCase ::=
"|" TCase
TryStmt ::= "TRY" Stmts ExceptOrFinally "END"
ExceptOrFinally ::= "EXCEPT" NL Handler VerticalHandler ElseStmts "FINALLY" Stmts
VerticalHandler ::=
"|" Handler
WhileStmt ::= "WHILE" Expr "DO" Stmts "END"
WithStmt ::= "WITH" Binding "DO" Stmts "END"
Case ::= "," "=>" StmtsLabels
Labels ::=
ConstExpr DotDotConstExpr
DotDotConstExpr ::=
".." ConstExpr
Handler ::= "," ParenthesizedId "=>" StmtsQualId
ParenthesizedId ::= "(" id ")"
TCase ::= "," ParenthesizedId "=>" StmtsType
Binding ::=
id "=" Expr
Actual ::=
Type
Expr
id ":=" Expr
Type ::= TypeName ArrayType EnumerationType RecordType ObjectType ProcedureType RefType SetType SubrangeType PackedType "(" Type ")"
ArrayType ::= "ARRAY" Type "," "OF" Type
PackedType ::= "BITS" ConstExpr "FOR" Type
EnumerationType ::= "{" IdList "}"
ObjectType ::= ObjectOrTypeName"OBJECT" IN NL Fields TheMethods TheOverrides "END" EXBrand
ObjectOrTypeName ::= TypeName ObjectType
TheMethods ::=
"METHODS" NL Methods
TheOverrides ::=
"OVERRIDES" NL Overrides
ProcedureType ::=
"PROCEDURE" Signature
RecordType ::= "RECORD" IN NL Fields "END" EX
RefType ::= "UNTRACED" Brand "REF" Type
SetType ::= "SET" "OF" Type
SubrangeType ::= "[" ConstExpr ".." ConstExpr "]"
Brand ::= "BRANDED" ConstExpr
Fields ::=
FieldList
FieldList ::= IN Field SemiColonField";" EX NL
SemiColonField ::=
";" NL Field
Field ::= IdList ColonTypeEqualConstExpr
Methods ::=
MethodList
MethodList ::= IN Method SemiColonMethod";" EX NL
SemiColonMethod ::=
";" NL Method
Method ::=
id Signature EqualConstExpr
Overrides ::=
OverrideList
OverrideList ::= IN Override SemiColonOverride";" EX NL
SemiColonOverride ::=
";" NL Override
Override ::=
id ":=" ConstExpr
ConstExpr ::= Expr
Expr ::=
E1 OrE1
OrE1 ::=
"OR" E1
E1 ::=
E2 AndE2
AndE2 ::=
"AND" E2
E2 ::= "NOT" E3
E3 ::=
E4 RelOpE4
RelOpE4 ::= RelOp E4
E4 ::=
E5 AddOpE5
AddOpE5 ::= AddOp E5
E5 ::=
E6 MulOpE6
MulOpE6 ::= MulOp E6
E6 ::=
SignOp
E7E7 ::=
E8 Selector
E8 ::= id Number charlit stringlit "(" Expr ")" Constructor
SignOp ::= "+" "-"
RelOp ::= "=" "#" "<" "<=" ">" ">=" "IN"
AddOp ::= "+" "-" "&"
MulOp ::= "*" "/" "DIV" "MOD"
Selector ::= "." id "[" Expr ComaExpr "]" "(" Actual "," ")" "^"
ComaExpr ::=
"," Expr
Constructor ::= Type "{" AnyCons "}"
AnyCons ::= SetCons RecordCons ArrayCons
SetCons ::= ","SetElt
SetElt ::=
Expr DotDotExpr
DotDotExpr ::=
".." Expr
RecordCons ::= ","RecordElt
RecordElt ::=
Expr EqualExpr
ArrayCons ::= "," ComaDotDotExpr
ComaDotDot ::= "," ".."
IdList ::= ","id
QualId ::=
id DotId
DotId ::=
"." id
TypeName ::= QualId "ROOT" "UNTRACED" "ROOT"