p6_pascal.lst 4.5 KB

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