| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- Coco/R - Compiler-Compiler V1.53
- Released by Pat Terry 17 September 2002
- Source file: pascal_impl/p6_pascal.atg
- Listing:
- 1 (* Pascal P6 ATG for Coco/R *)
- 2 (* Pascal-6 (1980) - N. Wirth's sixth Pascal implementation *)
- 3 (* Features: Parameterized types (generics), additional control structures *)
- 4
- 5 (* Tags: P6, PASCAL6, WIRTH *)
- 6
- 7 COMPILER PascalP6
- 8
- 9 CHARACTERS
- 10 eol = CHR(13) .
- 11 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
- 12 digit = "0123456789" .
- 13 IGNORE CHR(9) .. CHR(13)
- 14 COMMENTS FROM "(*" TO "*)" NESTED
- 15
- 16 TOKENS
- 17 ident = letter { letter | digit } .
- 18
- 19 PRODUCTIONS
- 20
- 21 Program = "program" ident ";" Block "." .
- 22
- 23 Block = [ UnitSection ] DeclPart Statements .
- 24
- 25 UnitSection = "unit" ident ";" { FileSection } "end" ident "." .
- 26
- 27 FileSection = ident { ";" ident } .
- 28
- 29 DeclPart = [ ConstSection ] [ TypeSection ] [ VarSection ] [ ProcDecl ].
- 30
- 31 ConstSection = "const" ConstDeclList { ";" ConstDeclList } .
- 32
- 33 ConstDeclList = ident "=" Value { ";" ident "=" Value } .
- 34
- 35 TypeSection = "type" TypeDeclList { ";" TypeDeclList } .
- 36
- 37 TypeDeclList = ident "=" Type { ";" ident "=" Type } .
- 38
- 39 VarSection = "var" VarDeclList { ";" VarDeclList } .
- 40
- 41 VarDeclList = identlist ":" Type .
- 42
- 43 identlist = ident { "," ident } .
- 44
- 45 Type = SimpleType | StructType | PointerType | ArrayType | SetType | EnumType | ParamType .
- 46
- 47 SimpleType = integertype | realtype | charType | booleanType .
- 48
- 49 integertype = "integer" .
- 50 realtype = "real" .
- 51 charType = "char" .
- 52 booleanType = "boolean" .
- 53
- 54 StructType = ArrayType | RecordType | SetType | EnumType .
- 55
- 56 ArrayType = "array" "[" IndexList "]" "of" Type .
- 57
- 58 IndexList = SimpleType { "," SimpleType } .
- 59
- 60 RecordType = "record" FieldList "end" .
- 61
- 62 FieldList = Field { ";" Field } .
- 63
- 64 Field = identlist ":" Type .
- 65
- 66 SetType = "set" "of" Type .
- 67
- 68 EnumType = "(" ident { "," ident } ")" .
- 69
- 70 ParamType = "array" "[" ParamList "]" "of" Type . (* Parameterized type *)
- 71
- 72 ProcSection = "proc" ParamList ";" { [ ConstDecl ; TypeDecl ; VarDecl ] } ";" .
- ***** ^ invalid Factor
- ***** ^ invalid Factor
- 73
- 74 Statements = Statement { ";" Statement } .
- 75
- 76 Statement = IfStatement
- 77 | CaseStatement
- 78 | WhileStatement
- 79 | RepeatStatement
- 80 | ForStatement
- 81 | Assignment
- 82 | ProcCall
- 83 | ReturnStatement
- 84 | EmptyStatement
- 85 | ProcDecl ; (* Nested procedure *)
- ***** ^ invalid Factor
- 86
- 87 IfStatement = "if" Expr "then" Stmts { "else" Stmts } .
- ***** ^ invalid Factor
- 88
- 89 CaseStmt = "case" Expr of { CaseItem ";" } "end" .
- 90
- 91 CaseItem = LabelList ":" Stmts .
- 92
- 93 LabelList = Label { "," Label } .
- 94
- 95 Label = number .
- 96
- 97 WhileStmt = "while" Expr "do" Stmts .
- 98
- 99 RepeatStmt = "repeat" Stmts "until" Expr .
- 100
- 101 ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts
- 102 | "for" ident ":=" Expr "downto" Expr "do" Stmts .
- 103
- 104 Assignment = Var ":=" Expr .
- 105
- 106 ProcCall = ident "(" [ ParamList ] ")" .
- 107
- 108 ParamList = Param { "," Param } .
- 109
- 110 Param = Expr .
- 111
- 112 ReturnStmt = "return" [ Expr ] .
- 113
- 114 EmptyStatement = "" .
- 115
- 116 Expr = SimpleExpr [ Relationship SimpleExpr ] .
- 117
- 118 Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
- 119
- 120 SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } .
- 121
- 122 Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } .
- 123
- 124 Factor = ["+" | "-"] ["not"] Primary .
- 125
- 126 Primary = number | ident | string | "(" Expr ")" | Primary "^" .
- 127
- 128 number = digit { digit } .
- 129
- 130 ident = letter { letter | digit } .
- 131
- 132 string = "'" { noQuote1 | "''" } "'" .
- 133
- 134 EndProgram = "." .
- 135 EOF
- 4 errors
|