mod2.atg — described in the file as an “Alternative grammar for PIM style Modula-2”.pimmod2.atg — described as a Coco/R grammar for Modula-2 based on Programming in Modula-2.The two grammars describe the same broad Modula-2 language, but they are not identical. mod2.atg is a more permissive/extended alternative grammar, while pimmod2.atg follows a more explicitly structured grammar based on Programming in Modula-2.
mod2.atg uses:
ModDecl = "MODULE" id [ Priority ] ";" { Import } [ Export ] Block id .
The { Import } means zero or more imports.
pimmod2.atg uses:
ModuleDeclaration = "MODULE" ident [ Priority ] ";"
[ Import ] [ Export ] Block ident .
The [ Import ] means zero or one import at that point.
Therefore mod2.atg accepts multiple IMPORT declarations in a module, while pimmod2.atg does not.
mod2.atg supports:
ProcDecl = ProcHead ";" ( Block id | "FORWARD" ) .
So a procedure may be declared with FORWARD.
pimmod2.atg uses:
ProcedureDeclaration = ProcedureHeading ";" Block ident .
There is no FORWARD alternative.
mod2.atg allows:
MulOp = "*" | "/" | "DIV" | "REM" | "MOD" | "AND" | "&" .
pimmod2.atg allows:
MulOperator = "*" | "/" | "DIV" | "MOD" | "AND" .
Therefore mod2.atg additionally accepts REM and &.
mod2.atg allows:
Rel = "=" | "#" | "<>" | "<" | "<=" | ">" | ">=" | "IN" .
pimmod2.atg allows:
Relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" .
Thus mod2.atg additionally accepts <>.
mod2.atg uses:
Elem = ConstExpr [ ".." ConstExpr ] .
pimmod2.atg uses:
Element = Expression [ ".." Expression ] .
So the first grammar restricts set elements/ranges to constant expressions, while the second permits general expressions.
mod2.atg combines assignment and procedure-call syntax:
Stat = [ Design ( ":=" Expr | [ ActPar ] )
| IfStat | CaseStat | LoopStat | ForStat
| RepeatStat | WhileStat | WithStat
| "EXIT" | "RETURN" [ Expr ]
] .
pimmod2.atg factors these explicitly:
Statement = [ Assignment | ProcedureCall | IfStatement
| CaseStatement | WhileStatement | RepeatStatement
| LoopStatement | ForStatement | WithStatement
| "EXIT" | "RETURN" [ Expression ] ] .
Assignment = Designator ":=" Expression .
ProcedureCall = Designator [ ActualParameters ] .
The second form is more explicitly structured and easier to distinguish conceptually.
Many non-semantic differences are simply naming/style choices:
mod2.atg |
pimmod2.atg |
|---|---|
id |
ident |
QualId |
QualIdent |
Design |
Designator |
Fact |
Factor |
Stat |
Statement |
ProcDecl |
ProcedureDeclaration |
ProcHead |
ProcedureHeading |
DefMod |
DefinitionModule |
ProgMod |
ProgramModule |
These changes mostly affect readability and grammar organization rather than the accepted language.
| Aspect | mod2.atg |
pimmod2.atg |
|---|---|---|
| Overall language | Modula-2 / PIM-style | Modula-2 based on Programming in Modula-2 |
| Grammar style | Compact, condensed | More explicit/factored |
| Multiple imports | Yes | No |
FORWARD procedures |
Yes | No |
REM operator |
Yes | No |
& operator |
Yes | No |
<> relation |
Yes | No |
| Set elements | ConstExpr |
Expression |
| Assignment/call structure | Combined | Explicitly separated |
mod2.atg can be viewed as the more permissive/extended practical grammar, while pimmod2.atg is the more explicitly structured PIM-oriented grammar.
For a practical Modula-2 editor/parser, mod2.atg is the more interesting starting point if the objective is to accept a broader range of existing source code. For compatibility with the grammar of Programming in Modula-2, pimmod2.atg is the closer reference.