p6_pascal.atg 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. (* Pascal P4 ATG for Coco/R *)
  2. (* Pascal-4 (1977) - N. Wirth's fourth Pascal implementation *)
  3. (* Features: Nested procedures/functions, empty procedures *)
  4. (* Tags: P4, PASCAL4, WIRTH *)
  5. COMPILER P6
  6. IGNORE CASE
  7. CHARACTERS
  8. eol = CHR(13) .
  9. letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  10. digit = "0123456789" .
  11. noQuote1 = ANY - "'" - eol .
  12. IGNORE CHR(9) .. CHR(13)
  13. COMMENTS FROM "(*" TO "*)" NESTED
  14. COMMENTS FROM "{" TO "}"
  15. TOKENS
  16. ident = letter { letter | digit } .
  17. pnumber = digit { digit } | digit { digit } CONTEXT ( ".." ) .
  18. preal = digit { digit } "." digit { digit } [ "E" [ "+" | "-" ] digit { digit } ] .
  19. pstring = "'" { noQuote1 | "''" } "'" .
  20. PRODUCTIONS
  21. P6 = "program" ident ";" Block "." .
  22. Block = [ UnitSection ] DeclPart [ Compound ] .
  23. Compound = "begin" Statements "end" .
  24. UnitSection = "unit" ident ";" { FileSection } "end" ident "." .
  25. FileSection = ident { ";" ident } .
  26. DeclPart = [ LabelSection ] [ ConstSection ] [ TypeSection ] [ VarSection ] { ProcDecl }.
  27. LabelSection = "label" Label { "," Label } ";" .
  28. ConstSection = "const" [ ConstDecl { ";" [ ConstDecl ] } ] .
  29. ConstDecl = ident "=" Value .
  30. Value = Expr .
  31. TypeSection = "type" [ TypeDecl { ";" [ TypeDecl ] } ] .
  32. TypeDecl = ident "=" Type .
  33. VarSection = "var" [ VarDecl { ";" [ VarDecl ] } ] .
  34. VarDecl = identlist ":" Type .
  35. ProcDecl = ( "procedure" | "function" ) ident [ FormalParams ] [ ":" Type ] ";" Block ";" .
  36. FormalParams = "(" [ FormalGroup { ";" FormalGroup } ] ")" .
  37. FormalGroup = [ "var" ] identlist ":" Type .
  38. identlist = ident { "," ident } .
  39. Type = SimpleType | StructType | PointerType | TypeIdent .
  40. TypeIdent = ident { "." ident } [ ".." ( ident | [ "-" ] pnumber ) ] | [ "-" ] pnumber [ ".." ( ident | [ "-" ] pnumber ) ] .
  41. PointerType = "^" Type .
  42. SimpleType = integertype | realtype | charType | booleanType .
  43. integertype = "integer" .
  44. realtype = "real" .
  45. charType = "char" .
  46. booleanType = "boolean" .
  47. StructType = ArrayType | RecordType | SetType | EnumType | ProcSection .
  48. ArrayType = "array" "[" Bound { "," Bound } "]" "of" Type .
  49. Bound = SimpleType | Expr [ ".." Expr ] .
  50. RecordType = "record" FieldList "end" .
  51. FieldList = [ Field { ";" [ Field ] } ] .
  52. Field = identlist ":" Type .
  53. SetType = "set" "of" Type .
  54. EnumType = "(" ident { "," ident } ")" .
  55. ProcSection = "proc" ParamList ";" { [ ConstDecl ";" TypeDecl ";" VarDecl ] } ";" .
  56. Statements = [ Statement { ";" [ Statement ] } ] .
  57. IfStatement = "if" Expr "then" Statement { "else" Statement } .
  58. Statement = [ pnumber ":" ]
  59. ( IfStatement
  60. | CaseStmt
  61. | WhileStmt
  62. | RepeatStmt
  63. | ForStmt
  64. | "goto" Label
  65. | ident IdentTail
  66. | ReturnStmt
  67. | Compound
  68. | ProcDecl ) . (* Nested procedure *)
  69. CaseStmt = "case" Expr "of" [ CaseItem { ";" [ CaseItem ] } ] "end" .
  70. CaseItem = LabelList ":" Statement .
  71. LabelList = Label { "," Label } .
  72. Label = pnumber | ident .
  73. WhileStmt = "while" Expr "do" Statement .
  74. RepeatStmt = "repeat" Statements "until" Expr .
  75. ForStmt = "for" ident ":=" Expr ( "to" | "downto" ) Expr "do" Statement .
  76. IdentTail = [ Selector { Selector } ] [ ":=" Expr | "(" [ ParamList ] ")" ] .
  77. Selector = "." ident | "[" Expr { "," Expr } "]" | "^" .
  78. ParamList = Param { "," Param } .
  79. Param = Expr .
  80. ReturnStmt = "return" [ Expr ] .
  81. Expr = SimpleExpr [ Relationship SimpleExpr ] .
  82. Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  83. SimpleExpr = ["+" | "-"] Term { ("+" | "-" | "or") Term } .
  84. Term = Factor { ("*" | "/" | "div" | "mod" | "&" | "and") Factor } .
  85. Factor = ["+" | "-"] ["not"] Primary .
  86. Primary = pnumber | preal | pstring | "(" Expr ")" | ident { Selector } [ "(" [ ParamList ] ")" ] .
  87. END P6.