pascals.atg 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. (* Pascal-S ATG for Coco/R *)
  2. (* Wirth Pascal-S (1976), as implemented by PascalS0 (Turbo batch) *)
  3. (* Lowercase ok (Turbo scanner); probed against psc, never fpc *)
  4. (* Tags: PASCALS, WIRTH *)
  5. COMPILER PascalS
  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 "*)"
  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. PascalS = "program" ident "(" ident { "," ident } ")" ";" Block "." .
  22. Block = DeclPart [ Compound ] .
  23. Compound = "begin" Statements "end" .
  24. DeclPart = { ConstSection | TypeSection | VarSection | ProcDecl } .
  25. ConstSection = "const" [ ConstDecl { ";" [ ConstDecl ] } ] .
  26. ConstDecl = ident "=" Value .
  27. Value = [ "+" | "-" ] ( pnumber | preal | pstring | ident ) .
  28. TypeSection = "type" [ TypeDecl { ";" [ TypeDecl ] } ] .
  29. TypeDecl = ident "=" Type .
  30. VarSection = "var" [ VarDecl { ";" [ VarDecl ] } ] .
  31. VarDecl = identlist ":" Type .
  32. ProcDecl = ( "procedure" | "function" ) ident [ FormalParams ] [ ":" Type ] ";" Block ";" .
  33. FormalParams = "(" [ FormalGroup { ";" FormalGroup } ] ")" .
  34. FormalGroup = [ "var" ] identlist ":" Type .
  35. identlist = ident { "," ident } .
  36. Type = SimpleType | StructType | TypeIdent .
  37. TypeIdent = ident .
  38. SimpleType = integertype | realtype | chartype | booleantype .
  39. integertype = "integer" .
  40. realtype = "real" .
  41. chartype = "char" .
  42. booleantype = "boolean" .
  43. StructType = ArrayType | RecordType .
  44. ArrayType = "array" "[" Bound { "," Bound } "]" "of" Type .
  45. Bound = SimpleType | Value [ ".." Value ] .
  46. RecordType = "record" FieldList "end" .
  47. FieldList = [ Field { ";" [ Field ] } ] .
  48. Field = identlist ":" Type .
  49. Statements = [ Statement { ";" [ Statement ] } ] .
  50. IfStatement = "if" Expr "then" Statement { "else" Statement } .
  51. Statement = IfStatement
  52. | CaseStmt
  53. | WhileStmt
  54. | RepeatStmt
  55. | ForStmt
  56. | ident IdentTail
  57. | Compound
  58. | ProcDecl .
  59. CaseStmt = "case" Expr "of" [ CaseItem { ";" [ CaseItem ] } ] "end" .
  60. CaseItem = CaseLabelList ":" Statement .
  61. CaseLabelList = CaseLabel { "," CaseLabel } .
  62. CaseLabel = pnumber | ident | pstring .
  63. WhileStmt = "while" Expr "do" Statement .
  64. RepeatStmt = "repeat" Statements "until" Expr .
  65. ForStmt = "for" ident ":=" Expr ( "to" | "downto" ) Expr "do" Statement .
  66. IdentTail = [ Selector { Selector } ] [ ":=" Expr | "(" [ ParamList ] ")" ] .
  67. Selector = "." ident | "[" Expr { "," Expr } "]" .
  68. ParamList = Param { "," Param } .
  69. Param = Expr [ ":" Expr [ ":" Expr ] ] .
  70. Expr = SimpleExpr [ Relationship SimpleExpr ] .
  71. Relationship = "=" | "<" | ">" | "<=" | ">=" | "<>" .
  72. SimpleExpr = ["+" | "-"] Term { ("+" | "-" | "or") Term } .
  73. Term = Factor { ("*" | "/" | "div" | "mod" | "and") Factor } .
  74. Factor = ["not"] Primary .
  75. Primary = pnumber | preal | pstring | EofCall | "(" Expr ")" | ident { Selector } [ "(" [ ParamList ] ")" ] .
  76. EofCall = ( "eof" | "eoln" ) "(" ident ")" .
  77. END PascalS.