free_pascal.atg 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. (* Free Pascal ATG for Coco/R *)
  2. (* Adapted from the standard Pascal grammar *)
  3. (* Tags: FREEPASCAL, FP, FPC, DELPHI *)
  4. COMPILER FreePascal
  5. CHARACTERS
  6. eol = CHR(13) .
  7. letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
  8. digit = "0123456789" .
  9. IGNORE CHR(9) .. CHR(13)
  10. COMMENTS FROM "(*" TO "*)" NESTED
  11. TOKENS
  12. ident = letter { letter | digit } .
  13. PRODUCTIONS
  14. Program = "program" ident ";" Block "." .
  15. Block = [ UnitSection ] DeclPart Statements .
  16. UnitSection = "unit" ident ";" ImpSection ";" "end" ident "." .
  17. ImpSection = "implementation" [ ImpItems ] .
  18. ImpItems = ident { ";" ident } .
  19. DeclPart = [ ConstDecl ] [ TypeDecl ] [ VarDecl ] [ LabelDecl ] [ ProcDecl ].
  20. ConstDecl = "const" ConstSection .
  21. ConstSection = ConstDeclList { ";" ConstDeclList } .
  22. ConstDeclList = ident "=" Value { ";" ident "=" Value } .
  23. Value = number | ident | string .
  24. TypeDecl = "type" TypeSection .
  25. TypeSection = TypeDef { ";" TypeDef } .
  26. TypeDef = ident "=" Type .
  27. VarDecl = "var" VarSection .
  28. VarSection = VarDeclList { ";" VarDeclList } .
  29. VarDeclList = identlist ":" Type .
  30. identlist = ident { "," ident } .
  31. Type = SimpleType | StructType | PointerType | ArrayType | SetType | FileOfType | ClassType | InterfaceType .
  32. SimpleType = IntType | RealType | CharType | BoolType .
  33. IntType = "integer" .
  34. RealType = "real" .
  35. CharType = "char" .
  36. BoolType = "boolean" .
  37. StructType = ArrayType | RecordType | SetType | FileOfType | ClassType | InterfaceType .
  38. ArrayType = "array" "[" IndexList "]" "of" Type .
  39. IndexList = Type { "," Type } .
  40. RecordType = "record" FieldList "end" .
  41. FieldList = Field { ";" Field } .
  42. Field = FieldListPart ":" Type .
  43. FieldListPart = ident { "." ident } { "." ident } .
  44. SetType = "set" "of" Type .
  45. FileOfType = "file" of Type .
  46. ClassType = "class" [ Ident ] .
  47. InterfaceType = "interface" [ Ident ] .
  48. ProcDecl = "procedure" ident [ ParDeclList ] ";" { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" .
  49. FuncDecl = "function" ident [ ParDeclList ] ":" Type { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" .
  50. Statements = Statement { ";" Statement } .
  51. Statement = IfStmt
  52. | CaseStmt
  53. | WhileStmt
  54. | RepeatStmt
  55. | ForStmt
  56. | AssignedStmt
  57. | ProcCall
  58. | RetStmt
  59. | WithStmt
  60. | GotoStmt
  61. | WithInlineAsm ;
  62. IfStmt = "if" Expr "then" Stmts { "else" Stmts } .
  63. CaseStmt = "case" Expr of { CaseItem ";" } "end" .
  64. CaseItem = Labels ":" Stmts .
  65. Labels = Label { "," Label } .
  66. Label = number .
  67. WhileStmt = "while" Expr "do" Stmts .
  68. RepeatStmt = "repeat" Stmts "until" Expr .
  69. ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts
  70. | "for" ident ":=" Expr "downto" Expr "do" Stmts .
  71. AssignedStmt = Var ":=" Expr .
  72. ProcCall = ident "(" [ ParamList ] ")" .
  73. ParamList = Param { "," Param } .
  74. Param = Expr .
  75. RetStmt = "return" [ Expr ] .
  76. WithStmt = "with" Var { "," Var } "do" Stmts .
  77. GotoStmt = "goto" ident .
  78. WithInlineAsm = "asm" AssemBlock "end" .
  79. AssemBlock = { AsmLine } .
  80. AsmLine = /[a-zA-Z0-9\s]+/ .
  81. Expr = SimpleExpr [ Relationship SimpleExpr ] .
  82. Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" .
  83. SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } .
  84. Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } .
  85. Factor = ["+" | "-"] ["not"] Primary .
  86. Primary = number | ident | string | "(" Expr ")" | Primary "^" .
  87. number = digit { digit } .
  88. ident = letter { letter | digit } .
  89. string = "'" { noQuote1 | "''" } "'" .
  90. EndProgram = "." .