Coco/R - Compiler-Compiler V1.53 Released by Pat Terry 17 September 2002 Source file: free_pascal.atg Listing: 1 (* Free Pascal ATG for Coco/R *) 2 (* Adapted from the standard Pascal grammar *) 3 4 (* Tags: FREEPASCAL, FP, FPC, DELPHI *) 5 6 COMPILER FreePascal 7 8 CHARACTERS 9 eol = CHR(13) . 10 letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" . 11 digit = "0123456789" . 12 IGNORE CHR(9) .. CHR(13) 13 COMMENTS FROM "(*" TO "*)" NESTED 14 15 TOKENS 16 ident = letter { letter | digit } . 17 18 PRODUCTIONS 19 20 Program = "program" ident ";" Block "." . 21 22 Block = [ UnitSection ] DeclPart Statements . 23 24 UnitSection = "unit" ident ";" ImpSection ";" "end" ident "." . 25 26 ImpSection = "implementation" [ ImpItems ] . 27 28 ImpItems = ident { ";" ident } . 29 30 DeclPart = [ ConstDecl ] [ TypeDecl ] [ VarDecl ] [ LabelDecl ] [ ProcDecl ]. 31 32 ConstDecl = "const" ConstSection . 33 34 ConstSection = ConstDeclList { ";" ConstDeclList } . 35 36 ConstDeclList = ident "=" Value { ";" ident "=" Value } . 37 38 Value = number | ident | string . 39 40 TypeDecl = "type" TypeSection . 41 42 TypeSection = TypeDef { ";" TypeDef } . 43 44 TypeDef = ident "=" Type . 45 46 VarDecl = "var" VarSection . 47 48 VarSection = VarDeclList { ";" VarDeclList } . 49 50 VarDeclList = identlist ":" Type . 51 52 identlist = ident { "," ident } . 53 54 Type = SimpleType | StructType | PointerType | ArrayType | SetType | FileOfType | ClassType | InterfaceType . 55 56 SimpleType = IntType | RealType | CharType | BoolType . 57 58 IntType = "integer" . 59 RealType = "real" . 60 CharType = "char" . 61 BoolType = "boolean" . 62 63 StructType = ArrayType | RecordType | SetType | FileOfType | ClassType | InterfaceType . 64 65 ArrayType = "array" "[" IndexList "]" "of" Type . 66 67 IndexList = Type { "," Type } . 68 69 RecordType = "record" FieldList "end" . 70 71 FieldList = Field { ";" Field } . 72 73 Field = FieldListPart ":" Type . 74 75 FieldListPart = ident { "." ident } { "." ident } . 76 77 SetType = "set" "of" Type . 78 79 FileOfType = "file" of Type . 80 81 ClassType = "class" [ Ident ] . 82 83 InterfaceType = "interface" [ Ident ] . 84 85 ProcDecl = "procedure" ident [ ParDeclList ] ";" { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" . ***** ^ invalid Factor ***** ^ invalid Factor ***** ^ invalid Factor 86 87 FuncDecl = "function" ident [ ParDeclList ] ":" Type { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" . ***** ^ invalid Factor ***** ^ invalid Factor ***** ^ invalid Factor 88 89 Statements = Statement { ";" Statement } . 90 91 Statement = IfStmt 92 | CaseStmt 93 | WhileStmt 94 | RepeatStmt 95 | ForStmt 96 | AssignedStmt 97 | ProcCall 98 | RetStmt 99 | WithStmt 100 | GotoStmt 101 | WithInlineAsm ; ***** ^ invalid Factor 102 103 IfStmt = "if" Expr "then" Stmts { "else" Stmts } . ***** ^ invalid Factor 104 105 CaseStmt = "case" Expr of { CaseItem ";" } "end" . 106 107 CaseItem = Labels ":" Stmts . 108 109 Labels = Label { "," Label } . 110 111 Label = number . 112 113 WhileStmt = "while" Expr "do" Stmts . 114 115 RepeatStmt = "repeat" Stmts "until" Expr . 116 117 ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts 118 | "for" ident ":=" Expr "downto" Expr "do" Stmts . 119 120 AssignedStmt = Var ":=" Expr . 121 122 ProcCall = ident "(" [ ParamList ] ")" . 123 124 ParamList = Param { "," Param } . 125 126 Param = Expr . 127 128 RetStmt = "return" [ Expr ] . 129 130 WithStmt = "with" Var { "," Var } "do" Stmts . 131 132 GotoStmt = "goto" ident . 133 134 WithInlineAsm = "asm" AssemBlock "end" . 135 136 AssemBlock = { AsmLine } . 137 138 AsmLine = /[a-zA-Z0-9\s]+/ . 139 140 Expr = SimpleExpr [ Relationship SimpleExpr ] . 141 142 Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" . 143 144 SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } . 145 146 Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } . 147 148 Factor = ["+" | "-"] ["not"] Primary . 149 150 Primary = number | ident | string | "(" Expr ")" | Primary "^" . 151 152 number = digit { digit } . 153 154 ident = letter { letter | digit } . 155 156 string = "'" { noQuote1 | "''" } "'" . 157 158 EndProgram = "." . 8 errors