Ulm-Oberon.lst 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. Coco/R - Compiler-Compiler V1.53
  2. Released by Pat Terry 17 September 2002
  3. Source file: cocor/Oberon.atg
  4. Grammar Tests:
  5. Deletable symbols:
  6. case
  7. statement
  8. FieldList
  9. FieldListSequence
  10. StatementSequence
  11. DeclarationSequence
  12. Undefined nonterminals: -- none --
  13. Unreachable nonterminals: -- none --
  14. Circular derivations: -- none --
  15. Underivable nonterminals: -- none --
  16. LL(1) conditions:
  17. LL(1) error in statement: ident is the start of several alternatives.
  18. LL(1) error in designator: "(" is the start & successor of a deletable structure
  19. LL(1) error in qualident: ident is the start & successor of a deletable structure
  20. LL(1) error in DeclarationSequence: "PROCEDURE" is the start & successor of a deletable structure
  21. LL(1) error in CompilationUnit: "BEGIN" is the start & successor of a deletable structure
  22. LL(1) error in CompilationUnit: "END" is the start & successor of a deletable structure
  23. Listing:
  24. 1 COMPILER Oberon
  25. 2
  26. 3 /* Oberon grammar extracted from Ulm's Oberon compiler (ulmo)
  27. 4 Source: src/compiler/OberonParser.om and src/compiler/OberonLex.om
  28. 5 Coco/R grammar for the Oberon language as implemented by ulmo 0.11.0 */
  29. 6
  30. 7 /* ------------------------------------------------------------------ */
  31. 8 /* Character classes */
  32. 9 /* ------------------------------------------------------------------ */
  33. 10
  34. 11 CHARACTERS
  35. 12 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  36. 13 digit = "0123456789" .
  37. 14 hexdigit = digit + "ABCDEF" .
  38. 15 noQuote = ANY - '"' - "'" .
  39. 16
  40. 17 /* ------------------------------------------------------------------ */
  41. 18 /* Scanner tokens */
  42. 19 /* ------------------------------------------------------------------ */
  43. 20
  44. 21 TOKENS
  45. 22 ident = letter { letter | digit } .
  46. 23 integer = digit { digit } | digit { hexdigit } "H" .
  47. 24 real = digit { digit } "." { digit }
  48. 25 [ ("E" | "D") [ "+" | "-" ] digit { digit } ] .
  49. 26 charconst = digit { hexdigit } "X" .
  50. 27 string = '"' { noQuote } '"' .
  51. 28
  52. 29 /* ------------------------------------------------------------------ */
  53. 30 /* Grammar productions */
  54. 31 /* ------------------------------------------------------------------ */
  55. 32
  56. 33 PRODUCTIONS
  57. 34
  58. 35 Oberon = CompilationUnit .
  59. 36
  60. 37 CompilationUnit = [ "DEFINITION" | "MODULE" ]
  61. 38 ident
  62. 39 [ ImportList ]
  63. 40 [ DeclarationSequence ]
  64. 41 [ "BEGIN" StatementSequence ]
  65. 42 "END" ident "."
  66. 43 .
  67. 44
  68. 45 ImportList = "IMPORT"
  69. 46 ( ident [ ":=" ident ]
  70. 47 { "," ident [ ":=" ident ] } )
  71. 48 ";"
  72. 49 .
  73. 50
  74. 51 DeclarationSequence = { "CONST" { ConstantDeclaration ";" }
  75. 52 | "TYPE" { TypeDeclaration ";" }
  76. 53 | "VAR" { VariableDeclaration ";" }
  77. 54 | ProcedureDeclaration ";" }
  78. 55 { ForwardDeclaration ";" } .
  79. 56
  80. 57 ConstantDeclaration = identdef "=" ConstExpression .
  81. 58 TypeDeclaration = identdef "=" type .
  82. 59 VariableDeclaration = IdentList ":" type .
  83. 60
  84. 61 identdef = ident [ "*" ] .
  85. 62 IdentList = identdef { "," identdef } .
  86. 63
  87. 64 qualident = [ ident "." ] ident .
  88. 65
  89. 66 ConstExpression = expression .
  90. 67
  91. 68 type = qualident | ArrayType | RecordType
  92. 69 | PointerType | ProcedureType .
  93. 70
  94. 71 ArrayType = "ARRAY" length { "," length } "OF" type .
  95. 72 length = ConstExpression .
  96. 73
  97. 74 RecordType = "RECORD" [ "(" BaseType ")" ]
  98. 75 FieldListSequence "END" .
  99. 76 BaseType = qualident .
  100. 77 FieldListSequence = FieldList { ";" FieldList } .
  101. 78 FieldList = [ IdentList ":" type ] .
  102. 79
  103. 80 PointerType = "POINTER" "TO" type .
  104. 81 ProcedureType = "PROCEDURE" [ FormalParameters ] .
  105. 82
  106. 83 FormalParameters = "(" [ FPSection { ";" FPSection } ] ")"
  107. 84 [ ":" qualident ] .
  108. 85 FPSection = [ "VAR" ] ident { "," ident } ":" FormalType .
  109. 86 FormalType = { "ARRAY" "OF" } ( qualident | ProcedureType ) .
  110. 87
  111. 88 designator = qualident
  112. 89 { "." ident | "[" ExpList "]"
  113. 90 | "(" qualident ")" | "^" } .
  114. 91 ExpList = expression { "," expression } .
  115. 92
  116. 93 expression = SimpleExpression [ relation SimpleExpression ] .
  117. 94 relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" | "IS" .
  118. 95
  119. 96 SimpleExpression = [ "+" | "-" ] term { AddOperator term } .
  120. 97 AddOperator = "+" | "-" | "OR" .
  121. 98
  122. 99 term = factor { MulOperator factor } .
  123. 100 MulOperator = "*" | "/" | "DIV" | "MOD" | "&" .
  124. 101
  125. 102 factor = number | charconst | string | "NIL" | set
  126. 103 | designator [ ActualParameters ]
  127. 104 | "(" expression ")" | "~" factor .
  128. 105
  129. 106 number = integer | real .
  130. 107
  131. 108 set = "{" [ element { "," element } ] "}" .
  132. 109 element = expression [ ".." expression ] .
  133. 110
  134. 111 ActualParameters = "(" [ ExpList ] ")" .
  135. 112
  136. 113 statement = [ assignment | ProcedureCall | IfStatement
  137. 114 | CaseStatement | WhileStatement | RepeatStatement
  138. 115 | LoopStatement | WithStatement | "EXIT"
  139. 116 | "RETURN" [ expression ] ] .
  140. 117
  141. 118 assignment = designator ":=" expression .
  142. 119 ProcedureCall = designator [ ActualParameters ] .
  143. 120
  144. 121 StatementSequence = statement { ";" statement } .
  145. 122
  146. 123 IfStatement = "IF" expression "THEN" StatementSequence
  147. 124 { "ELSIF" expression "THEN" StatementSequence }
  148. 125 [ "ELSE" StatementSequence ] "END" .
  149. 126
  150. 127 CaseStatement = "CASE" expression "OF" case { "|" case }
  151. 128 [ "ELSE" StatementSequence ] "END" .
  152. 129 case = [ CaseLabelList ":" StatementSequence ] .
  153. 130 CaseLabelList = CaseLabels { "," CaseLabels } .
  154. 131 CaseLabels = ConstExpression [ ".." ConstExpression ] .
  155. 132
  156. 133 WhileStatement = "WHILE" expression "DO" StatementSequence "END" .
  157. 134 RepeatStatement = "REPEAT" StatementSequence "UNTIL" expression .
  158. 135 LoopStatement = "LOOP" StatementSequence "END" .
  159. 136 WithStatement = "WITH" qualident ":" qualident "DO" StatementSequence "END" .
  160. 137
  161. 138 ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident .
  162. 139 ProcedureHeading = "PROCEDURE" [ "*" ] identdef [ FormalParameters ] .
  163. 140 ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END" .
  164. 141
  165. 142 ForwardDeclaration = "PROCEDURE" "^" ident [ "*" ] [ FormalParameters ] .
  166. 143
  167. 144 END Oberon.
  168. 0 errors
  169. Statistics:
  170. nr of terminals: 66 (limit 400)
  171. nr of non-terminals: 53 (limit 210)
  172. nr of pragmas: 0 (limit 434)
  173. nr of symbolnodes: 119 (limit 500)
  174. nr of graphnodes: 357 (limit 1500)
  175. nr of conditionsets: 5 (limit 100)
  176. nr of charactersets: 8 (limit 250)