p4_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 P4
  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. P4 = "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 | EnumType | TypeIdent .
  40. EnumType = "(" ident { "," ident } ")" .
  41. TypeIdent = ident { "." ident } [ ".." ( ident | [ "-" ] pnumber ) ] | [ "-" ] pnumber [ ".." ( ident | [ "-" ] pnumber ) ] .
  42. PointerType = "^" Type .
  43. SimpleType = integertype | realtype | charType | booleanType .
  44. integertype = "integer" .
  45. realtype = "real" .
  46. charType = "char" .
  47. booleanType = "boolean" .
  48. StructType = ArrayType | RecordType | SetType | ProcType .
  49. ArrayType = "array" "[" IndexList "]" "of" Type .
  50. IndexList = Index { "," Index } .
  51. Index = SimpleType | Value [ ".." Value ] .
  52. RecordType = "record" FieldList "end" .
  53. FieldList = [ Field { ";" [ Field ] } ] .
  54. Field = identlist ":" Type .
  55. SetType = "set" "of" Type .
  56. ProcType = "procedure" ParamList ";" { [ ConstDecl ";" TypeDecl ";" VarDecl ";" ProcDecl ] } ";" .
  57. Statements = [ Statement { ";" [ Statement ] } ] .
  58. IfStatement = "if" Expr "then" Statement { "else" Statement } .
  59. Statement = [ pnumber ":" ]
  60. ( IfStatement
  61. | CaseStmt
  62. | WhileStmt
  63. | RepeatStmt
  64. | ForStmt
  65. | "goto" Label
  66. | ident IdentTail
  67. | ReturnStmt
  68. | Compound
  69. | ProcDecl ) . (* Nested procedure *)
  70. CaseStmt = "case" Expr "of" [ CaseItem { ";" [ CaseItem ] } ] "end" .
  71. CaseItem = LabelList ":" Statement .
  72. LabelList = Label { "," Label } .
  73. Label = pnumber | ident .
  74. WhileStmt = "while" Expr "do" Statement .
  75. RepeatStmt = "repeat" Statements "until" Expr .
  76. ForStmt = "for" ident ":=" Expr ( "to" | "downto" ) Expr "do" Statement .
  77. IdentTail = [ Selector { Selector } ] [ ":=" Expr | "(" [ ParamList ] ")" ] .
  78. Selector = "." ident | "[" Expr { "," Expr } "]" | "^" .
  79. ParamList = Param { "," Param } .
  80. Param = Expr .
  81. ReturnStmt = "return" [ Expr ] .
  82. Expr = SimpleExpr [ Relationship SimpleExpr ] .
  83. Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  84. SimpleExpr = ["+" | "-"] Term { ("+" | "-" | "or") Term } .
  85. Term = Factor { ("*" | "/" | "div" | "mod" | "&" | "and") Factor } .
  86. Factor = ["+" | "-"] ["not"] Primary .
  87. Primary = pnumber | preal | pstring | "(" Expr ")" | ident { Selector } [ "(" [ ParamList ] ")" ] .
  88. END P4.