(* 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.