| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- (* Pascal-S ATG for Coco/R *)
- (* Wirth Pascal-S (1976), as implemented by PascalS0 (Turbo batch) *)
- (* Lowercase ok (Turbo scanner); probed against psc, never fpc *)
- (* Tags: PASCALS, WIRTH *)
- COMPILER PascalS
- IGNORE CASE
- CHARACTERS
- eol = CHR(13) .
- letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" .
- digit = "0123456789" .
- noQuote1 = ANY - "'" - eol .
- IGNORE CHR(9) .. CHR(13)
- COMMENTS FROM "(*" TO "*)"
- COMMENTS FROM "{" TO "}"
- TOKENS
- ident = letter { letter | digit } .
- pnumber = digit { digit } | digit { digit } CONTEXT ( ".." ) .
- preal = digit { digit } "." digit { digit } [ "E" [ "+" | "-" ] digit { digit } ] .
- pstring = "'" { noQuote1 | "''" } "'" .
- PRODUCTIONS
- PascalS = "program" ident "(" ident { "," ident } ")" ";" Block "." .
- Block = DeclPart [ Compound ] .
- Compound = "begin" Statements "end" .
- DeclPart = { ConstSection | TypeSection | VarSection | ProcDecl } .
- ConstSection = "const" [ ConstDecl { ";" [ ConstDecl ] } ] .
- ConstDecl = ident "=" Value .
- Value = [ "+" | "-" ] ( pnumber | preal | pstring | ident ) .
- TypeSection = "type" [ TypeDecl { ";" [ TypeDecl ] } ] .
- TypeDecl = ident "=" Type .
- VarSection = "var" [ VarDecl { ";" [ VarDecl ] } ] .
- VarDecl = identlist ":" Type .
- ProcDecl = ( "procedure" | "function" ) ident [ FormalParams ] [ ":" Type ] ";" Block ";" .
- FormalParams = "(" [ FormalGroup { ";" FormalGroup } ] ")" .
- FormalGroup = [ "var" ] identlist ":" Type .
- identlist = ident { "," ident } .
- Type = SimpleType | StructType | TypeIdent .
- TypeIdent = ident .
- SimpleType = integertype | realtype | chartype | booleantype .
- integertype = "integer" .
- realtype = "real" .
- chartype = "char" .
- booleantype = "boolean" .
- StructType = ArrayType | RecordType .
- ArrayType = "array" "[" Bound { "," Bound } "]" "of" Type .
- Bound = SimpleType | Value [ ".." Value ] .
- RecordType = "record" FieldList "end" .
- FieldList = [ Field { ";" [ Field ] } ] .
- Field = identlist ":" Type .
- Statements = [ Statement { ";" [ Statement ] } ] .
- IfStatement = "if" Expr "then" Statement { "else" Statement } .
- Statement = IfStatement
- | CaseStmt
- | WhileStmt
- | RepeatStmt
- | ForStmt
- | ident IdentTail
- | Compound
- | ProcDecl .
- CaseStmt = "case" Expr "of" [ CaseItem { ";" [ CaseItem ] } ] "end" .
- CaseItem = CaseLabelList ":" Statement .
- CaseLabelList = CaseLabel { "," CaseLabel } .
- CaseLabel = pnumber | ident | pstring .
- WhileStmt = "while" Expr "do" Statement .
- RepeatStmt = "repeat" Statements "until" Expr .
- ForStmt = "for" ident ":=" Expr ( "to" | "downto" ) Expr "do" Statement .
- IdentTail = [ Selector { Selector } ] [ ":=" Expr | "(" [ ParamList ] ")" ] .
- Selector = "." ident | "[" Expr { "," Expr } "]" .
- ParamList = Param { "," Param } .
- Param = Expr [ ":" Expr [ ":" Expr ] ] .
- Expr = SimpleExpr [ Relationship SimpleExpr ] .
- Relationship = "=" | "<" | ">" | "<=" | ">=" | "<>" .
- SimpleExpr = ["+" | "-"] Term { ("+" | "-" | "or") Term } .
- Term = Factor { ("*" | "/" | "div" | "mod" | "and") Factor } .
- Factor = ["not"] Primary .
- Primary = pnumber | preal | pstring | EofCall | "(" Expr ")" | ident { Selector } [ "(" [ ParamList ] ")" ] .
- EofCall = ( "eof" | "eoln" ) "(" ident ")" .
- END PascalS.
|