p4_pascal.lst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. Coco/R - Compiler-Compiler V1.53
  2. Released by Pat Terry 17 September 2002
  3. Source file: pascal_impl/p4_pascal.atg
  4. Listing:
  5. 1 (* Pascal P4 ATG for Coco/R *)
  6. 2 (* Pascal-4 (1977) - N. Wirth's fourth Pascal implementation *)
  7. 3 (* Features: Nested procedures/functions, empty procedures *)
  8. 4
  9. 5 (* Tags: P4, PASCAL4, WIRTH *)
  10. 6
  11. 7 COMPILER PascalP4
  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 | ProcType .
  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 | ProcType .
  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 ProcType = "procedure" ParList ";" { [ ConstDecl ; TypeDecl ; VarDecl ; ProcDecl ] } ";" .
  73. ***** ^ invalid Factor
  74. ***** ^ invalid Factor
  75. ***** ^ invalid Factor
  76. 69
  77. 70 Statements = Statement { ";" Statement } .
  78. 71
  79. 72 Statement = IfStatement
  80. 73 | CaseStatement
  81. 74 | WhileStatement
  82. 75 | RepeatStatement
  83. 76 | ForStatement
  84. 77 | Assignment
  85. 78 | ProcCall
  86. 79 | ReturnStatement
  87. 80 | EmptyStatement
  88. 81 | ProcDecl ; (* Nested procedure *)
  89. ***** ^ invalid Factor
  90. 82
  91. 83 IfStatement = "if" Expr "then" Stmts { "else" Stmts } .
  92. ***** ^ invalid Factor
  93. 84
  94. 85 CaseStmt = "case" Expr of { CaseItem ";" } "end" .
  95. 86
  96. 87 CaseItem = LabelList ":" Stmts .
  97. 88
  98. 89 LabelList = Label { "," Label } .
  99. 90
  100. 91 Label = number .
  101. 92
  102. 93 WhileStmt = "while" Expr "do" Stmts .
  103. 94
  104. 95 RepeatStmt = "repeat" Stmts "until" Expr .
  105. 96
  106. 97 ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts
  107. 98 | "for" ident ":=" Expr "downto" Expr "do" Stmts .
  108. 99
  109. 100 Assignment = Var ":=" Expr .
  110. 101
  111. 102 ProcCall = ident "(" [ ParamList ] ")" .
  112. 103
  113. 104 ParamList = Param { "," Param } .
  114. 105
  115. 106 Param = Expr .
  116. 107
  117. 108 ReturnStmt = "return" [ Expr ] .
  118. 109
  119. 110 EmptyStatement = "" .
  120. 111
  121. 112 Expr = SimpleExpr [ Relationship SimpleExpr ] .
  122. 113
  123. 114 Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  124. 115
  125. 116 SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } .
  126. 117
  127. 118 Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } .
  128. 119
  129. 120 Factor = ["+" | "-"] ["not"] Primary .
  130. 121
  131. 122 Primary = number | ident | string | "(" Expr ")" | Primary "^" .
  132. 123
  133. 124 number = digit { digit } .
  134. 125
  135. 126 ident = letter { letter | digit } .
  136. 127
  137. 128 string = "'" { noQuote1 | "''" } "'" .
  138. 129
  139. 130 EndProgram = "." .
  140. 131 EOF
  141. 5 errors