home *** CD-ROM | disk | FTP | other *** search
-
- unit YaccLib;
- (* V1.1 9-29-88 AG; to be loaded with parsers generated by Yacc
- V2.0 2-25-89, 5-27-89 11-22-89 AG *)
-
- interface
-
- type YYSTYPE = integer;
- (* default type used for semantic attributes; may be redefined
- to fit the target application
- note: if you use the %union definition in your Yacc specification
- Yacc will put a redefinition of YYSTYPE in the generated header
- file *)
- const yymaxdepth = 1024;
- (* size (number of stack positions) allocated for parser stack;
- may be redefined (size actually needed for the stack is
- yymaxdepth*(sizeOf(integer)+sizeOf(yystype)));
- note that right recursive grammar rules in the Yacc specification
- may increase stack space requirements *)
- procedure yymsg(msg : string);
- (* default message print routine for yyparse; prints msg on standard
- output (currently, possible values for msg are `syntax error' and
- `yyparse: stack overflow'); may be redefined
- IMPORTANT: This routine replaces the UNIX Yacc `yyerror' routine
- since the name `yyerror' is used for the error simulation routine
- discussed below (which is implemented as the macro YYERROR in UNIX
- Yacc). *)
- procedure yydebugmsg(s : integer; act : string; x : integer);
- (* debug message printing routine for yyparse; this routine is
- only needed if a parser is compiled with `/Dyydebug'.
- s denotes a parser state, act a parser action, and x can either
- be <0 (undefined) or denotes a state, a grammar rule or an input
- token, depending on act.
- The default version prints a message of the form
- [s] act x
- on standard output (x is omitted if <0). yydebugmsg may be redefined,
- e.g. to give more informative messages, write to a window, etc. *)
-
- (* the following variables and procedures are not declared in the Yacc
- library, but directly in the Yacc output file:
- var yychar : integer;
- { current lookahead token for yyparse; may be useful in actions
- (especially user-supplied error recovery routines); if value is
- `any' (code 257), no lookahead symbol is present and next symbol
- is obtained via yylex }
- var yynerrs : integer;
- { current error count; incremented by yyparse after each call to yymsg }
- var yylval : yystype;
- { value associated with current lookahead token (set by yylex)
- note: declared in the header file }
- procedure yyerror;
- { simulates syntax error (syntactic error recovery is started, as if
- the next input symbol was illegal) }
- procedure yyerrok;
- { force the parser to believe that an error has fully been recovered from }
- procedure yyaccept;
- { simulates accept action of the parser; yyparse accepts and returns 0 }
- procedure yyabort;
- { simulates abort action of the parser; yyparse aborts the parse and
- returns 1 }
- procedure yyclearin;
- { deletes the current lookahead token }
- *)
-
- implementation
- procedure yymsg(msg : string);
- begin
- writeln(msg);
- end(*yymsg*);
- procedure yydebugmsg(s : integer; act : string; x : integer);
- begin
- write('[', s, '] ', act);
- if x>=0 then
- writeln(' ', x)
- else
- writeln
- end(*yydebugmsg*);
- end(*YaccLib*).