Ulml-Oberon.atg 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. COMPILER Oberon
  2. /* Oberon grammar extracted from Ulm's Oberon compiler (ulmo)
  3. Source: src/compiler/OberonParser.om and src/compiler/OberonLex.om
  4. Coco/R grammar for the Oberon language as implemented by ulmo 0.11.0 */
  5. /* ------------------------------------------------------------------ */
  6. /* Character classes */
  7. /* ------------------------------------------------------------------ */
  8. CHARACTERS
  9. letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  10. digit = "0123456789" .
  11. hexdigit = digit + "ABCDEF" .
  12. noQuote = ANY - '"' - "'" .
  13. /* ------------------------------------------------------------------ */
  14. /* Scanner tokens */
  15. /* ------------------------------------------------------------------ */
  16. TOKENS
  17. ident = letter { letter | digit } .
  18. integer = digit { digit } | digit { hexdigit } "H" .
  19. real = digit { digit } "." { digit }
  20. [ ("E" | "D") [ "+" | "-" ] digit { digit } ] .
  21. charconst = digit { hexdigit } "X" .
  22. string = '"' { noQuote } '"' .
  23. /* ------------------------------------------------------------------ */
  24. /* Grammar productions */
  25. /* ------------------------------------------------------------------ */
  26. PRODUCTIONS
  27. Oberon = CompilationUnit .
  28. CompilationUnit = [ "DEFINITION" | "MODULE" ]
  29. ident
  30. [ ImportList ]
  31. [ DeclarationSequence ]
  32. [ "BEGIN" StatementSequence ]
  33. "END" ident "."
  34. .
  35. ImportList = "IMPORT"
  36. ( ident [ ":=" ident ]
  37. { "," ident [ ":=" ident ] } )
  38. ";"
  39. .
  40. DeclarationSequence = { "CONST" { ConstantDeclaration ";" }
  41. | "TYPE" { TypeDeclaration ";" }
  42. | "VAR" { VariableDeclaration ";" }
  43. | ProcedureDeclaration ";" }
  44. { ForwardDeclaration ";" } .
  45. ConstantDeclaration = identdef "=" ConstExpression .
  46. TypeDeclaration = identdef "=" type .
  47. VariableDeclaration = IdentList ":" type .
  48. identdef = ident [ "*" ] .
  49. IdentList = identdef { "," identdef } .
  50. qualident = [ ident "." ] ident .
  51. ConstExpression = expression .
  52. type = qualident | ArrayType | RecordType
  53. | PointerType | ProcedureType .
  54. ArrayType = "ARRAY" length { "," length } "OF" type .
  55. length = ConstExpression .
  56. RecordType = "RECORD" [ "(" BaseType ")" ]
  57. FieldListSequence "END" .
  58. BaseType = qualident .
  59. FieldListSequence = FieldList { ";" FieldList } .
  60. FieldList = [ IdentList ":" type ] .
  61. PointerType = "POINTER" "TO" type .
  62. ProcedureType = "PROCEDURE" [ FormalParameters ] .
  63. FormalParameters = "(" [ FPSection { ";" FPSection } ] ")"
  64. [ ":" qualident ] .
  65. FPSection = [ "VAR" ] ident { "," ident } ":" FormalType .
  66. FormalType = { "ARRAY" "OF" } ( qualident | ProcedureType ) .
  67. designator = qualident
  68. { "." ident | "[" ExpList "]"
  69. | "(" qualident ")" | "^" } .
  70. ExpList = expression { "," expression } .
  71. expression = SimpleExpression [ relation SimpleExpression ] .
  72. relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" | "IS" .
  73. SimpleExpression = [ "+" | "-" ] term { AddOperator term } .
  74. AddOperator = "+" | "-" | "OR" .
  75. term = factor { MulOperator factor } .
  76. MulOperator = "*" | "/" | "DIV" | "MOD" | "&" .
  77. factor = number | charconst | string | "NIL" | set
  78. | designator [ ActualParameters ]
  79. | "(" expression ")" | "~" factor .
  80. number = integer | real .
  81. set = "{" [ element { "," element } ] "}" .
  82. element = expression [ ".." expression ] .
  83. ActualParameters = "(" [ ExpList ] ")" .
  84. statement = [ assignment | ProcedureCall | IfStatement
  85. | CaseStatement | WhileStatement | RepeatStatement
  86. | LoopStatement | WithStatement | "EXIT"
  87. | "RETURN" [ expression ] ] .
  88. assignment = designator ":=" expression .
  89. ProcedureCall = designator [ ActualParameters ] .
  90. StatementSequence = statement { ";" statement } .
  91. IfStatement = "IF" expression "THEN" StatementSequence
  92. { "ELSIF" expression "THEN" StatementSequence }
  93. [ "ELSE" StatementSequence ] "END" .
  94. CaseStatement = "CASE" expression "OF" case { "|" case }
  95. [ "ELSE" StatementSequence ] "END" .
  96. case = [ CaseLabelList ":" StatementSequence ] .
  97. CaseLabelList = CaseLabels { "," CaseLabels } .
  98. CaseLabels = ConstExpression [ ".." ConstExpression ] .
  99. WhileStatement = "WHILE" expression "DO" StatementSequence "END" .
  100. RepeatStatement = "REPEAT" StatementSequence "UNTIL" expression .
  101. LoopStatement = "LOOP" StatementSequence "END" .
  102. WithStatement = "WITH" qualident ":" qualident "DO" StatementSequence "END" .
  103. ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident .
  104. ProcedureHeading = "PROCEDURE" [ "*" ] identdef [ FormalParameters ] .
  105. ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END" .
  106. ForwardDeclaration = "PROCEDURE" "^" ident [ "*" ] [ FormalParameters ] .
  107. END Oberon.