free_pascal.lst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. Coco/R - Compiler-Compiler V1.53
  2. Released by Pat Terry 17 September 2002
  3. Source file: free_pascal.atg
  4. Listing:
  5. 1 (* Free Pascal ATG for Coco/R *)
  6. 2 (* Adapted from the standard Pascal grammar *)
  7. 3
  8. 4 (* Tags: FREEPASCAL, FP, FPC, DELPHI *)
  9. 5
  10. 6 COMPILER FreePascal
  11. 7
  12. 8 CHARACTERS
  13. 9 eol = CHR(13) .
  14. 10 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  15. 11 digit = "0123456789" .
  16. 12 IGNORE CHR(9) .. CHR(13)
  17. 13 COMMENTS FROM "(*" TO "*)" NESTED
  18. 14
  19. 15 TOKENS
  20. 16 ident = letter { letter | digit } .
  21. 17
  22. 18 PRODUCTIONS
  23. 19
  24. 20 Program = "program" ident ";" Block "." .
  25. 21
  26. 22 Block = [ UnitSection ] DeclPart Statements .
  27. 23
  28. 24 UnitSection = "unit" ident ";" ImpSection ";" "end" ident "." .
  29. 25
  30. 26 ImpSection = "implementation" [ ImpItems ] .
  31. 27
  32. 28 ImpItems = ident { ";" ident } .
  33. 29
  34. 30 DeclPart = [ ConstDecl ] [ TypeDecl ] [ VarDecl ] [ LabelDecl ] [ ProcDecl ].
  35. 31
  36. 32 ConstDecl = "const" ConstSection .
  37. 33
  38. 34 ConstSection = ConstDeclList { ";" ConstDeclList } .
  39. 35
  40. 36 ConstDeclList = ident "=" Value { ";" ident "=" Value } .
  41. 37
  42. 38 Value = number | ident | string .
  43. 39
  44. 40 TypeDecl = "type" TypeSection .
  45. 41
  46. 42 TypeSection = TypeDef { ";" TypeDef } .
  47. 43
  48. 44 TypeDef = ident "=" Type .
  49. 45
  50. 46 VarDecl = "var" VarSection .
  51. 47
  52. 48 VarSection = VarDeclList { ";" VarDeclList } .
  53. 49
  54. 50 VarDeclList = identlist ":" Type .
  55. 51
  56. 52 identlist = ident { "," ident } .
  57. 53
  58. 54 Type = SimpleType | StructType | PointerType | ArrayType | SetType | FileOfType | ClassType | InterfaceType .
  59. 55
  60. 56 SimpleType = IntType | RealType | CharType | BoolType .
  61. 57
  62. 58 IntType = "integer" .
  63. 59 RealType = "real" .
  64. 60 CharType = "char" .
  65. 61 BoolType = "boolean" .
  66. 62
  67. 63 StructType = ArrayType | RecordType | SetType | FileOfType | ClassType | InterfaceType .
  68. 64
  69. 65 ArrayType = "array" "[" IndexList "]" "of" Type .
  70. 66
  71. 67 IndexList = Type { "," Type } .
  72. 68
  73. 69 RecordType = "record" FieldList "end" .
  74. 70
  75. 71 FieldList = Field { ";" Field } .
  76. 72
  77. 73 Field = FieldListPart ":" Type .
  78. 74
  79. 75 FieldListPart = ident { "." ident } { "." ident } .
  80. 76
  81. 77 SetType = "set" "of" Type .
  82. 78
  83. 79 FileOfType = "file" of Type .
  84. 80
  85. 81 ClassType = "class" [ Ident ] .
  86. 82
  87. 83 InterfaceType = "interface" [ Ident ] .
  88. 84
  89. 85 ProcDecl = "procedure" ident [ ParDeclList ] ";" { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" .
  90. ***** ^ invalid Factor
  91. ***** ^ invalid Factor
  92. ***** ^ invalid Factor
  93. 86
  94. 87 FuncDecl = "function" ident [ ParDeclList ] ":" Type { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" .
  95. ***** ^ invalid Factor
  96. ***** ^ invalid Factor
  97. ***** ^ invalid Factor
  98. 88
  99. 89 Statements = Statement { ";" Statement } .
  100. 90
  101. 91 Statement = IfStmt
  102. 92 | CaseStmt
  103. 93 | WhileStmt
  104. 94 | RepeatStmt
  105. 95 | ForStmt
  106. 96 | AssignedStmt
  107. 97 | ProcCall
  108. 98 | RetStmt
  109. 99 | WithStmt
  110. 100 | GotoStmt
  111. 101 | WithInlineAsm ;
  112. ***** ^ invalid Factor
  113. 102
  114. 103 IfStmt = "if" Expr "then" Stmts { "else" Stmts } .
  115. ***** ^ invalid Factor
  116. 104
  117. 105 CaseStmt = "case" Expr of { CaseItem ";" } "end" .
  118. 106
  119. 107 CaseItem = Labels ":" Stmts .
  120. 108
  121. 109 Labels = Label { "," Label } .
  122. 110
  123. 111 Label = number .
  124. 112
  125. 113 WhileStmt = "while" Expr "do" Stmts .
  126. 114
  127. 115 RepeatStmt = "repeat" Stmts "until" Expr .
  128. 116
  129. 117 ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts
  130. 118 | "for" ident ":=" Expr "downto" Expr "do" Stmts .
  131. 119
  132. 120 AssignedStmt = Var ":=" Expr .
  133. 121
  134. 122 ProcCall = ident "(" [ ParamList ] ")" .
  135. 123
  136. 124 ParamList = Param { "," Param } .
  137. 125
  138. 126 Param = Expr .
  139. 127
  140. 128 RetStmt = "return" [ Expr ] .
  141. 129
  142. 130 WithStmt = "with" Var { "," Var } "do" Stmts .
  143. 131
  144. 132 GotoStmt = "goto" ident .
  145. 133
  146. 134 WithInlineAsm = "asm" AssemBlock "end" .
  147. 135
  148. 136 AssemBlock = { AsmLine } .
  149. 137
  150. 138 AsmLine = /[a-zA-Z0-9\s]+/ .
  151. 139
  152. 140 Expr = SimpleExpr [ Relationship SimpleExpr ] .
  153. 141
  154. 142 Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  155. 143
  156. 144 SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } .
  157. 145
  158. 146 Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } .
  159. 147
  160. 148 Factor = ["+" | "-"] ["not"] Primary .
  161. 149
  162. 150 Primary = number | ident | string | "(" Expr ")" | Primary "^" .
  163. 151
  164. 152 number = digit { digit } .
  165. 153
  166. 154 ident = letter { letter | digit } .
  167. 155
  168. 156 string = "'" { noQuote1 | "''" } "'" .
  169. 157
  170. 158 EndProgram = "." .
  171. 8 errors