(* Free Pascal ATG for Coco/R *) (* Adapted from the standard Pascal grammar *) (* Tags: FREEPASCAL, FP, FPC, DELPHI *) COMPILER FreePascal CHARACTERS eol = CHR(13) . letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" . digit = "0123456789" . IGNORE CHR(9) .. CHR(13) COMMENTS FROM "(*" TO "*)" NESTED TOKENS ident = letter { letter | digit } . PRODUCTIONS Program = "program" ident ";" Block "." . Block = [ UnitSection ] DeclPart Statements . UnitSection = "unit" ident ";" ImpSection ";" "end" ident "." . ImpSection = "implementation" [ ImpItems ] . ImpItems = ident { ";" ident } . DeclPart = [ ConstDecl ] [ TypeDecl ] [ VarDecl ] [ LabelDecl ] [ ProcDecl ]. ConstDecl = "const" ConstSection . ConstSection = ConstDeclList { ";" ConstDeclList } . ConstDeclList = ident "=" Value { ";" ident "=" Value } . Value = number | ident | string . TypeDecl = "type" TypeSection . TypeSection = TypeDef { ";" TypeDef } . TypeDef = ident "=" Type . VarDecl = "var" VarSection . VarSection = VarDeclList { ";" VarDeclList } . VarDeclList = identlist ":" Type . identlist = ident { "," ident } . Type = SimpleType | StructType | PointerType | ArrayType | SetType | FileOfType | ClassType | InterfaceType . SimpleType = IntType | RealType | CharType | BoolType . IntType = "integer" . RealType = "real" . CharType = "char" . BoolType = "boolean" . StructType = ArrayType | RecordType | SetType | FileOfType | ClassType | InterfaceType . ArrayType = "array" "[" IndexList "]" "of" Type . IndexList = Type { "," Type } . RecordType = "record" FieldList "end" . FieldList = Field { ";" Field } . Field = FieldListPart ":" Type . FieldListPart = ident { "." ident } { "." ident } . SetType = "set" "of" Type . FileOfType = "file" of Type . ClassType = "class" [ Ident ] . InterfaceType = "interface" [ Ident ] . ProcDecl = "procedure" ident [ ParDeclList ] ";" { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" . FuncDecl = "function" ident [ ParDeclList ] ":" Type { ConstDecl ; TypeDecl ; VarDecl ; ProcDecl } ";" . Statements = Statement { ";" Statement } . Statement = IfStmt | CaseStmt | WhileStmt | RepeatStmt | ForStmt | AssignedStmt | ProcCall | RetStmt | WithStmt | GotoStmt | WithInlineAsm ; IfStmt = "if" Expr "then" Stmts { "else" Stmts } . CaseStmt = "case" Expr of { CaseItem ";" } "end" . CaseItem = Labels ":" Stmts . Labels = Label { "," Label } . Label = number . WhileStmt = "while" Expr "do" Stmts . RepeatStmt = "repeat" Stmts "until" Expr . ForStmt = "for" ident ":=" Expr "to" Expr "do" Stmts | "for" ident ":=" Expr "downto" Expr "do" Stmts . AssignedStmt = Var ":=" Expr . ProcCall = ident "(" [ ParamList ] ")" . ParamList = Param { "," Param } . Param = Expr . RetStmt = "return" [ Expr ] . WithStmt = "with" Var { "," Var } "do" Stmts . GotoStmt = "goto" ident . WithInlineAsm = "asm" AssemBlock "end" . AssemBlock = { AsmLine } . AsmLine = /[a-zA-Z0-9\s]+/ . Expr = SimpleExpr [ Relationship SimpleExpr ] . Relationship = "=" | "#" | "<" | ">" | "<=" | ">=" | "<>" . SimpleExpr = ["+" | "-"] Term { ("+" | "-") Term } . Term = Factor { ("*" | "/" | "div" | "mod" | "&") Factor } . Factor = ["+" | "-"] ["not"] Primary . Primary = number | ident | string | "(" Expr ")" | Primary "^" . number = digit { digit } . ident = letter { letter | digit } . string = "'" { noQuote1 | "''" } "'" . EndProgram = "." .