| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- Coco/R - Compiler-Compiler V1.53
- Released by Pat Terry 17 September 2002
- Source file: pascal.atg
- Listing:
- 1 COMPILER Pascal
- 2 (* J & W Pascal - not Turbo Pascal *)
- 3 (* This grammar is not LL(1) *)
- 4
- 5 CHARACTERS
- 6 eol = CHR(13) .
- 7 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
- 8 digit = "0123456789".
- 9 noQuote1 = ANY - "'" - eol .
- 10
- 11 IGNORE CHR(9) .. CHR(13)
- 12 IGNORE CASE
- ***** ^ IGNORE CASE must appear earlier
- 13
- 14 COMMENTS FROM "(*" TO "*)"
- 15 COMMENTS FROM "{" TO "}"
- 16
- 17 TOKENS
- 18 identifier = letter { letter | digit } .
- 19 integer = digit { digit } | digit { digit } CONTEXT ("..") .
- 20 real = digit { digit } "." digit { digit }
- 21 [ "E" ["+" | "-"] digit { digit } ]
- 22 | digit { digit } "E" ["+" | "-"] digit { digit } .
- 23 string = "'" { noQuote1 | "''" } "'" .
- 24
- 25 PRODUCTIONS
- ***** ^ could not make deterministic automaton
- 26
- 27 Pascal = "program" NewIdent [ ExternalFiles ] ";"
- 28 Block "." .
- 29
- 30 ExternalFiles = "(" NewIdentList ")" .
- 31
- 32 Block = DeclarationPart StatementPart .
- 33
- 34 DeclarationPart = LabelDeclarations ConstDefinitions
- 35 TypeDefinitions VarDeclarations
- 36 { ProcDeclarations } .
- 37
- 38 (* -------------------------------------------------------------------- *)
- 39
- 40 LabelDeclarations = [ "label" Labels ";" ] .
- 41
- 42 Labels = Label { "," Label } .
- 43
- 44 Label = UnsignedInt .
- 45
- 46 (* -------------------------------------------------------------------- *)
- 47
- 48 ConstDefinitions = [ "const" ConstDef { ConstDef } ] .
- 49
- 50 ConstDef = NewIdent "=" Constant ";" .
- 51
- 52 Constant = [ "+" | "-" ] ( UnsignedNumber | ConstIdent ) | String .
- 53
- 54 UnsignedNumber = UnsignedInt | UnsignedReal .
- 55
- 56 ConstIdent = identifier .
- 57
- 58 (* -------------------------------------------------------------------- *)
- 59
- 60 TypeDefinitions = [ "type" TypeDef { TypeDef } ] .
- 61
- 62 TypeDef = NewIdent "=" Type ";" .
- 63
- 64 Type = SimpleType | [ "packed" ] StructType | "^" TypeIdent .
- 65
- 66 SimpleType = TypeIdent | EnumerationType | SubrangeType .
- 67
- 68 TypeIdent = identifier .
- 69
- 70 EnumerationType = "(" NewIdentList ")" .
- 71
- 72 SubrangeType = Constant ".." Constant .
- 73
- 74 StructType = ArrayType | RecordType | SetType | FileType .
- 75
- 76 ArrayType = "array" "[" IndexList "]" "of" Type .
- 77
- 78 IndexList = SimpleType { "," SimpleType } .
- 79
- 80 RecordType = "record" FieldList "end" .
- 81
- 82 SetType = "set" "of" SimpleType .
- 83
- 84 FileType = "file" "of" Type .
- 85
- 86 FieldList = [ ( fixedPart [ ";" VariantPart ] | VariantPart ) [ ";" ] ] .
- 87
- 88 fixedPart = RecordSection { ";" RecordSection } .
- 89
- 90 RecordSection = NewIdentList ":" Type .
- 91
- 92 VariantPart = "case" VariantSelector "of" Variant { ";" Variant } .
- 93
- 94 VariantSelector = [ NewIdent ":" ] TypeIdent .
- 95
- 96 Variant = CaseLabelList ":" "(" FieldList ")" .
- 97
- 98 (* -------------------------------------------------------------------- *)
- 99
- 100 VarDeclarations = [ "var" VarDecl { VarDecl } ] .
- 101
- 102 VarDecl = NewIdentList ":" Type ";" .
- 103
- 104 (* -------------------------------------------------------------------- *)
- 105
- 106 ProcDeclarations = ( ProcHeading | FuncHeading ) ";" Body ";" .
- 107
- 108 ProcHeading = "procedure" NewIdent [ FormalParams ] .
- 109
- 110 FuncHeading = "function" NewIdent [ FormalParams ] ReturnType .
- 111
- 112 ReturnType = [ (* empty if forward referenced *) ":" TypeIdent ] .
- 113
- 114 Body = Block | "forward" .
- 115
- 116 FormalParams = "(" FormalSection { ";" FormalSection } ")" .
- 117
- 118 FormalSection = [ "var" ] ParamGroup | ProcHeading | FuncHeading .
- 119
- 120 ParamGroup = NewIdentList ":" ParamType .
- 121
- 122 ParamType = TypeIdent
- 123 | "array" "[" IndexSpecList "]" "of" ParamType
- 124 | "packed" "array" "[" IndexSpec "]" "of" TypeIdent .
- 125
- 126 IndexSpecList = IndexSpec { ";" IndexSpec } .
- 127
- 128 IndexSpec = NewIdent ".." NewIdent ":" TypeIdent .
- 129
- 130 (* -------------------------------------------------------------------- *)
- 131
- 132 StatementPart = CompoundStatement .
- 133
- 134 CompoundStatement = "begin" StatementSequence "end" .
- 135
- 136 StatementSequence = Statement { ";" Statement } .
- 137
- 138 Statement = [ Label ":" ]
- 139 [ AssignmentOrCall
- 140 | CompoundStatement
- 141 | GotoStatement
- 142 | WhileStatement
- 143 | RepeatStatement
- 144 | IfStatement
- 145 | CaseStatement
- 146 | ForStatement
- 147 | WithStatement ] .
- 148
- 149 AssignmentOrCall = Designator ( ":=" Expression | [ ActualParams ] ) .
- 150
- 151 ActualParams = "(" ActualParameter { "," ActualParameter } ")" .
- 152
- 153 ActualParameter = Expression [ FieldWidth (* only in i/o *) ] .
- 154
- 155 FieldWidth = ":" IntegerExpression [ ":" IntegerExpression ] .
- 156
- 157 GotoStatement = "goto" Label .
- 158
- 159 WhileStatement = "while" BooleanExpression "do" Statement .
- 160
- 161 RepeatStatement = "repeat" StatementSequence "until" BooleanExpression .
- 162
- 163 IfStatement = "if" BooleanExpression "then" Statement
- 164 [ "else" Statement ] .
- 165
- 166 CaseStatement = "case" OrdinalExpression "of" CaseList "end" .
- 167
- 168 CaseList = OneCase { ";" OneCase } [ ";" ] .
- 169
- 170 OneCase = CaseLabelList ":" Statement .
- 171
- 172 CaseLabelList = CaseLabel { "," CaseLabel } .
- 173
- 174 CaseLabel = Constant .
- 175
- 176 ForStatement = "for" ControlVariable ":=" OrdinalExpression
- 177 ( "to" | "downto" ) OrdinalExpression "do" Statement .
- 178
- 179 ControlVariable = identifier .
- 180
- 181 WithStatement = "with" RecVarList "do" Statement .
- 182
- 183 RecVarList = Designator { "," Designator } .
- 184
- 185 (* -------------------------------------------------------------------- *)
- 186
- 187 IntegerExpression = Expression .
- 188
- 189 BooleanExpression = Expression .
- 190
- 191 OrdinalExpression = Expression .
- 192
- 193 Expression = SimpleExpression [ RelOp SimpleExpression ] .
- 194
- 195 RelOp = "=" | "<" | ">" | "<=" | ">=" | "<>" | "in" .
- 196
- 197 SimpleExpression = ( "+" Term | "-" Term | Term ) { AddOp Term } .
- 198
- 199 AddOp = "+" | "-" | "or" .
- 200
- 201 Term = Factor { MulOp Factor } .
- 202
- 203 MulOp = "*" | "/" | "div" | "mod" | "and" .
- 204
- 205 Factor = Designator [ ActualParams ]
- 206 | UnsignedLiteral
- 207 | SetConstructor
- 208 | "(" Expression ")"
- 209 | "not" Factor .
- 210
- 211 Designator = identifier { "." identifier | "[" ExpList "]" | "^" } .
- 212
- 213 ExpList = Expression { "," Expression } .
- 214
- 215 UnsignedLiteral = UnsignedNumber | "nil" | String .
- 216
- 217 SetConstructor = "[" Member { "," Member } "]" .
- 218
- 219 Member = Expression [ ".." Expression ] .
- 220
- 221 (* -------------------------------------------------------------------- *)
- 222
- 223 NewIdentList = NewIdent { "," NewIdent } .
- 224
- 225 NewIdent = identifier .
- 226
- 227 UnsignedInt = integer .
- 228
- 229 UnsignedReal = real .
- 230
- 231 String = string .
- 232
- 233 END Pascal.
- 2 errors
|