Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: modula/modula-3/src-052/extracted
Source used for this grammar: Luca Cardelli, James Donahue, Lucille Glassman, Mick Jordan, Bill Kalsow, Greg Nelson, SRC 052: Modula-3 Report (revised), 1 November 1989, §9 Syntax, pages 56–60
Compilation
, Interface
, Module
, Import
, Block
, Declaration
, ConstDecl
, TypeDecl
, ExceptionDecl
, VariableDecl
, ProcedureHead
, Signature
, Formals
, Formal
, Raises
, Stmts
, Stmt
, AssignStmt
, CallStmt
, CaseStmt
, ExitStmt
, EvalStmt
, ForStmt
, IfStmt
, LockStmt
, LoopStmt
, RaiseStmt
, Repeatstmt
, ReturnStmt
, TCaseStmt
, TryXptStmt
, TryFinStmt
, WhileStmt
, WithStmt
, Case
, Labels
, Handler
, Tcase
, Binding
, Actual
, Type
, ArrayType
, PackedType
, EnumType
, ObjectType
, ProcedureType
, RecordType
, RefType
, SetType
, SubrangeType
, Ancestor
, Brand
, Fields
, Field
, Methods
, Method
, ConstExpr
, Expr
, E1
, E2
, E3
, E4
, E5
, E6
, E7
, E8
, Relop
, Addop
, Mulop
, Selector
, Constructor
, SetCons
, SetElt
, RecordCons
, RecordElt
, ArrayCons
, TypeName
, ExceptionID
, ProcedureID
, IDList
, Literal
, Ident
, Operator
, CharLiteral
, TextLiteral
, Escape
, Number
, Exponent
, PrintingChar
, HexDigit
, Digit
, OctalDigit
, Letter
, OtherChar
, ExtendedChar
), 0 root (—), 5 top (Compilation
, Repeatstmt
, Literal
, Operator
, OtherChar
), 4 bottom (Expt
3, TypeID
, UtherChar
, RepeatStmt
).Compilation ::= "UNSAFE" Interface Module
Interface ::= "INTERFACE" Ident ";" Import Declaration "END" Ident "."
Module ::= "MODULE" Ident "EXPORTS" IDList ";" Import Block Ident "."
Import ::= "FROM" Ident "IMPORT" IDList ";"
Block ::= Declaration"BEGIN" Stmts "END"
Declaration ::= "CONST" ConstDecl ";" "TYPE" TypeDecl ";" "EXCEPTION" ExceptionDecl ";" "VAR" VariableDecl ";" ProcedureHead "=" Block Ident ";" "REVEAL" TypeID "=""<:" Type ";"
ConstDecl ::= Ident ":" Type "=" ConstExpr
TypeDecl ::= Ident "=""<:" Type
ExceptionDecl ::= Ident "(" Type ")"
VariableDecl ::= IDList ":" Type "&" ":=" Expr
ProcedureHead ::=
"PROCEDURE" Ident Signature
Signature ::= "(" Formals ")" ":" Type "RAISES" Raises
Formals ::= ";" Formal ";"Formal
Formal ::= "VALUE""VAR""READONLY" IDList ":" Type "&" ":=" ConstExpr
Raises ::= "{" ExceptionID "," ExceptionID "}"
Stmts ::= ";" Stmt ";"Stmt
Stmt ::= AssignStmt Block CallStmt CaseStmt ExitStmt EvalStmt ForStmt IfStmt LockStmt LoopStmt RaiseStmt RepeatStmt ReturnStmt TryFinStmt TryXptStmt TCaseStmt WhileStmt WithStmt
AssignStmt ::=
Expr ":=" Expr
CallStmt ::= Expr "(" Actual "," Actual ")"
CaseStmt ::= "CASE" Expr "OF" Case "|" Case "ELSE" Stmts "END"
ExitStmt ::=
"EXIT"
EvalStmt ::=
"EVAL" Expr
ForStmt ::= "FOR" Ident ":=" Expt "TO" Expr "BY" Expr "DO" Stmts "END"
IfStmt ::= "IF" Expr "THEN" Stmts "ELSIF" Expt "THEN" Stmts "ELSE" Stmts "END"
LockStmt ::= "LOCK" Expr "DO" Stmts "END"
LoopStmt ::= "LOOP" Stmts "END"
RaiseStmt ::= "RAISE" ExceptionID "(" Expr ")"
Repeatstmt ::= "REPEAT" Stmts "UNTIL" Expr
ReturnStmt ::= "RETURN" Expr
TCaseStmt ::= "TYPECASE" Expr "OF" Tcase "|" Tcase "ELSE" Stmts "END"
TryXptStmt ::= "TRY" Stmts "EXCEPT" Handler "|" Handler "ELSE" Stmts "END"
TryFinStmt ::= "TRY" Stmts "FINALLY" Stmts "END"
WhileStmt ::= "WHILE" Expt "DO" Stmts "END"
WithStmt ::= "WITH" Binding "," Binding "DO" Stmts "END"
Case ::= Labels "," Labels "=>" Stmts
Labels ::= ConstExpr ".." ConstExpr
Handler ::= ExceptionID "," ExceptionID "(" Ident ")" "=>" Stmts
Tcase ::= Type "," Type "(" Ident ")" "=>" Stmts
Binding ::=
Ident "=" Expr
Actual ::= ":=" Expr TypeIdent
Type ::= TypeName ArrayType PackedType EnumType ObjectType ProcedureType RecordType RefType SetType SubrangeType "(" Type ")"
ArrayType ::= "ARRAY" Type "," Type "OF" Type
PackedType ::= "BITS" ConstExpr "FOR" Type
EnumType ::= "{" IDList "}"
ObjectType ::= Ancestor"OBJECT" Fields "METHODS" Methods "END"Brand
ProcedureType ::=
"PROCEDURE" Signature
RecordType ::= "RECORD" Fields "END"
RefType ::= "UNTRACED" Brand "REF" Type
SetType ::= "SET" "OF" Type
SubrangeType ::= "[" ConstExpr ".." ConstExpr "]"
Ancestor ::=
TypeName
ObjectType
"UNTRACED"
Brand ::= "BRANDED" TextLiteral
Fields ::= ";" Field ";"Field
Field ::= IDList ":" Type "&" ":=" ConstExpr
Methods ::= ";" Method ";"Method
Method ::= Ident "&" ":=" ProcedureIDSignature
ConstExpr ::= Expr
Expr ::= E1 "OR" E1
E1 ::= E2 "AND" E2
E2 ::= "NOT" E3
E3 ::= E4Relop E4
E4 ::= E5Addop E5
E5 ::= E6Mulop E6
E6 ::= "+""-" E7
E7 ::=
E8 Selector
E8 ::= Ident Number CharLiteral TextLiteral Constructor "(" Expr ")"
Relop ::= "=" "#" "<" "<=" ">" ">=" "IN"
Addop ::= "+" "-" "&"
Mulop ::= "*" "/" "DIV" "MOD"
Selector ::= "^" "." Ident "[" Expr "," Expr "]" "(" Actual "," Actual ")"
Constructor ::= Type "{" SetCons RecordCons ArrayCons "}"
SetCons ::= SetElt "." SetElt
SetElt ::= Expr ".." Expr
RecordCons ::= RecordElt "," RecordElt
RecordElt ::= ":=" ExprIdent
ArrayCons ::= Expr "," Expr "," ".."
TypeName ::= Ident "." Ident "ROOT" "UNTRACED" "ROOT"
ExceptionID ::= Ident "." Ident
ProcedureID ::= Ident "." Ident
IDList ::= Ident "," Ident
Literal ::= Number CharLiteral TextLiteral
Ident ::= Letter "_"Letter Digit
Operator ::= "+" "-" "*" "/" "." "^" ":" "=" "=" "$" "<" "<" "=" ">" "=" ">" "&" "<" ":" "=" ">" "," ";" "|" ":" "." "." "(" ")" "{" "}" "[" "]"
CharLiteral ::= "’" PrintingChar Escape "’"
TextLiteral ::= "DQUOTE" PrintingChar Escape "DQUOTE"
Escape ::= "\" "n" "\" "t" "\" "r" "\" "f" "\" "\" "\" "’" "\" "DQUOTE" "\" OctalDigit OctalDigit OctalDigit
Number ::= Digit Digit"_" HexDigit HexDigit Digit Digit "." Digit Digit ExponentDigit Digit
Exponent ::= "E""e""D""d" "+""-" Digit Digit
PrintingChar ::= Letter Digit UtherChar
HexDigit ::= Digit "A" "B" "C" "D" "E" "F" "a" "b" "c" "d" "e" "f"
Digit ::= "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"
OctalDigit ::= "0" "1" "2" "3" "4" "5" "6" "7"
Letter ::= "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
OtherChar ::= " " "!" "#" "$" "%" "&" "(" ")" "*" "+" "," "-" "." "/" ":" ";" "<" "=" ">" "?" "@" "[" "]" "^" "_" "‘" "{" "|" "}" "~" ExtendedChar
ExtendedChar ::= " " "¡" "¢" "£" "¤" "¥" "¦" "§" "¨" "©" "ª" "«" "¬" "" "®" "¯" "°" "±" "²" "³" "´" "µ" "¶" "·" "¸" "¹" "º" "»" "¼" "½" "¾" "¿" "À" "Á" "Â" "Ã" "Ä" "Å" "Æ" "Ç" "È" "É" "Ê" "Ë" "Ì" "Í" "Î" "Ï" "Ð" "Ñ" "Ò" "Ó" "Ô" "Õ" "Ö" "×" "Ø" "Ù" "Ú" "Û" "Ü" "Ý" "Þ" "ß" "à" "á" "â" "ã" "ä" "å" "æ" "ç" "è" "é" "ê" "ë" "ì" "í" "î" "ï" "ð" "ñ" "ò" "ó" "ô" "õ" "ö" "÷" "ø" "ù" "ú" "û" "ü" "ý" "þ" "ÿ"