p2_pascal.atg 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. (* P2 Pascal ATG for Coco/R *)
  2. (* Wirth/Ammann Pascal-P2 (1972-73), as implemented by pcom *)
  3. (* Uppercase only (CDC charset); probed against pcom, never fpc *)
  4. (* Tags: P2, PASCALP2, WIRTH *)
  5. COMPILER P2
  6. CHARACTERS
  7. eol = CHR(13) .
  8. letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" .
  9. digit = "0123456789" .
  10. noQuote1 = ANY - "'" - eol .
  11. IGNORE CHR(9) .. CHR(13)
  12. COMMENTS FROM "(*" TO "*)"
  13. TOKENS
  14. ident = letter { letter | digit } .
  15. pnumber = digit { digit } | digit { digit } CONTEXT ( ".." ) .
  16. preal = digit { digit } "." digit { digit } [ "E" [ "+" | "-" ] digit { digit } ] .
  17. pstring = "'" { noQuote1 | "''" } "'" .
  18. PRODUCTIONS
  19. P2 = "PROGRAM" ident [ "(" ident { "," ident } ")" ] ";" Block "." .
  20. Block = DeclPart [ Compound ] .
  21. Compound = "BEGIN" Statements "END" .
  22. DeclPart = { LabelSection | ConstSection | TypeSection | VarSection | ProcDecl } .
  23. LabelSection = "LABEL" Label { "," Label } ";" .
  24. ConstSection = "CONST" [ ConstDecl { ";" [ ConstDecl ] } ] .
  25. ConstDecl = ident "=" Value .
  26. Value = [ "+" | "-" ] ( pnumber | preal | pstring | ident ) .
  27. TypeSection = "TYPE" [ TypeDecl { ";" [ TypeDecl ] } ] .
  28. TypeDecl = ident "=" Type .
  29. VarSection = "VAR" [ VarDecl { ";" [ VarDecl ] } ] .
  30. VarDecl = identlist ":" Type .
  31. ProcDecl = ( "PROCEDURE" | "FUNCTION" ) ident [ FormalParams ] [ ":" Type ] ";" ( "FORWARD" | Block ) ";" .
  32. FormalParams = "(" [ FormalGroup { ";" FormalGroup } ] ")" .
  33. FormalGroup = [ "VAR" ] identlist ":" Type
  34. | ( "PROCEDURE" | "FUNCTION" ) ident [ FormalParams ] [ ":" Type ] .
  35. identlist = ident { "," ident } .
  36. Type = SimpleType | StructType | PointerType | EnumType | TypeIdent .
  37. EnumType = "(" ident { "," ident } ")" .
  38. TypeIdent = ident [ ".." ( ident | [ "-" ] pnumber ) ] | [ "-" ] pnumber [ ".." ( ident | [ "-" ] pnumber ) ] .
  39. PointerType = "^" Type .
  40. SimpleType = integertype | realtype | charType | booleanType .
  41. integertype = "INTEGER" .
  42. realtype = "REAL" .
  43. charType = "CHAR" .
  44. booleanType = "BOOLEAN" .
  45. StructType = [ "PACKED" ] ( ArrayType | RecordType ) | SetType .
  46. ArrayType = "ARRAY" "[" Bound { "," Bound } "]" "OF" Type .
  47. Bound = SimpleType | Expr [ ".." Expr ] .
  48. RecordType = "RECORD" FieldList "END" .
  49. FieldList = [ Field { ";" [ Field ] } ] .
  50. Field = FieldListPart ":" Type | VariantPart .
  51. FieldListPart = ident { "," ident } .
  52. VariantPart = "CASE" Type ":" Type "OF" [ Variant { ";" [ Variant ] } ] .
  53. Variant = LabelList ":" "(" FieldList ")" .
  54. SetType = "SET" "OF" Type .
  55. Statements = [ Statement { ";" [ Statement ] } ] .
  56. IfStatement = "IF" Expr "THEN" Statement { "ELSE" Statement } .
  57. Statement = [ pnumber ":" ]
  58. ( IfStatement
  59. | CaseStmt
  60. | WhileStmt
  61. | RepeatStmt
  62. | ForStmt
  63. | GotoStmt
  64. | WithStmt
  65. | StdProcCall
  66. | ident IdentTail
  67. | Compound
  68. | ProcDecl ) .
  69. StdProcCall = StdProc "(" [ ParamList ] ")" .
  70. StdProc = "GET" | "PUT" | "RESET" | "REWRITE" | "READ" | "WRITE"
  71. | "PACK" | "UNPACK" | "NEW" | "RELEASE" | "READLN" | "WRITELN" | "MARK" .
  72. CaseStmt = "CASE" Expr "OF" [ CaseItem { ";" [ CaseItem ] } ] "END" .
  73. CaseItem = CaseLabelList ":" Statement .
  74. CaseLabelList = CaseLabel { "," CaseLabel } .
  75. CaseLabel = pnumber | ident | pstring .
  76. LabelList = Label { "," Label } .
  77. Label = pnumber .
  78. WhileStmt = "WHILE" Expr "DO" Statement .
  79. RepeatStmt = "REPEAT" Statements "UNTIL" Expr .
  80. ForStmt = "FOR" ident ":=" Expr ( "TO" | "DOWNTO" ) Expr "DO" Statement .
  81. IdentTail = [ Selector { Selector } ] [ ":=" Expr | "(" [ ParamList ] ")" ] .
  82. Selector = "." ident | "[" Expr { "," Expr } "]" | "^" .
  83. ParamList = Param { "," Param } .
  84. Param = Expr [ ":" Expr [ ":" Expr ] ] .
  85. WithStmt = "WITH" WithItem { "," WithItem } "DO" Statement .
  86. WithItem = ident .
  87. GotoStmt = "GOTO" Label .
  88. Expr = SimpleExpr [ ( Relationship | "IN" ) SimpleExpr ] .
  89. Relationship = "=" | "<" | ">" | "<=" | ">=" | "<>" .
  90. SimpleExpr = ["+" | "-"] Term { ("+" | "-" | "OR") Term } .
  91. Term = Factor { ("*" | "/" | "DIV" | "MOD" | "AND") Factor } .
  92. Factor = ["+" | "-"] ["NOT"] Primary .
  93. Primary = pnumber | preal | pstring | "NIL" | StdFuncCall | "(" Expr ")" | ident { Selector } [ "(" [ ParamList ] ")" ] .
  94. StdFuncCall = StdFunc "(" [ ParamList ] ")" .
  95. StdFunc = "ABS" | "SQR" | "TRUNC" | "ODD" | "ORD" | "CHR"
  96. | "PRED" | "SUCC" | "EOF" | "EOLN" | "SIN" | "COS" | "EXP" | "SQRT" | "LN" | "ARCTAN" .
  97. END P2.