Browsable Modula-3 Grammar

CC-BY

Grammar connected by Vadim Zaytsev, see the Grammar Zoo entry for details: modula/modula-3/vinju-storm/connected
Source used for this grammar: Jurgen Vinju, Tijs van der Storm, Modula-3.sdf, 13 February 2006 – 19 September 2008 [MetaEnv]

Summary

Syntax

Compilation ::=
	"UNSAFE"? (Interface | Module | GenInf | GenMod)
Interface ::=
	"INTERFACE" Id ";" Import* Decl* "END" Id "."
	"INTERFACE" Id "=" Id GenActls "END" Id "."
Module ::=
	"MODULE" Id ("EXPORTS" IdList)? ";" Import* Block Id "."
	"MODULE" Id ("EXPORTS" IdList)? "=" Id GenActls "END" Id "."
GenInf ::=
	"GENERIC" "INTERFACE" Id GenFmls ";" Import* Decl* "END" Id "."
GenMod ::=
	"GENERIC" "MODULE" Id GenFmls ";" Import* Block Id "."
Import ::=
	AsImport
	FromImport
AsImport ::=
	"IMPORT" ImportItem ("," ImportItem)* ";"
FromImport ::=
	"FROM" Id "IMPORT" IdList ";"
Block ::=
	Decl* "BEGIN" Stmts "END"
Decl ::=
	"CONST" (ConstDecl ";")*
	"TYPE" (TypeDecl ";")*
	"EXCEPTION" (ExceptionDecl ";")*
	"VAR" (VariableDecl ";")*
	ProcedureHead ("=" Block Id)? ";"
	"REVEAL" (QualId ("=" | "<:") Type ";")*
GenFmls ::=
	"(" IdList? ")"
GenActls ::=
	"(" IdList? ")"
ImportItem ::=
	Id
	Id "AS" Id
ConstDecl ::=
	Id (":" Type)? "=" Expr
TypeDecl ::=
	Id ("=" | "<:") Type
ExceptionDecl ::=
	Id ("(" Type ")")?
VariableDecl ::=
	IdList ":" Type ":=" Expr
	IdList ":" Type
	IdList ":=" Expr
ProcedureHead ::=
	"PROCEDURE" Id Signature
Signature ::=
	"(" Formals ")" (":" Type)? ("RAISES" Raises)?
Formals ::=
	(Formal (";" Formal)* ";"?)?
Formal ::=
	Mode? IdList ":" Type ":=" Expr
	Mode? IdList ":" Type
	Mode? IdList ":=" Expr
Mode ::=
	"VALUE"
	"VAR"
	"READONLY"
Raises ::=
	"{" (QualId ("," QualId)*)? "}"
	"ANY"
Expr ::=
	Expr "OR" Expr
	Expr "AND" Expr
	"NOT" Expr
	Expr Relop Expr
	Expr Addop Expr
	Expr Mulop Expr
	"+" Expr
	"-" Expr
	Expr Selector
	Id
	Literal
	Constructor
	"(" Expr ")"
Relop ::=
	"="
	"#"
	"<"
	"<="
	">"
	">="
	"IN"
Addop ::=
	"+"
	"-"
	"&"
Mulop ::=
	"*"
	"/"
	"DIV"
	"MOD"
Selector ::=
	"^"
	"." Id
	"[" Expr ("," Expr)* "]"
	"(" (Actual ("," Actual)*)? ")"
Elt ::=
	Expr ".." Expr
	Expr
	Id ":=" Expr
AnyCons ::=
	Elt ("," Elt)* ("," "..")?
Constructor ::=
	Type "{" AnyCons? "}"
Stmt ::=
	AssignStmt
	Block
	CallStmt
	CaseStmt
	ExitStmt
	EvalStmt
	ForStmt
	IfStmt
	LockStmt
	LoopStmt
	RaiseStmt
	RepeatStmt
	ReturnStmt
	TryFinStmt
	TryXptStmt
	TCaseStmt
	WhileStmt
	WithStmt
Stmts ::=
	(Stmt (";" Stmt)* ";"?)?
AssignStmt ::=
	Expr ":=" Expr
CallStmt ::=
	Expr "(" (Actual ("," Actual)*)? ")"
CaseStmt ::=
	"CASE" Expr "OF" "|"? Case ("|" Case)* ("ELSE" Stmts)? "END"
ExitStmt ::=
	"EXIT"
EvalStmt ::=
	"EVAL" Expr
ForStmt ::=
	"FOR" Id ":=" Expr "TO" Expr ("BY" Expr)? "DO" Stmts "END"
IfStmt ::=
	"IF" Expr "THEN" Stmts ("ELSIF" Expr "THEN" Stmts)* ("ELSE" Stmts)? "END"
LockStmt ::=
	"LOCK" Expr "DO" Stmts "END"
LoopStmt ::=
	"LOOP" Stmts "END"
RaiseStmt ::=
	"RAISE" QualId ("(" 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" Expr "DO" Stmts "END"
WithStmt ::=
	"WITH" Binding ("," Binding)* "DO" Stmts "END"
Case ::=
	Label ("," Label)* "=>" Stmts
Label ::=
	Expr (".." Expr)?
Handler ::=
	QualId ("," QualId)* ("(" Id ")")? "=>" Stmts
TCase ::=
	Type ("," Type)* ("(" Id ")")? "=>" Stmts
Binding ::=
	Id "=" Expr
Actual ::=
	TypeLiteral
	(Id ":=")? Expr
QualId ::=
	Id ("." Id)?
IdList ::=
	Id ("," Id)*
TypeName ::=
	"ROOT"
	"UNTRACED" "ROOT"
Type ::=
	TypeLiteral
	QualId
TypeLiteral ::=
	ArrayType
	PackedType
	EnumType
	ObjectType
	ProcedureType
	RecordType
	RefType
	SetType
	SubrangeType
	"(" Type ")"
	TypeName
ArrayType ::=
	"ARRAY" (Type ("," Type)*)? "OF" Type
PackedType ::=
	"BITS" Expr "FOR" Type
EnumType ::=
	"{" IdList? "}"
Ancestor ::=
	TypeName
	ObjectType
	QualId
ObjectType ::=
	Ancestor? Brand? "OBJECT" Fields ("METHODS" Methods)? ("OVERRIDES" Overrides)? "END"
ProcedureType ::=
	"PROCEDURE" Signature
RecordType ::=
	"RECORD" Fields "END"
RefType ::=
	"UNTRACED"? Brand? "REF" Type
SetType ::=
	"SET" "OF" Type
SubrangeType ::=
	"[" Expr ".." Expr "]"
Brand ::=
	"BRANDED" TextLiteral?
Fields ::=
	(Field (";" Field)* ";"?)?
Field ::=
	IdList ":" Type ":=" Expr
	IdList ":" Type
	IdList ":=" Expr
Methods ::=
	(Method (";" Method)* ";"?)?
Method ::=
	Id Signature (":=" Expr)?
Overrides ::=
	(Override (";" Override)* ";"?)?
Override ::=
	Id ":=" Expr
Literal ::=
	Number
	FloatNumber
	CharLiteral
	TextLiteral
Id ::=
	Letter (Letter | Digit | "_")* &amp; ¬"NOT" &amp; ¬"ROOT"
CharLiteral ::=
	"'" PrintingChar
	Escape
	""" "'"
TextLiteral ::=
	""" TextContents """
TextContents ::=
	(PrintingChar | Escape)*
Escape ::=
	"\\n"
	"\\t"
	"\\r"
	"\\f"
	"\\\\"
	"'"
	"\\"
	"\\" OctalDigit OctalDigit OctalDigit
Number ::=
	Digit Digit*
	Digit Digit* "_" HexDigit HexDigit*
FloatNumber ::=
	Digit Digit* "." Digit Digit* Exponent?
Exponent ::=
	("E" | "e" | "D" | "d" | "X" | "x") ("+" | "-")? Digit Digit*
PrintingChar ::=
	Letter
	Digit
	OtherChar
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 ::=
	"\<"
	"\>"
	"\"
	"\!"
	"\?"
	"\#"
	"\$"
	"\%"
	"\&"
	"\("
	"\)"
	"\*"
	"\+"
	"\,"
	"\-"
	"\."
	"\/"
	"\:"
	"\;"
	"\_"
	"\`"
	"\{"
	"\}"
	"\~"
	"\["
	"\]"
	"\|"
	"\^"
	"\="

GrammarLabMaintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Last updated in September 2015. []