pascal.lst 9.8 KB

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