p6_pascal.atg 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. (* Pascal P6 ATG for Coco/R *)
  2. (* Pascal-6 (1980) - N. Wirth's sixth Pascal implementation *)
  3. (* Features: Parameterized types (generics), additional control structures *)
  4. (* Tags: P6, PASCAL6, WIRTH *)
  5. COMPILER PascalP6
  6. CHARACTERS
  7. eol = CHR(13) .
  8. letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  9. digit = "0123456789" .
  10. IGNORE CHR(9) .. CHR(13)
  11. COMMENTS FROM "(*" TO "*)" NESTED
  12. TOKENS
  13. ident = letter { letter | digit } .
  14. PRODUCTIONS
  15. Program = "program" ident ";" Block "." .
  16. Block = [ UnitSection ] DeclPart Statements .
  17. UnitSection = "unit" ident ";" { FileSection } "end" ident "." .
  18. FileSection = ident { ";" ident } .
  19. DeclPart = [ ConstSection ] [ TypeSection ] [ VarSection ] [ ProcDecl ].
  20. ConstSection = "const" ConstDeclList { ";" ConstDeclList } .
  21. ConstDeclList = ident "=" Value { ";" ident "=" Value } .
  22. TypeSection = "type" TypeDeclList { ";" TypeDeclList } .
  23. TypeDeclList = ident "=" Type { ";" ident "=" Type } .
  24. VarSection = "var" VarDeclList { ";" VarDeclList } .
  25. VarDeclList = identlist ":" Type .
  26. identlist = ident { "," ident } .
  27. Type = SimpleType | StructType | PointerType | ArrayType | SetType | EnumType | ParamType .
  28. SimpleType = integertype | realtype | charType | booleanType .
  29. integertype = "integer" .
  30. realtype = "real" .
  31. charType = "char" .
  32. booleanType = "boolean" .
  33. StructType = ArrayType | RecordType | SetType | EnumType .
  34. ArrayType = "array" "[" IndexList "]" "of" Type .
  35. IndexList = SimpleType { "," SimpleType } .
  36. RecordType = "record" FieldList "end" .
  37. FieldList = Field { ";" Field } .
  38. Field = identlist ":" Type .
  39. SetType = "set" "of" Type .
  40. EnumType = "(" ident { "," ident } ")" .
  41. ParamType = "array" "[" ParamList "]" "of" Type . (* Parameterized type *)
  42. ProcSection = "proc" ParamList ";" { [ ConstDecl ; TypeDecl ; VarDecl ] } ";" .
  43. Statements = Statement { ";" Statement } .
  44. Statement = IfStatement
  45. | CaseStatement
  46. | WhileStatement
  47. | RepeatStatement
  48. | ForStatement
  49. | Assignment
  50. | ProcCall
  51. | ReturnStatement
  52. | EmptyStatement
  53. | ProcDecl ; (* Nested procedure *)
  54. IfStatement = "if" Expr "then" Stmts { "else" Stmts } .
  55. CaseStmt = "case" Expr of { CaseItem ";" } "end" .
  56. CaseItem = LabelList ":" Stmts .
  57. LabelList = Label { "," Label } .
  58. Label = number .
  59. WhileStmt = "while" Expr "do" Stmts .
  60. RepeatStmt = "repeat" Stmts "until" Expr .
  61. ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts
  62. | "for" ident ":=" Expr "downto" Expr "do" Stmts .
  63. Assignment = Var ":=" Expr .
  64. ProcCall = ident "(" [ ParamList ] ")" .
  65. ParamList = Param { "," Param } .
  66. Param = Expr .
  67. ReturnStmt = "return" [ Expr ] .
  68. EmptyStatement = "" .
  69. Expr = SimpleExpr [ Relationship SimpleExpr ] .
  70. Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  71. SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } .
  72. Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } .
  73. Factor = ["+" | "-"] ["not"] Primary .
  74. Primary = number | ident | string | "(" Expr ")" | Primary "^" .
  75. number = digit { digit } .
  76. ident = letter { letter | digit } .
  77. string = "'" { noQuote1 | "''" } "'" .
  78. EndProgram = "." .
  79. EOF