Title: The Modular 3 Grammar
1The Modular 3 Grammar
Note that 1. ALL CAPS indicates
tokens/terminals 2. MiXeD
CaSe indicates non-terminals Compilation --gt
Interface Module Interface --gt T_INTERFACE
T_IDENT T_SEMI OptImports OptDecl
T_END T_IDENT T_PERIOD Module
--gt T_MODULE T_IDENT OptExports T_SEMI
OptImports Block T_IDENT T_PERIOD
OptImports--gt epsilon ImportList
ImportList--gt ImportList Import Import
Import --gt AsImport FromImport
AsImport --gt T_IMPORT ImpItemLst T_SEMI
FromImport--gt T_FROM T_IDENT T_IMPORT
IdList T_SEMI ImpItemLst--gt
ImpItemLst T_COMMA ImportItem ImportItem
ImportItem--gt T_IDENT OptAs
OptExports--gt epsilon T_EXPORTS IdList
OptAs --gt epsilon T_AS T_IDENT
2The Modular 3 Grammar
Block --gt OptDecl T_BEGIN StmtGroup T_END
OptDecl --gt epsilon DeclList
T_SEMI DeclList --gt DeclList Decl
Decl Decl --gt T_CONST OptConDec
ConDecLst T_TYPE OptTypDec
TypDecLst T_VAR OptVarDec
VarDecLst ProcHead OptBlock
T_REVEAL OptReveal OptConDec
--gt epsilon ConDecLst ConDecLst --gt ConDecLst
T_SEMI ConstDecl ConstDecl ConstDecl --gt
T_IDENT OptType T_EQ ConstExpr OptType --gt
epsilon T_COLON Type OptTypDec --gt epsilon
TypDecLst TypDecLst --gt TypDecLst T_SEMI
TypeDecl TypeDecl TypeDecl --gt T_IDENT
TypeSym Type TypeSym --gt T_EQ T_LTCOL
3The Modular 3 Grammar
OptVarDec --gt epsilon VarDecLst VarDecLst --gt
VarDecLst T_SEMI VarDecl VarDecl VarDecl
--gt IdList VarRest VarRest --gt T_COLON Type
T_COLON Type T_ASSIGN Expr T_ASSIGN
Expr ProcHead --gt T_PROC T_IDENT
Signature Signature --gt T_LPAR OptFormals
T_RPAR OptType OptFormals--gt epsilon
FormalList OptSemi FormalList--gt FormalList
T_SEMI Formal Formal Formal --gt OptMode
IdList FormRest OptMode --gt epsilon
Mode Mode --gt T_VALUE T_VAR
T_READONLY FormRest --gt T_COLON Type
T_COLON Type T_ASSIGN ConstExpr
T_ASSIGN ConstExpr OptBlock --gt epsilon T_EQ
Block T_IDENT OptReveal --gt epsilon
RevealList
4The Modular 3 Grammar
RevealList--gt RevealList T_SEMI RevealRest
RevealRest RevealRest--gt QualId T_EQ
Type Statement --gt AssignSt Block
CallSt CaseSt ExitSt ForSt
IfSt LoopSt RepeatSt ReturnSt
WhileSt StmtGroup --gt epsilon StmtList
OptSemi StmtList --gt StmtList T_SEMI
Statement Statement AssignSt --gt Expr
T_ASSIGN Expr CallSt --gt Expr T_LPAR
ActualSel T_RPAR CaseSt --gt T_CASE Expr
T_OF OptCase OptElse T_END OptCase
--gt epsilon CaseList CaseList --gt
CaseList T_BAR Case Case Case
--gt LabelList T_IMPLIES StmtGroup
LabelList --gt LabelList T_COMMA Labels
Labels Labels --gt ConstExpr
OptRange OptRange --gt epsilon
T_DOTDOT ConstExpr
5The Modular 3 Grammar
OptElse --gt epsilon T_ELSE StmtGroup ExitSt
--gt T_EXIT ForSt --gt T_FOR T_IDENT
T_ASSIGN Expr T_TO Expr OptBy
T_DO StmtGroup T_END OptBy --gt epsilon
T_BY Expr IfSt --gt T_IF Expr T_THEN
StmtGroup OptElseIf OptElse T_END OptElseIf
--gt epsilon ElseIfList ElseIfList--gt
ElseIfList ElseIfSt ElseIfSt ElseIfSt --gt
T_ELSEIF Expr T_THEN StmtGroup LoopSt --gt
T_LOOP StmtGroup T_END RepeatSt --gt T_REPEAT
StmtGroup T_UNTIL Expr ReturnSt --gt T_RETURN
OptReturn OptReturn --gt epsilon Expr WhileSt
--gt T_WHILE Expr T_DO StmtGroup T_END
6The Modular 3 Grammar
Type --gt TypeName ArrayType PackedType
EnumType ProcType
RecordType SetType SubRangeTy ObjType
T_LPAR Type T_RPAR ArrayType --gt
T_ARRAY OptArrTyp1 T_OF Type OptArrTyp1--gt
epsilon OptTypList OptTypList--gt OptTypList
T_COMMA Type Type PackedType--gt T_BITS
ConstExpr T_FOR Type EnumType --gt T_LCB
OptIdList T_RCB OptIdList --gt epsilon IdList
ProcType --gt T_PROC
Signature RecordType--gt T_RECORD OptFields
T_END OptFields --gt epsilon FieldList
OptSemi FieldList --gt FieldList T_SEMI Field
Field Field --gt IdList FieldRest FieldRest
--gt FieldRest1 FieldRest2 MoreField FieldRest1
--gt T_ASSIGN ConstExpr
7The Modular 3 Grammar
FieldRest2--gt T_COLON Type MoreField --gt
epsilon FieldRest1 SetType --gt T_SET T_OF
Type SubRangeTy--gt T_LSB ConstExpr T_DOTDOT
ConstExpr T_RSB ObjType --gt OptName OptBrand
T_OBJECT OptFields ObjMethods ObjOverRi
T_END OptName --gt epsilon ObjType
TypeName OptBrand --gt epsilon
T_BRANDED ObjMethods--gt epsilon T_METHODS
OptMethods ObjOverRi --gt epsilon T_OVERRIDES
OptOverRid OptMethods--gt epsilon MethodList
OptSemi MethodList--gt MethodList
T_SEMI Method Method Method --gt T_IDENT
Signature MethodRest MethodRest--gt epsilon
T_ASSIGN ConstExpr OptOverRid--gt epsilon
OverRiList OptSemi
8The Modular 3 Grammar
OverRiList--gt OverRiList T_SEMI OverRide
OverRide OverRide --gt T_IDENT T_ASSIGN
ConstExpr ConstExpr --gt Expr Expr --gt
Expr T_OR Expr1 Expr1 Expr1 --gt Expr1
T_AND Expr2 Expr2 Expr2 --gt OptNot
Expr3 OptNot --gt epsilon OptNot
T_NOT Expr3 --gt Expr3 Relop Expr4
Expr4 Expr4 --gt Expr4 Addop Expr5
Expr5 Expr5 --gt Expr5 Mulop Expr6
Expr6 Expr6 --gt OptPM Expr7 OptPM --gt
epsilon OptPM PorM PorM --gt T_PLUS
T_MINUS Expr7 --gt Expr8 OptSelect
9The Modular 3 Grammar
OptSelect --gt epsilon OptSelect
Selector Expr8 --gt T_IDENT T_NUM
T_CHARLIT T_TEXTLIT T_LPAR Expr T_RPAR
Relop --gt T_EQ T_SHRP T_LT T_LE T_GT
T_GE T_IN Addop --gt T_PLUS T_MINUS
T_AMP Mulop --gt T_TIMES T_QUOT T_DIV
T_MOD Selector --gt T_CARAT T_PERIOD T_IDENT
T_LSB ExprSel T_RSB T_LPAR
ActualSel T_RPAR ExprSel --gt ExprSel T_COMMA
Expr Expr ActualSel --gt epsilon
ActualList ActualList--gt ActualList
T_COMMA Actual Actual Actual --gt
Type OptId Expr OptId --gt
epsilon T_IDENT T_ASSIGN IdList
--gt IdList T_COMMA T_IDENT T_IDENT
QualId --gt T_IDENT OptQual OptQual --gt
epsilon T_PERIOD T_IDENT TypeName --gt QualId
T_ROOT T_UNTRACED T_ROOT OptSemi --gt
epsilon T_SEMI