blaise_pascal.atg 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. (* Tags: BLAISE, BLAISEPASCALE, BLA *)
  2. (* Tags: ORIGINAL, OISOberon, Classic, ETHOberon *)
  3. COMPILER Oberon
  4. (* A grammar for Oberon *)
  5. CHARACTERS
  6. eol = CHR(13) .
  7. letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  8. digit = "0123456789" .
  9. hexDigit = digit + "ABCDEF" .
  10. noQuote = ANY - '"' - eol .
  11. IGNORE CHR(9) .. CHR(13)
  12. COMMENTS
  13. FROM "(*" TO "*)" NESTED
  14. TOKENS
  15. ident = letter { letter | digit } .
  16. integer = digit { digit } | digit { hexDigit } "H" .
  17. real = digit { digit } "." { digit }
  18. [ ("E" | "D") [ "+" | "-" ] digit { digit } ] .
  19. CharConstant = digit { hexDigit } "X" .
  20. string = '"' { noQuote } '"' .
  21. PRODUCTIONS
  22. Oberon = module .
  23. number = integer | real .
  24. identdef = ident [ "*" ] .
  25. qualident = [ ident "." ] ident .
  26. ConstantDeclaration = identdef "=" ConstExpression .
  27. ConstExpression = expression .
  28. TypeDeclaration = identdef "=" type .
  29. type = qualident | ArrayType | RecordType | PointerType | ProcedureType .
  30. ArrayType = "ARRAY" length { "," length } "OF" type .
  31. length = ConstExpression .
  32. RecordType = "RECORD" [ "(" BaseType ")" ] FieldListSequence "END" .
  33. BaseType = qualident .
  34. FieldListSequence = FieldList { ";" FieldList } .
  35. FieldList = [ IdentList ":" type ] .
  36. IdentList = identdef { "," identdef } .
  37. PointerType = "POINTER" "TO" type .
  38. ProcedureType = "PROCEDURE" [ FormalParameters ] .
  39. VariableDeclaration = IdentList ":" type .
  40. designator = qualident { "." ident | "[" ExpList "]" | "(" qualident ")" | "^" } .
  41. ExpList = expression { "," expression } .
  42. expression = SimpleExpression [ relation SimpleExpression ] .
  43. relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" | "IS" .
  44. SimpleExpression = [ "+" | "-" ] term { AddOperator term } .
  45. AddOperator = "+" | "-" | "OR" .
  46. term = factor { MulOperator factor } .
  47. MulOperator = "*" | "/" | "DIV" | "MOD" | "&" .
  48. factor = number | CharConstant | string | "NIL" | set
  49. | designator [ ActualParameters ]
  50. | "(" expression ")" | "~" factor .
  51. set = "{" [ element { "," element } ] "}" .
  52. element = expression [ ".." expression ] .
  53. ActualParameters = "(" [ ExpList ] ")" .
  54. statement = [ assignment | ProcedureCall | IfStatement |
  55. CaseStatement | WhileStatement | RepeatStatement |
  56. LoopStatement | WithStatement | "EXIT" |
  57. "RETURN" [ expression ] ] .
  58. assignment = designator ":=" expression .
  59. ProcedureCall = designator [ ActualParameters ] .
  60. StatementSequence = statement { ";" statement } .
  61. IfStatement = "IF" expression "THEN" StatementSequence
  62. { "ELSIF" expression "THEN" StatementSequence }
  63. [ "ELSE" StatementSequence ] "END" .
  64. CaseStatement = "CASE" expression "OF" case { "|" case }
  65. [ "ELSE" StatementSequence ] "END" .
  66. case = [ CaseLabelList ":" StatementSequence ] .
  67. CaseLabelList = CaseLabels { "," CaseLabels } .
  68. CaseLabels = ConstExpression [ ".." ConstExpression ] .
  69. WhileStatement = "WHILE" expression "DO" StatementSequence "END" .
  70. RepeatStatement = "REPEAT" StatementSequence "UNTIL" expression .
  71. LoopStatement = "LOOP" StatementSequence "END" .
  72. WithStatement = "WITH" qualident ":" qualident "DO" StatementSequence "END" .
  73. ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident .
  74. ProcedureHeading = "PROCEDURE" [ "*" ] identdef [ FormalParameters ] .
  75. ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END" .
  76. ForwardDeclaration = "PROCEDURE" "^" ident [ "*" ] [ FormalParameters ] .
  77. DeclarationSequence = { "CONST" { ConstantDeclaration ";" }
  78. | "TYPE" { TypeDeclaration ";" }
  79. | "VAR" { VariableDeclaration ";" } }
  80. { ProcedureDeclaration ";"
  81. | ForwardDeclaration ";" } .
  82. FormalParameters = "(" [ FPSection { ";" FPSection } ] ")" [ ":" qualident ] .
  83. FPSection = [ "VAR" ] ident { "," ident } ":" FormalType .
  84. FormalType = { "ARRAY" "OF" } (qualident | ProcedureType) .
  85. ImportList = "IMPORT" import { "," import } ";" .
  86. import = ident [ ":=" ident ] .
  87. module = "MODULE" ident ";"
  88. [ ImportList ] DeclarationSequence
  89. [ "BEGIN" StatementSequence ] "END" ident "." .
  90. END Oberon.