Eric Streit 3 недель назад
Родитель
Сommit
0e87a2c27d

+ 0 - 163
coco-chatgpt-doesntwork/coco_r_grammar_comparison.md

@@ -1,163 +0,0 @@
-# Fundamental Difference Between the Two Coco/R Modula-2 Grammars
-
-## Files compared
-
-- `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*.
-
-## Overall conclusion
-
-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*.
-
-## Important semantic differences
-
-### 1. Multiple IMPORT declarations
-
-`mod2.atg` uses:
-
-```text
-ModDecl = "MODULE" id [ Priority ] ";" { Import } [ Export ] Block id .
-```
-
-The `{ Import }` means zero or more imports.
-
-`pimmod2.atg` uses:
-
-```text
-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.
-
-### 2. FORWARD procedure declarations
-
-`mod2.atg` supports:
-
-```text
-ProcDecl = ProcHead ";" ( Block id | "FORWARD" ) .
-```
-
-So a procedure may be declared with `FORWARD`.
-
-`pimmod2.atg` uses:
-
-```text
-ProcedureDeclaration = ProcedureHeading ";" Block ident .
-```
-
-There is no `FORWARD` alternative.
-
-### 3. Arithmetic/logical operators
-
-`mod2.atg` allows:
-
-```text
-MulOp = "*" | "/" | "DIV" | "REM" | "MOD" | "AND" | "&" .
-```
-
-`pimmod2.atg` allows:
-
-```text
-MulOperator = "*" | "/" | "DIV" | "MOD" | "AND" .
-```
-
-Therefore `mod2.atg` additionally accepts `REM` and `&`.
-
-### 4. Relational operators
-
-`mod2.atg` allows:
-
-```text
-Rel = "=" | "#" | "<>" | "<" | "<=" | ">" | ">=" | "IN" .
-```
-
-`pimmod2.atg` allows:
-
-```text
-Relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" .
-```
-
-Thus `mod2.atg` additionally accepts `<>`.
-
-### 5. Set elements
-
-`mod2.atg` uses:
-
-```text
-Elem = ConstExpr [ ".." ConstExpr ] .
-```
-
-`pimmod2.atg` uses:
-
-```text
-Element = Expression [ ".." Expression ] .
-```
-
-So the first grammar restricts set elements/ranges to constant expressions, while the second permits general expressions.
-
-### 6. Statement structure
-
-`mod2.atg` combines assignment and procedure-call syntax:
-
-```text
-Stat = [ Design ( ":=" Expr | [ ActPar ] )
-      | IfStat | CaseStat | LoopStat | ForStat
-      | RepeatStat | WhileStat | WithStat
-      | "EXIT" | "RETURN" [ Expr ]
-      ] .
-```
-
-`pimmod2.atg` factors these explicitly:
-
-```text
-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.
-
-## Naming and organization differences
-
-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.
-
-## Practical interpretation
-
-| 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 |
-
-## Bottom line
-
-`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.

+ 0 - 548
coco-chatgpt-doesntwork/explanations.md

@@ -1,548 +0,0 @@
-# Mini Modula-2 Compiler — Explanations
-
-## 1. Goal
-
-The project is a simplified Modula-2-like compiler implemented in GNU Modula-2.
-
-The language is intentionally smaller than full Modula-2:
-
-- no procedures or functions
-- `INTEGER` and `CHAR` types
-- variables and constants as supported by the compiler
-- basic statements and expressions
-- symbol table
-- type checking
-- code generation
-
-The objective is to have a real compiler pipeline rather than only a parser.
-
-## 2. Compiler architecture
-
-The compiler follows this pipeline:
-
-```text
-MiniM2 source
-    |
-    v
-+-----------+
-|   Lexer   |
-+-----------+
-    |
-    v
-+-----------+
-|  Parser   |
-+-----------+
-    |
-    v
-+----------------+
-| Symbol table   |
-| Type checking  |
-+----------------+
-    |
-    v
-+----------------+
-| Code generator |
-+----------------+
-    |
-    v
-Generated GNU Modula-2
-    |
-    v
-+-----------+
-|    gm2    |
-+-----------+
-    |
-    v
-Native executable
-```
-
-The compiler itself is written in GNU Modula-2.
-
-## 3. Why GNU Modula-2 is used as the backend
-
-Coco/R has traditionally provided compiler-generator targets such as C#, Java and C++, but GNU Modula-2 is not a standard Coco/R target.
-
-Instead of trying to make Coco/R generate GNU Modula-2 code, the compiler can be implemented directly in GNU Modula-2.
-
-The first native backend is source-to-source:
-
-1. Parse the MiniM2 program.
-2. Build and check its symbols and types.
-3. Generate valid GNU Modula-2.
-4. Invoke `gm2`.
-5. Let GNU Modula-2 produce the final native executable.
-
-This is already a genuine compiler architecture: the front-end performs lexical analysis, parsing and semantic checking, while GNU Modula-2 acts as the native backend.
-
-## 4. GNU Modula-2
-
-GNU Modula-2 is provided by GCC.
-
-Typical compilation is:
-
-```bash
-gm2 -g hello.mod
-```
-
-GNU Modula-2 uses `.mod` files for implementation/program modules and `.def` files for definition modules.
-
-The generated program can therefore be compiled by the GNU Modula-2 compiler.
-
-## 5. Project layout
-
-The generated project is:
-
-```text
-mini-modula2-real-compiler/
-├── MiniM2C.mod
-├── Makefile
-├── README.md
-└── examples/
-    ├── hello.mod
-    └── bad.mod
-```
-
-`MiniM2C.mod` contains the compiler implementation.
-
-`examples/hello.mod` is a valid example program.
-
-`examples/bad.mod` is intended to demonstrate semantic/type errors.
-
-## 6. Building
-
-From the project directory:
-
-```bash
-make
-```
-
-The compiler executable is intended to be:
-
-```text
-minim2c
-```
-
-A MiniM2 source file can then be compiled with:
-
-```bash
-./minim2c examples/hello.mod
-```
-
-The compiler generates a GNU Modula-2 source file:
-
-```text
-examples/hello.mod.gen.mod
-```
-
-and then invokes `gm2` to build the native executable.
-
-The exact executable name can depend on the generated module and GNU Modula-2 toolchain.
-
-## 7. Running the example
-
-The intended workflow is:
-
-```bash
-cd mini-modula2-real-compiler
-make
-./minim2c examples/hello.mod
-./mini-program
-```
-
-If the generated executable has a different name, use the executable name reported by the compiler or inspect the generated build output.
-
-## 8. Lexer
-
-The lexer converts source characters into tokens.
-
-Typical token categories include:
-
-- identifiers
-- integer literals
-- character literals
-- operators
-- punctuation
-- keywords
-
-Examples of keywords include:
-
-```text
-MODULE
-BEGIN
-END
-VAR
-CONST
-INTEGER
-CHAR
-READ
-WRITE
-IF
-THEN
-ELSE
-WHILE
-DO
-```
-
-The lexer is responsible for recognizing these tokens before parsing.
-
-## 9. Parser
-
-The parser consumes the token stream and verifies that the program follows the MiniM2 grammar.
-
-A simplified structure is:
-
-```text
-Module
-    = MODULE identifier ;
-      declarations
-      BEGIN
-        statements
-      END identifier .
-```
-
-Expressions are parsed according to precedence.
-
-For example:
-
-```text
-a + b * c
-```
-
-must be interpreted as:
-
-```text
-a + (b * c)
-```
-
-rather than:
-
-```text
-(a + b) * c
-```
-
-## 10. Symbol table
-
-The symbol table records declared identifiers.
-
-For each identifier the compiler can keep information such as:
-
-```text
-name
-kind
-type
-```
-
-For example:
-
-```text
-x : INTEGER
-letter : CHAR
-```
-
-When an identifier is used, the compiler looks it up in the symbol table.
-
-This allows the compiler to detect errors such as:
-
-```text
-unknown variable
-duplicate declaration
-```
-
-## 11. Type checking
-
-The semantic phase checks that expressions and statements use compatible types.
-
-Examples:
-
-```text
-INTEGER + INTEGER
-```
-
-is valid.
-
-But:
-
-```text
-INTEGER + CHAR
-```
-
-is rejected by the type checker.
-
-Assignments are also checked.
-
-For example:
-
-```text
-VAR
-    x : INTEGER;
-    c : CHAR;
-```
-
-Then:
-
-```text
-x := 10;
-```
-
-is valid, while:
-
-```text
-x := c;
-```
-
-should produce a type error.
-
-## 12. Code generation
-
-The current backend generates GNU Modula-2 source.
-
-For example, an internal MiniM2 construct such as:
-
-```text
-x := 10;
-```
-
-can be emitted as GNU Modula-2:
-
-```modula2
-x := 10;
-```
-
-The generated source is then compiled by `gm2`.
-
-This approach makes the compiler relatively small while still producing native executables.
-
-## 13. Important backend limitation
-
-The first implementation is deliberately simple.
-
-In particular, the initial `WRITE` implementation supports only simple operands such as an identifier or literal rather than every possible expression.
-
-For example, this may be supported:
-
-```text
-WRITE(x);
-```
-
-while something such as:
-
-```text
-WRITE(x + 1);
-```
-
-requires an expression-aware `WRITE` code-generation path.
-
-That is one of the natural next improvements.
-
-## 14. Error handling
-
-The compiler should report lexical, syntactic and semantic errors.
-
-Examples:
-
-```text
-unexpected token
-expected identifier
-undeclared identifier
-duplicate declaration
-type mismatch
-```
-
-A useful future improvement is to preserve exact source line and column information for every token and report errors like:
-
-```text
-example.mod:12:7: type mismatch
-```
-
-## 15. Why this is a real compiler
-
-A compiler does not have to directly emit machine instructions itself.
-
-A common architecture is:
-
-```text
-source
-  -> front-end
-  -> intermediate representation / generated source
-  -> backend compiler
-  -> object code
-  -> executable
-```
-
-In this project, GNU Modula-2 is the backend.
-
-The compiler therefore performs real compilation work:
-
-- lexical analysis
-- syntax analysis
-- symbol resolution
-- semantic/type checking
-- code generation
-- native compilation
-
-## 16. Future evolution
-
-A stronger version can evolve toward:
-
-### AST
-
-Instead of immediately generating code while parsing, build an Abstract Syntax Tree:
-
-```text
-Module
- ├── Declarations
- └── Statements
-      ├── Assignment
-      ├── If
-      ├── While
-      └── Write
-```
-
-### Intermediate representation
-
-The AST can then be converted into an IR.
-
-For example:
-
-```text
-LOAD_CONST 10
-STORE x
-```
-
-or:
-
-```text
-LOAD x
-LOAD 1
-ADD
-STORE x
-```
-
-### Better code generation
-
-The IR can then be translated to:
-
-- GNU Modula-2
-- C
-- LLVM IR
-- assembly
-- another native backend
-
-### More language features
-
-Possible additions include:
-
-- `BOOLEAN`
-- arrays
-- records
-- `FOR`
-- richer `IF`
-- richer `WHILE`
-- modules and definition modules
-- procedures
-- functions
-- parameters
-- standard library support
-
-## 17. Relation to the Theia extension
-
-The compiler and the Theia Modula-2 extension can eventually be integrated.
-
-Theia can provide:
-
-- syntax highlighting
-- indentation
-- keyword uppercasing
-- snippets
-- diagnostics
-- build commands
-- compiler invocation
-- error navigation
-
-The compiler can provide:
-
-- parsing
-- semantic analysis
-- type checking
-- code generation
-- executable generation
-
-A future language-server integration could expose compiler diagnostics directly in the editor.
-
-## 18. Automatic keyword uppercasing
-
-The Theia extension has a separate editor feature for automatic Modula-2 keyword uppercasing.
-
-The required behavior is:
-
-> Only the keyword currently being typed is converted to uppercase.
-
-It should not uppercase unrelated existing text in the document.
-
-For example, when typing:
-
-```text
-mod
-```
-
-the editor can turn the current keyword into:
-
-```text
-MOD
-```
-
-without modifying other words.
-
-## 19. Snippets
-
-The Theia extension can also provide Modula-2 snippets.
-
-Typical snippets can accelerate constructs such as:
-
-```modula2
-MODULE ...;
-BEGIN
-...
-END ... .
-```
-
-or declarations and control structures.
-
-Snippets are normally triggered through the editor's completion/snippet mechanism.
-
-## 20. Verification status
-
-The project was generated as a GNU Modula-2 compiler prototype.
-
-It should not be described as production-ready without compiling and testing it with an installed GNU Modula-2 (`gm2`) toolchain.
-
-The development environment used to prepare the project did not have `gm2` available, so the generated compiler was not actually built and executed there.
-
-Before treating it as a finished compiler, install GNU Modula-2 and run:
-
-```bash
-gm2 --version
-make
-./minim2c examples/hello.mod
-```
-
-Then test both successful programs and intentionally invalid programs.
-
-## 21. Recommended next step
-
-The most useful next improvement is to make the compiler robust enough to compile its complete test suite under GNU Modula-2.
-
-After that, the compiler can be upgraded from the simple source-to-source backend to:
-
-```text
-Lexer
-  -> Parser
-  -> AST
-  -> Symbol table
-  -> Type checker
-  -> IR
-  -> Code generator
-  -> Native executable
-```
-
-This provides a cleaner foundation for adding the full set of desired Modula-2 features.

BIN
coco-chatgpt-doesntwork/mini-modula2-cocor-xds-attributed.zip


BIN
coco-chatgpt-doesntwork/mini-modula2-real-compiler.zip


+ 0 - 112
coco-chatgpt-doesntwork/mod2.atg

@@ -1,112 +0,0 @@
-COMPILER Mod2
-(* Alternative grammar for PIM style Modula-2 *)
-
-CHARACTERS
-  eol      = CHR(13) .
-  letter   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
-  octDigit = "01234567" .
-  digit    = octDigit + '89'.
-  hexDigit = digit + 'ABCDEF'.
-  noQuote1 = ANY - "'" - eol .
-  noQuote2 = ANY - '"' - eol .
-
-IGNORE  CHR(9) .. CHR(13)
-
-COMMENTS
-  FROM '(*' TO '*)' NESTED
-
-TOKENS
-  id      =  letter { letter | digit }.
-  integer =    digit { digit }
-             | digit { digit }  CONTEXT ("..")
-             | octDigit { octDigit } ("B" | "C")
-             | digit { hexDigit } "H".
-  real    =  digit { digit } "." { digit }
-             [ "E" [ "+" | "-" ] digit { digit } ].
-  string  =    "'" { noQuote1 } "'"
-             | '"' { noQuote2 } '"'.
-
-PRODUCTIONS
-  Mod2         =  DefMod | [ "IMPLEMENTATION" ] ProgMod .
-  ProgMod      =  "MODULE" id [ Priority ] ";" { Import } Block id "." .
-  Def          =    "CONST" { ConstDecl ";" }
-                  | "TYPE"  { id [ "=" Type ] ";" }
-                  | "VAR"   { VarDecl ";" }
-                  | ProcHead ";" .
-  DefMod       =  "DEFINITION" "MODULE" id ";" { Import } { Def } "END" id "." .
-  Import       =  "FROM" id "IMPORT" IdList ";" | "IMPORT" id { "," id } ";" .
-  Export       =  "EXPORT" [ "QUALIFIED" ] IdList ";" .
-  Priority     =  "[" ConstExpr "]" .
-  ModDecl      =  "MODULE" id [ Priority ] ";" { Import } [ Export ] Block id .
-  FormType     =  [ "ARRAY" "OF" ] QualId .
-  QualId       =  id { "." id } .
-  FPSect       =  [ "VAR" ] IdList ":" FormType .
-  FormPar      =  "(" [ FPSect { ";" FPSect } ] ")" [ ":" QualId ] .
-  Decl         =    "CONST" { ConstDecl ";" }
-                  | "TYPE"  { TypeDecl  ";" }
-                  | "VAR"   { VarDecl   ";" }
-                  | ProcDecl ";"
-                  | ModDecl  ";" .
-  Block        =  { Decl } [ "BEGIN"  StatSeq ] "END" .
-  StatSeq      =  Stat { ";" Stat } .
-  Stat         =  [ Design ( ":=" Expr | [ ActPar ] )
-                  | IfStat  | CaseStat | LoopStat | ForStat
-                  | RepeatStat | WhileStat | WithStat
-                  | "EXIT" | "RETURN" [ Expr ]
-                  ] .
-  ProcHead     =  "PROCEDURE" id [ FormPar ] .
-  ProcDecl     =  ProcHead ";" ( Block id | "FORWARD" ) .
-  WithStat     =  "WITH" Design "DO" StatSeq "END" .
-  LoopStat     =  "LOOP" StatSeq "END" .
-  ForStat      =  "FOR" id ":=" Expr "TO" Expr [ "BY" ConstExpr ]
-                  "DO" StatSeq "END".
-  RepeatStat   =  "REPEAT" StatSeq "UNTIL" Expr  .
-  WhileStat    =  "WHILE" Expr "DO" StatSeq "END" .
-  Case         =  [ CaseLabList ":" StatSeq ] .
-  CaseStat     =  "CASE" Expr "OF" Case { "|" Case } [ "ELSE" StatSeq ] "END" .
-  IfStat       =  "IF" Expr "THEN" StatSeq
-                  { "ELSIF" Expr "THEN" StatSeq }
-                  [ "ELSE" StatSeq ]
-                  "END" .
-  ActPar       =  "(" [ ExpList ] ")" .
-  Elem         =  ConstExpr [ ".." ConstExpr ] .
-  Fact         =    integer | real | string | SetRest
-                  | id { SetRest | "." id | "[" ExpList "]" | "^" } [ ActPar ]
-                  | "(" Expr ")"
-                  | ( "NOT" | "~" ) Fact.
-  SetRest      =  "{" [ Elem { "," Elem } ] "}" .
-  MulOp        =  "*" | "/" | "DIV" | "REM" | "MOD" | "AND" | "&" .
-  Term         =  Fact { MulOp Fact }.
-  AddOp        =  "+" | "-" | "OR" .
-  SimExpr      =  [ "+" | "-" ] Term { AddOp Term }.
-  Rel          =  "=" | "#" | "<>" | "<" | "<=" | ">" | ">=" | "IN" .
-  Expr         =  SimExpr [ Rel SimExpr ] .
-  ConstDecl    =  id "=" ConstExpr .
-  ConstExpr    =  Expr.
-  TypeDecl     =  id "=" Type .
-  Type         =    SimType | ArrayType | RecType
-                  | SetType | PointerType | ProcType .
-  SimType      =    QualId [ "[" ConstExpr ".." ConstExpr "]" ]
-                  | Enum | "[" ConstExpr ".." ConstExpr "]" .
-  Enum         =  "(" IdList ")" .
-  IdList       =  id { "," id } .
-  ArrayType    =  "ARRAY" SimType { "," SimType } "OF" Type.
-  RecType      =  "RECORD" FieldListSeq "END" .
-  FieldListSeq =  FieldList { ";" FieldList } .
-  FieldList    =  [ IdList ":" Type
-                   | "CASE" [ id ] ":" QualId "OF" Variant { "|" Variant }
-                     [ "ELSE" FieldListSeq ] "END"
-                  ].
-  Variant      =  [ CaseLabList ":" FieldListSeq ] .
-  CaseLabList  =  CaseLabs { "," CaseLabs } .
-  CaseLabs     =  ConstExpr [ ".." ConstExpr ] .
-  SetType      =  "SET" "OF" SimType .
-  PointerType  =  "POINTER" "TO" Type .
-  ProcType     =  "PROCEDURE" [ FormTypeList ] .
-  FormTypeList =  "(" [ [ "VAR" ] FormType { "," [ "VAR" ] FormType } ] ")"
-                  [ ":" QualId ] .
-  VarDecl      =  IdList ":" Type .
-  Design       =  id { "[" ExpList "]" | "^" | "." id }.
-  ExpList      =  Expr { "," Expr }.
-
-END Mod2.

+ 0 - 117
coco-chatgpt-doesntwork/pimmod2.atg

@@ -1,117 +0,0 @@
-COMPILER Mod2
-(* COCO/R Grammar for Modula-2 based on "Programming in Modula-2 *)
-
-CHARACTERS
-  eol      = CHR(13) .
-  letter   = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
-  octDigit = "01234567" .
-  digit    = octDigit + '89' .
-  hexDigit = digit + 'ABCDEF' .
-  noQuote1 = ANY - "'" - eol .
-  noQuote2 = ANY - '"' - eol .
-
-IGNORE  CHR(9).. CHR(13)
-
-COMMENTS
-  FROM '(*' TO '*)' NESTED
-
-TOKENS
-  ident   =  letter { letter | digit } .
-  integer =    digit { digit }
-             | digit { digit }  CONTEXT ("..")
-             | octDigit { octDigit } ("B" | "C")
-             | digit { hexDigit } "H" .
-  real    =  digit { digit } "." { digit }
-             [ "E" [ "+" | "-" ] digit { digit } ] .
-  string  =    "'" { noQuote1 } "'"
-             | '"' { noQuote2 } '"' .
-
-PRODUCTIONS
-  Mod2                 = DefinitionModule | [ "IMPLEMENTATION" ] ProgramModule .
-  Number               = integer | real .
-  QualIdent            = ident { "." ident } .
-  ConstantDeclaration  = ident "=" ConstExpression .
-  ConstExpression      = Expression .
-  TypeDeclaration      = ident "=" Type .
-  Type                 =   SimpleType | ArrayType | RecordType | SetType
-                         | PointerType | ProcedureType .
-  SimpleType           = QualIdent | Enumeration | SubrangeType .
-  Enumeration          = "(" IdentList ")" .
-  IdentList            = ident { "," ident } .
-  SubrangeType         = [ ident ] "[" ConstExpression ".." ConstExpression "]" .
-  ArrayType            = "ARRAY" SimpleType { "," SimpleType } "OF" Type .
-  RecordType           = "RECORD" FieldListSequence "END" .
-  FieldListSequence    = FieldList { ";" FieldList } .
-  FieldList            =   [ IdentList ":" Type
-                         | "CASE" [ ident ] ":" QualIdent "OF"
-                           Variant { "|" Variant }
-                           [ "ELSE" FieldListSequence ] "END" ] .
-  Variant              = [ CaseLabelList ":" FieldListSequence ] .
-  CaseLabelList        = CaseLabels { "," CaseLabels } .
-  CaseLabels           = ConstExpression [ ".." ConstExpression ] .
-  SetType              = "SET" "OF" SimpleType .
-  PointerType          = "POINTER" "TO" Type .
-  ProcedureType        = "PROCEDURE" [ FormalTypeList ] .
-  FormalTypeList       = "(" [ [ "VAR" ] FormalType
-                         { "," [ "VAR" ] FormalType } ] ")" [ ":" QualIdent ] .
-  VariableDeclaration  = IdentList ":" Type .
-  Designator           = QualIdent { "." ident | "[" ExpList "]" | "^" } .
-  ExpList              = Expression { "," Expression } .
-  Expression           = SimpleExpression [ Relation SimpleExpression ] .
-  Relation             = "=" | "#" | "<" |"<=" | ">" | ">=" | "IN" .
-  SimpleExpression     = [ "+" | "-" ] Term { AddOperator Term } .
-  AddOperator          = "+" | "-" | "OR" .
-  Term                 = Factor { MulOperator Factor } .
-  MulOperator          = "*" |"/" | "DIV" | "MOD" | "AND" .
-  Factor               =   Number | string | Set | "NOT" Factor
-                         | Designator [ ActualParameters ]
-                         | "(" Expression ")" .
-  Set                  = [ QualIdent ] "{" [ Element { "," Element } ] "}" .
-  Element              = Expression [ ".." Expression ] .
-  ActualParameters     = "(" [ ExpList ] ")" .
-  Statement            = [  Assignment | ProcedureCall | IfStatement
-                          | CaseStatement | WhileStatement | RepeatStatement
-                          | LoopStatement | ForStatement | WithStatement
-                          | "EXIT" | "RETURN" [ Expression ] ] .
-  Assignment           = Designator ":=" Expression .
-  ProcedureCall        = Designator [ ActualParameters ] .
-  StatementSequence    = Statement { ";" Statement } .
-  IfStatement          = "IF" Expression "THEN" StatementSequence
-                         { "ELSIF" Expression "THEN" StatementSequence }
-                         [ "ELSE" StatementSequence ] "END" .
-  CaseStatement        = "CASE" Expression "OF" Case { "|" Case }
-                         [ "ELSE" StatementSequence ] "END" .
-  Case                 = [ CaseLabelList ":" StatementSequence ] .
-  WhileStatement       = "WHILE" Expression "DO" StatementSequence "END" .
-  RepeatStatement      = "REPEAT" StatementSequence "UNTIL" Expression .
-  ForStatement         = "FOR" ident ":=" Expression "TO" Expression
-                         [ "BY" ConstExpression ] "DO" StatementSequence "END" .
-  LoopStatement        = "LOOP" StatementSequence "END" .
-  WithStatement        = "WITH" Designator "DO" StatementSequence "END" .
-  ProcedureDeclaration = ProcedureHeading ";" Block ident .
-  ProcedureHeading     = "PROCEDURE" ident [ FormalParameters ] .
-  Block                = { Declaration } [ "BEGIN" StatementSequence ] "END" .
-  Declaration          =   "CONST" { ConstantDeclaration ";" }
-                         | "TYPE" { TypeDeclaration ";" }
-                         | "VAR" { VariableDeclaration ";" }
-                         | ProcedureDeclaration ";"
-                         | ModuleDeclaration ";" .
-  FormalParameters     = "(" [ FPSection { ";" FPSection } ] ")"
-                         [ ":" QualIdent ] .
-  FPSection            = [ "VAR" ] IdentList ":" FormalType .
-  FormalType           = [ "ARRAY" "OF" ] QualIdent .
-  ModuleDeclaration    = "MODULE" ident [ Priority ] ";"
-                         [ Import ] [ Export ] Block ident .
-  Priority             = "[" ConstExpression "]" .
-  Export               = "EXPORT" [ "QUALIFIED" ] IdentList ";" .
-  Import               = [ "FROM" ident ] "IMPORT" IdentList ";" .
-  DefinitionModule     = "DEFINITION" "MODULE" ident ";"
-                         { Import } { Definition } "END" ident "." .
-  Definition           =   "CONST" { ConstantDeclaration ";" } |
-                         | "TYPE" { ident [ "=" Type ] ";" }
-                         | "VAR" { VariableDeclaration ";" }
-                         | ProcedureHeading ";" .
-  ProgramModule        = "MODULE" ident [ Priority ] ";"
-                         { Import } Block ident "." .
-
-END Mod2.