(* P2 Pascal ATG for Coco/R *) (* Wirth/Ammann Pascal-P2 (1972-73), as implemented by pcom *) (* Uppercase only (CDC charset); probed against pcom, never fpc *) (* Tags: P2, PASCALP2, WIRTH *) COMPILER P2 CHARACTERS eol = CHR(13) . letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" . digit = "0123456789" . noQuote1 = ANY - "'" - eol . IGNORE CHR(9) .. CHR(13) 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 P2 = "PROGRAM" ident [ "(" ident { "," ident } ")" ] ";" Block "." . Block = DeclPart [ Compound ] . Compound = "BEGIN" Statements "END" . DeclPart = { LabelSection | ConstSection | TypeSection | VarSection | ProcDecl } . LabelSection = "LABEL" Label { "," Label } ";" . 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 ] ";" ( "FORWARD" | Block ) ";" . FormalParams = "(" [ FormalGroup { ";" FormalGroup } ] ")" . FormalGroup = [ "VAR" ] identlist ":" Type | ( "PROCEDURE" | "FUNCTION" ) ident [ FormalParams ] [ ":" Type ] . identlist = ident { "," ident } . Type = SimpleType | StructType | PointerType | EnumType | TypeIdent . EnumType = "(" ident { "," ident } ")" . TypeIdent = ident [ ".." ( ident | [ "-" ] pnumber ) ] | [ "-" ] pnumber [ ".." ( ident | [ "-" ] pnumber ) ] . PointerType = "^" Type . SimpleType = integertype | realtype | charType | booleanType . integertype = "INTEGER" . realtype = "REAL" . charType = "CHAR" . booleanType = "BOOLEAN" . StructType = [ "PACKED" ] ( ArrayType | RecordType ) | SetType . ArrayType = "ARRAY" "[" Bound { "," Bound } "]" "OF" Type . Bound = SimpleType | Expr [ ".." Expr ] . RecordType = "RECORD" FieldList "END" . FieldList = [ Field { ";" [ Field ] } ] . Field = FieldListPart ":" Type | VariantPart . FieldListPart = ident { "," ident } . VariantPart = "CASE" Type ":" Type "OF" [ Variant { ";" [ Variant ] } ] . Variant = LabelList ":" "(" FieldList ")" . SetType = "SET" "OF" Type . Statements = [ Statement { ";" [ Statement ] } ] . IfStatement = "IF" Expr "THEN" Statement { "ELSE" Statement } . Statement = [ pnumber ":" ] ( IfStatement | CaseStmt | WhileStmt | RepeatStmt | ForStmt | GotoStmt | WithStmt | StdProcCall | ident IdentTail | Compound | ProcDecl ) . StdProcCall = StdProc "(" [ ParamList ] ")" . StdProc = "GET" | "PUT" | "RESET" | "REWRITE" | "READ" | "WRITE" | "PACK" | "UNPACK" | "NEW" | "RELEASE" | "READLN" | "WRITELN" | "MARK" . CaseStmt = "CASE" Expr "OF" [ CaseItem { ";" [ CaseItem ] } ] "END" . CaseItem = CaseLabelList ":" Statement . CaseLabelList = CaseLabel { "," CaseLabel } . CaseLabel = pnumber | ident | pstring . LabelList = Label { "," Label } . Label = pnumber . 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 ] ] . WithStmt = "WITH" WithItem { "," WithItem } "DO" Statement . WithItem = ident . GotoStmt = "GOTO" Label . Expr = SimpleExpr [ ( Relationship | "IN" ) SimpleExpr ] . Relationship = "=" | "<" | ">" | "<=" | ">=" | "<>" . SimpleExpr = ["+" | "-"] Term { ("+" | "-" | "OR") Term } . Term = Factor { ("*" | "/" | "DIV" | "MOD" | "AND") Factor } . Factor = ["+" | "-"] ["NOT"] Primary . Primary = pnumber | preal | pstring | "NIL" | StdFuncCall | "(" Expr ")" | ident { Selector } [ "(" [ ParamList ] ")" ] . StdFuncCall = StdFunc "(" [ ParamList ] ")" . StdFunc = "ABS" | "SQR" | "TRUNC" | "ODD" | "ORD" | "CHR" | "PRED" | "SUCC" | "EOF" | "EOLN" | "SIN" | "COS" | "EXP" | "SQRT" | "LN" | "ARCTAN" . END P2.