| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- (* 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 = "." .
|