p2_pascal.lst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. Coco/R - Compiler-Compiler V1.53
  2. Released by Pat Terry 17 September 2002
  3. Source file: p2_pascal.atg
  4. Grammar Tests:
  5. Deletable symbols:
  6. DeclarationSequence
  7. case
  8. StatementSequence
  9. statement
  10. FieldList
  11. FieldListSequence
  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 DeclarationSequence: "PROCEDURE" is the start of several alternatives.
  18. LL(1) error in statement: ident is the start of several alternatives.
  19. LL(1) error in designator: "(" is the start & successor of a deletable structure
  20. LL(1) error in qualident: ident is the start & successor of a deletable structure
  21. Listing:
  22. 1 (* Tags: ORIGINAL, OISOberon, Classic, ETHOberon *)
  23. 2 COMPILER Oberon
  24. 3 (* A grammar for Oberon *)
  25. 4
  26. 5 CHARACTERS
  27. 6 eol = CHR(13) .
  28. 7 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  29. 8 digit = "0123456789" .
  30. 9 hexDigit = digit + "ABCDEF" .
  31. 10 noQuote = ANY - '"' - eol .
  32. 11
  33. 12 IGNORE CHR(9) .. CHR(13)
  34. 13
  35. 14 COMMENTS
  36. 15 FROM "(*" TO "*)" NESTED
  37. 16
  38. 17 TOKENS
  39. 18 ident = letter { letter | digit } .
  40. 19 integer = digit { digit } | digit { hexDigit } "H" .
  41. 20 real = digit { digit } "." { digit }
  42. 21 [ ("E" | "D") [ "+" | "-" ] digit { digit } ] .
  43. 22 CharConstant = digit { hexDigit } "X" .
  44. 23 string = '"' { noQuote } '"' .
  45. 24
  46. 25 PRODUCTIONS
  47. 26 Oberon = module .
  48. 27 number = integer | real .
  49. 28 identdef = ident [ "*" ] .
  50. 29 qualident = [ ident "." ] ident .
  51. 30 ConstantDeclaration = identdef "=" ConstExpression .
  52. 31 ConstExpression = expression .
  53. 32 TypeDeclaration = identdef "=" type .
  54. 33 type = qualident | ArrayType | RecordType | PointerType | ProcedureType .
  55. 34 ArrayType = "ARRAY" length { "," length } "OF" type .
  56. 35 length = ConstExpression .
  57. 36 RecordType = "RECORD" [ "(" BaseType ")" ] FieldListSequence "END" .
  58. 37 BaseType = qualident .
  59. 38 FieldListSequence = FieldList { ";" FieldList } .
  60. 39 FieldList = [ IdentList ":" type ] .
  61. 40 IdentList = identdef { "," identdef } .
  62. 41 PointerType = "POINTER" "TO" type .
  63. 42 ProcedureType = "PROCEDURE" [ FormalParameters ] .
  64. 43 VariableDeclaration = IdentList ":" type .
  65. 44 designator = qualident { "." ident | "[" ExpList "]" | "(" qualident ")" | "^" } .
  66. 45 ExpList = expression { "," expression } .
  67. 46 expression = SimpleExpression [ relation SimpleExpression ] .
  68. 47 relation = "=" | "#" | "<" | "<=" | ">" | ">=" | "IN" | "IS" .
  69. 48 SimpleExpression = [ "+" | "-" ] term { AddOperator term } .
  70. 49 AddOperator = "+" | "-" | "OR" .
  71. 50 term = factor { MulOperator factor } .
  72. 51 MulOperator = "*" | "/" | "DIV" | "MOD" | "&" .
  73. 52 factor = number | CharConstant | string | "NIL" | set
  74. 53 | designator [ ActualParameters ]
  75. 54 | "(" expression ")" | "~" factor .
  76. 55 set = "{" [ element { "," element } ] "}" .
  77. 56 element = expression [ ".." expression ] .
  78. 57 ActualParameters = "(" [ ExpList ] ")" .
  79. 58 statement = [ assignment | ProcedureCall | IfStatement |
  80. 59 CaseStatement | WhileStatement | RepeatStatement |
  81. 60 LoopStatement | WithStatement | "EXIT" |
  82. 61 "RETURN" [ expression ] ] .
  83. 62 assignment = designator ":=" expression .
  84. 63 ProcedureCall = designator [ ActualParameters ] .
  85. 64 StatementSequence = statement { ";" statement } .
  86. 65 IfStatement = "IF" expression "THEN" StatementSequence
  87. 66 { "ELSIF" expression "THEN" StatementSequence }
  88. 67 [ "ELSE" StatementSequence ] "END" .
  89. 68 CaseStatement = "CASE" expression "OF" case { "|" case }
  90. 69 [ "ELSE" StatementSequence ] "END" .
  91. 70 case = [ CaseLabelList ":" StatementSequence ] .
  92. 71 CaseLabelList = CaseLabels { "," CaseLabels } .
  93. 72 CaseLabels = ConstExpression [ ".." ConstExpression ] .
  94. 73 WhileStatement = "WHILE" expression "DO" StatementSequence "END" .
  95. 74 RepeatStatement = "REPEAT" StatementSequence "UNTIL" expression .
  96. 75 LoopStatement = "LOOP" StatementSequence "END" .
  97. 76 WithStatement = "WITH" qualident ":" qualident "DO" StatementSequence "END" .
  98. 77 ProcedureDeclaration = ProcedureHeading ";" ProcedureBody ident .
  99. 78 ProcedureHeading = "PROCEDURE" [ "*" ] identdef [ FormalParameters ] .
  100. 79 ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END" .
  101. 80 ForwardDeclaration = "PROCEDURE" "^" ident [ "*" ] [ FormalParameters ] .
  102. 81 DeclarationSequence = { "CONST" { ConstantDeclaration ";" }
  103. 82 | "TYPE" { TypeDeclaration ";" }
  104. 83 | "VAR" { VariableDeclaration ";" } }
  105. 84 { ProcedureDeclaration ";"
  106. 85 | ForwardDeclaration ";" } .
  107. 86 FormalParameters = "(" [ FPSection { ";" FPSection } ] ")" [ ":" qualident ] .
  108. 87 FPSection = [ "VAR" ] ident { "," ident } ":" FormalType .
  109. 88 FormalType = { "ARRAY" "OF" } (qualident | ProcedureType) .
  110. 89 ImportList = "IMPORT" import { "," import } ";" .
  111. 90 import = ident [ ":=" ident ] .
  112. 91 module = "MODULE" ident ";"
  113. 92 [ ImportList ] DeclarationSequence
  114. 93 [ "BEGIN" StatementSequence ] "END" ident "." .
  115. 94 END Oberon.
  116. 0 errors