p4_pascal.atg 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 PascalP4
  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 | ProcType .
  28. SimpleType = integertype | realtype | charType | booleanType .
  29. integertype = "integer" .
  30. realtype = "real" .
  31. charType = "char" .
  32. booleanType = "boolean" .
  33. StructType = ArrayType | RecordType | SetType | ProcType .
  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. ProcType = "procedure" ParList ";" { [ ConstDecl ; TypeDecl ; VarDecl ; ProcDecl ] } ";" .
  41. Statements = Statement { ";" Statement } .
  42. Statement = IfStatement
  43. | CaseStatement
  44. | WhileStatement
  45. | RepeatStatement
  46. | ForStatement
  47. | Assignment
  48. | ProcCall
  49. | ReturnStatement
  50. | EmptyStatement
  51. | ProcDecl ; (* Nested procedure *)
  52. IfStatement = "if" Expr "then" Stmts { "else" Stmts } .
  53. CaseStmt = "case" Expr of { CaseItem ";" } "end" .
  54. CaseItem = LabelList ":" Stmts .
  55. LabelList = Label { "," Label } .
  56. Label = number .
  57. WhileStmt = "while" Expr "do" Stmts .
  58. RepeatStmt = "repeat" Stmts "until" Expr .
  59. ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts
  60. | "for" ident ":=" Expr "downto" Expr "do" Stmts .
  61. Assignment = Var ":=" Expr .
  62. ProcCall = ident "(" [ ParamList ] ")" .
  63. ParamList = Param { "," Param } .
  64. Param = Expr .
  65. ReturnStmt = "return" [ Expr ] .
  66. EmptyStatement = "" .
  67. Expr = SimpleExpr [ Relationship SimpleExpr ] .
  68. Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  69. SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } .
  70. Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } .
  71. Factor = ["+" | "-"] ["not"] Primary .
  72. Primary = number | ident | string | "(" Expr ")" | Primary "^" .
  73. number = digit { digit } .
  74. ident = letter { letter | digit } .
  75. string = "'" { noQuote1 | "''" } "'" .
  76. EndProgram = "." .
  77. EOF