Browsable Modula-3 Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: modula/modula-3/vinju-storm/extracted
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 ::=
	"INTERFACE" Id "=" Id GenActls "END" Id "."
Module ::=
	"MODULE" Id ("EXPORTS" IdList)? ";" Import* Block Id "."
Module ::=
	"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
Import ::=
	FromImport
AsImport ::=
	"IMPORT" (ImportItem ("," ImportItem)*) ";"
FromImport ::=
	"FROM" Id "IMPORT" IdList ";"
Block ::=
	Decl* "BEGIN" Stmts "END"
Decl ::=
	"CONST" (ConstDecl ";")*
Decl ::=
	"TYPE" (TypeDecl ";")*
Decl ::=
	"EXCEPTION" (ExceptionDecl ";")*
Decl ::=
	"VAR" (VariableDecl ";")*
Decl ::=
	ProcedureHead ("=" (Block Id))? ";"
Decl ::=
	"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
VariableDecl ::=
	IdList ":" Type
VariableDecl ::=
	IdList ":=" Expr
ProcedureHead ::=
	"PROCEDURE" Id Signature
Signature ::=
	"(" Formals ")" (":" Type)? ("RAISES" Raises)?
Formals ::=
	((Formal (";" Formal)*) ";"?)?
Formal ::=
	Mode? IdList ":" Type ":=" Expr
Formal ::=
	Mode? IdList ":" Type
Formal ::=
	Mode? IdList ":=" Expr
Mode ::=
	"VALUE"
	"VAR" | "READONLY"
Raises ::=
	"{" ((QualId ("," QualId)*)? "}")
	"ANY"
Expr ::=
	Expr "OR" Expr
Expr ::=
	Expr "AND" Expr
Expr ::=
	"NOT" Expr
Id ::=
	"NOT"
Expr ::=
	Expr Relop Expr
Expr ::=
	Expr Addop Expr
Expr ::=
	Expr Mulop Expr
Expr ::=
	"+" Expr
Expr ::=
	"-" Expr
Expr ::=
	Expr Selector
Expr ::=
	Id
	Literal | Constructor
Expr ::=
	"(" Expr ")"
Relop ::=
	"="
	"#" | "<" | "<=" | ">" | ">=" | "IN"
Addop ::=
	"+"
	"-" | "&"
Mulop ::=
	"*"
	"/" | "DIV" | "MOD"
Selector ::=
	"^"
Selector ::=
	"." Id
Selector ::=
	"[" (Expr ("," Expr)*) "]"
Selector ::=
	"(" (Actual ("," Actual)*)? ")"
Elt ::=
	Expr ".." Expr
Elt ::=
	Expr
Elt ::=
	Id ":=" Expr
AnyCons ::=
	(Elt ("," Elt)*) ("," "..")?
Constructor ::=
	Type "{" AnyCons? "}"
Expr ::=
	"+" Expr
Expr ::=
	"-" Expr
Ident ::=
	"ABS"
Ident ::=
	"ADDRESS"
Ident ::=
	"ADR"
Ident ::=
	"ADRSIZE"
Ident ::=
	"BITSIZE"
Ident ::=
	"BOOLEAN"
Ident ::=
	"BYTESIZE"
Ident ::=
	"CARDINAL"
Ident ::=
	"CEILING"
Ident ::=
	"CHAR"
Ident ::=
	"DEC"
Ident ::=
	"DISPOSE"
Ident ::=
	"FALSE"
Ident ::=
	"FIRST"
Ident ::=
	"FLOAT"
Ident ::=
	"FLOOR"
Ident ::=
	"INC"
Ident ::=
	"INTEGER"
Ident ::=
	"ISTYPE"
Ident ::=
	"LAST"
Ident ::=
	"LONGFLOAT"
Ident ::=
	"LONGREAL"
Ident ::=
	"LOOPHOLE"
Ident ::=
	"MAX"
Ident ::=
	"MIN"
Ident ::=
	"MUTEX"
Ident ::=
	"NARROW"
Ident ::=
	"NEW"
Ident ::=
	"NIL"
Ident ::=
	"NULL"
Ident ::=
	"NUMBER"
Ident ::=
	"ORD"
Ident ::=
	"REAL"
Ident ::=
	"REFANY"
Ident ::=
	"ROUND"
Ident ::=
	"SUBARRAY"
Ident ::=
	"TEXT"
Ident ::=
	"TRUE"
Ident ::=
	"TRUNC"
Ident ::=
	"TYPECODE"
Ident ::=
	"VAL"
Stmt ::=
	AssignStmt
Stmt ::=
	Block
Stmt ::=
	CallStmt
Stmt ::=
	CaseStmt
Stmt ::=
	ExitStmt
Stmt ::=
	EvalStmt
Stmt ::=
	ForStmt
Stmt ::=
	IfStmt
Stmt ::=
	LockStmt
Stmt ::=
	LoopStmt
Stmt ::=
	RaiseStmt
Stmt ::=
	RepeatStmt
Stmt ::=
	ReturnStmt
Stmt ::=
	TryFinStmt
Stmt ::=
	TryXptStmt
Stmt ::=
	TCaseStmt
Stmt ::=
	WhileStmt
Stmt ::=
	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"
Id ::=
	"ROOT"
Type ::=
	TypeLiteral
Type ::=
	QualId
TypeLiteral ::=
	ArrayType
TypeLiteral ::=
	PackedType
TypeLiteral ::=
	EnumType
TypeLiteral ::=
	ObjectType
TypeLiteral ::=
	ProcedureType
TypeLiteral ::=
	RecordType
TypeLiteral ::=
	RefType
TypeLiteral ::=
	SetType
TypeLiteral ::=
	SubrangeType
TypeLiteral ::=
	"(" Type ")"
TypeLiteral ::=
	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
Field ::=
	IdList ":" Type
Field ::=
	IdList ":=" Expr
Methods ::=
	((Method (";" Method)*) ";"?)?
Method ::=
	Id Signature (":=" Expr)?
Overrides ::=
	((Override (";" Override)*) ";"?)?
Override ::=
	Id ":=" Expr

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