xref: /netbsd-src/external/bsd/elftosb/dist/elftosb2/FlexLexer.h (revision 993229b6fea628ff8b1fa09146c80b0cfb2768eb)
1*993229b6Sjkunz // -*-C++-*-
2*993229b6Sjkunz // FlexLexer.h -- define interfaces for lexical analyzer classes generated
3*993229b6Sjkunz // by flex
4*993229b6Sjkunz 
5*993229b6Sjkunz // Copyright (c) 1993 The Regents of the University of California.
6*993229b6Sjkunz // All rights reserved.
7*993229b6Sjkunz //
8*993229b6Sjkunz // This code is derived from software contributed to Berkeley by
9*993229b6Sjkunz // Kent Williams and Tom Epperly.
10*993229b6Sjkunz //
11*993229b6Sjkunz //  Redistribution and use in source and binary forms, with or without
12*993229b6Sjkunz //  modification, are permitted provided that the following conditions
13*993229b6Sjkunz //  are met:
14*993229b6Sjkunz 
15*993229b6Sjkunz //  1. Redistributions of source code must retain the above copyright
16*993229b6Sjkunz //  notice, this list of conditions and the following disclaimer.
17*993229b6Sjkunz //  2. Redistributions in binary form must reproduce the above copyright
18*993229b6Sjkunz //  notice, this list of conditions and the following disclaimer in the
19*993229b6Sjkunz //  documentation and/or other materials provided with the distribution.
20*993229b6Sjkunz 
21*993229b6Sjkunz //  Neither the name of the University nor the names of its contributors
22*993229b6Sjkunz //  may be used to endorse or promote products derived from this software
23*993229b6Sjkunz //  without specific prior written permission.
24*993229b6Sjkunz 
25*993229b6Sjkunz //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
26*993229b6Sjkunz //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
27*993229b6Sjkunz //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28*993229b6Sjkunz //  PURPOSE.
29*993229b6Sjkunz 
30*993229b6Sjkunz // This file defines FlexLexer, an abstract class which specifies the
31*993229b6Sjkunz // external interface provided to flex C++ lexer objects, and yyFlexLexer,
32*993229b6Sjkunz // which defines a particular lexer class.
33*993229b6Sjkunz //
34*993229b6Sjkunz // If you want to create multiple lexer classes, you use the -P flag
35*993229b6Sjkunz // to rename each yyFlexLexer to some other xxFlexLexer.  You then
36*993229b6Sjkunz // include <FlexLexer.h> in your other sources once per lexer class:
37*993229b6Sjkunz //
38*993229b6Sjkunz //	#undef yyFlexLexer
39*993229b6Sjkunz //	#define yyFlexLexer xxFlexLexer
40*993229b6Sjkunz //	#include <FlexLexer.h>
41*993229b6Sjkunz //
42*993229b6Sjkunz //	#undef yyFlexLexer
43*993229b6Sjkunz //	#define yyFlexLexer zzFlexLexer
44*993229b6Sjkunz //	#include <FlexLexer.h>
45*993229b6Sjkunz //	...
46*993229b6Sjkunz 
47*993229b6Sjkunz #ifndef __FLEX_LEXER_H
48*993229b6Sjkunz // Never included before - need to define base class.
49*993229b6Sjkunz #define __FLEX_LEXER_H
50*993229b6Sjkunz 
51*993229b6Sjkunz #include <iostream>
52*993229b6Sjkunz #  ifndef FLEX_STD
53*993229b6Sjkunz #    define FLEX_STD std::
54*993229b6Sjkunz #  endif
55*993229b6Sjkunz 
56*993229b6Sjkunz extern "C++" {
57*993229b6Sjkunz 
58*993229b6Sjkunz struct yy_buffer_state;
59*993229b6Sjkunz typedef int yy_state_type;
60*993229b6Sjkunz 
61*993229b6Sjkunz class FlexLexer {
62*993229b6Sjkunz public:
~FlexLexer()63*993229b6Sjkunz 	virtual ~FlexLexer()	{ }
64*993229b6Sjkunz 
YYText()65*993229b6Sjkunz 	const char* YYText() const	{ return yytext; }
YYLeng()66*993229b6Sjkunz 	int YYLeng()	const	{ return yyleng; }
67*993229b6Sjkunz 
68*993229b6Sjkunz 	virtual void
69*993229b6Sjkunz 		yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
70*993229b6Sjkunz 	virtual struct yy_buffer_state*
71*993229b6Sjkunz 		yy_create_buffer( FLEX_STD istream* s, int size ) = 0;
72*993229b6Sjkunz 	virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
73*993229b6Sjkunz 	virtual void yyrestart( FLEX_STD istream* s ) = 0;
74*993229b6Sjkunz 
75*993229b6Sjkunz 	virtual int yylex() = 0;
76*993229b6Sjkunz 
77*993229b6Sjkunz 	// Call yylex with new input/output sources.
78*993229b6Sjkunz 	int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
79*993229b6Sjkunz 		{
80*993229b6Sjkunz 		switch_streams( new_in, new_out );
81*993229b6Sjkunz 		return yylex();
82*993229b6Sjkunz 		}
83*993229b6Sjkunz 
84*993229b6Sjkunz 	// Switch to new input/output streams.  A nil stream pointer
85*993229b6Sjkunz 	// indicates "keep the current one".
86*993229b6Sjkunz 	virtual void switch_streams( FLEX_STD istream* new_in = 0,
87*993229b6Sjkunz 					FLEX_STD ostream* new_out = 0 ) = 0;
88*993229b6Sjkunz 
lineno()89*993229b6Sjkunz 	int lineno() const		{ return yylineno; }
90*993229b6Sjkunz 
debug()91*993229b6Sjkunz 	int debug() const		{ return yy_flex_debug; }
set_debug(int flag)92*993229b6Sjkunz 	void set_debug( int flag )	{ yy_flex_debug = flag; }
93*993229b6Sjkunz 
94*993229b6Sjkunz protected:
95*993229b6Sjkunz 	char* yytext;
96*993229b6Sjkunz 	int yyleng;
97*993229b6Sjkunz 	int yylineno;		// only maintained if you use %option yylineno
98*993229b6Sjkunz 	int yy_flex_debug;	// only has effect with -d or "%option debug"
99*993229b6Sjkunz };
100*993229b6Sjkunz 
101*993229b6Sjkunz }
102*993229b6Sjkunz #endif // FLEXLEXER_H
103*993229b6Sjkunz 
104*993229b6Sjkunz //#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
105*993229b6Sjkunz // had to disable the 'defined(yyFlexLexer)' part because it was causing duplicate class defs
106*993229b6Sjkunz #if ! defined(yyFlexLexerOnce)
107*993229b6Sjkunz // Either this is the first time through (yyFlexLexerOnce not defined),
108*993229b6Sjkunz // or this is a repeated include to define a different flavor of
109*993229b6Sjkunz // yyFlexLexer, as discussed in the flex manual.
110*993229b6Sjkunz #define yyFlexLexerOnce
111*993229b6Sjkunz 
112*993229b6Sjkunz extern "C++" {
113*993229b6Sjkunz 
114*993229b6Sjkunz class yyFlexLexer : public FlexLexer {
115*993229b6Sjkunz public:
116*993229b6Sjkunz 	// arg_yyin and arg_yyout default to the cin and cout, but we
117*993229b6Sjkunz 	// only make that assignment when initializing in yylex().
118*993229b6Sjkunz 	yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 );
119*993229b6Sjkunz 
120*993229b6Sjkunz 	virtual ~yyFlexLexer();
121*993229b6Sjkunz 
122*993229b6Sjkunz 	void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
123*993229b6Sjkunz 	struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size );
124*993229b6Sjkunz 	void yy_delete_buffer( struct yy_buffer_state* b );
125*993229b6Sjkunz 	void yyrestart( FLEX_STD istream* s );
126*993229b6Sjkunz 
127*993229b6Sjkunz 	void yypush_buffer_state( struct yy_buffer_state* new_buffer );
128*993229b6Sjkunz 	void yypop_buffer_state();
129*993229b6Sjkunz 
130*993229b6Sjkunz 	virtual int yylex();
131*993229b6Sjkunz 	virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 );
132*993229b6Sjkunz 	virtual int yywrap();
133*993229b6Sjkunz 
134*993229b6Sjkunz protected:
135*993229b6Sjkunz 	virtual int LexerInput( char* buf, int max_size );
136*993229b6Sjkunz 	virtual void LexerOutput( const char* buf, int size );
137*993229b6Sjkunz 	virtual void LexerError( const char* msg );
138*993229b6Sjkunz 
139*993229b6Sjkunz 	void yyunput( int c, char* buf_ptr );
140*993229b6Sjkunz 	int yyinput();
141*993229b6Sjkunz 
142*993229b6Sjkunz 	void yy_load_buffer_state();
143*993229b6Sjkunz 	void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s );
144*993229b6Sjkunz 	void yy_flush_buffer( struct yy_buffer_state* b );
145*993229b6Sjkunz 
146*993229b6Sjkunz 	int yy_start_stack_ptr;
147*993229b6Sjkunz 	int yy_start_stack_depth;
148*993229b6Sjkunz 	int* yy_start_stack;
149*993229b6Sjkunz 
150*993229b6Sjkunz 	void yy_push_state( int new_state );
151*993229b6Sjkunz 	void yy_pop_state();
152*993229b6Sjkunz 	int yy_top_state();
153*993229b6Sjkunz 
154*993229b6Sjkunz 	yy_state_type yy_get_previous_state();
155*993229b6Sjkunz 	yy_state_type yy_try_NUL_trans( yy_state_type current_state );
156*993229b6Sjkunz 	int yy_get_next_buffer();
157*993229b6Sjkunz 
158*993229b6Sjkunz 	FLEX_STD istream* yyin;	// input source for default LexerInput
159*993229b6Sjkunz 	FLEX_STD ostream* yyout;	// output sink for default LexerOutput
160*993229b6Sjkunz 
161*993229b6Sjkunz 	// yy_hold_char holds the character lost when yytext is formed.
162*993229b6Sjkunz 	char yy_hold_char;
163*993229b6Sjkunz 
164*993229b6Sjkunz 	// Number of characters read into yy_ch_buf.
165*993229b6Sjkunz 	int yy_n_chars;
166*993229b6Sjkunz 
167*993229b6Sjkunz 	// Points to current character in buffer.
168*993229b6Sjkunz 	char* yy_c_buf_p;
169*993229b6Sjkunz 
170*993229b6Sjkunz 	int yy_init;		// whether we need to initialize
171*993229b6Sjkunz 	int yy_start;		// start state number
172*993229b6Sjkunz 
173*993229b6Sjkunz 	// Flag which is used to allow yywrap()'s to do buffer switches
174*993229b6Sjkunz 	// instead of setting up a fresh yyin.  A bit of a hack ...
175*993229b6Sjkunz 	int yy_did_buffer_switch_on_eof;
176*993229b6Sjkunz 
177*993229b6Sjkunz 
178*993229b6Sjkunz 	size_t yy_buffer_stack_top; /**< index of top of stack. */
179*993229b6Sjkunz 	size_t yy_buffer_stack_max; /**< capacity of stack. */
180*993229b6Sjkunz 	struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
181*993229b6Sjkunz 	void yyensure_buffer_stack(void);
182*993229b6Sjkunz 
183*993229b6Sjkunz 	// The following are not always needed, but may be depending
184*993229b6Sjkunz 	// on use of certain flex features (like REJECT or yymore()).
185*993229b6Sjkunz 
186*993229b6Sjkunz 	yy_state_type yy_last_accepting_state;
187*993229b6Sjkunz 	char* yy_last_accepting_cpos;
188*993229b6Sjkunz 
189*993229b6Sjkunz 	yy_state_type* yy_state_buf;
190*993229b6Sjkunz 	yy_state_type* yy_state_ptr;
191*993229b6Sjkunz 
192*993229b6Sjkunz 	char* yy_full_match;
193*993229b6Sjkunz 	int* yy_full_state;
194*993229b6Sjkunz 	int yy_full_lp;
195*993229b6Sjkunz 
196*993229b6Sjkunz 	int yy_lp;
197*993229b6Sjkunz 	int yy_looking_for_trail_begin;
198*993229b6Sjkunz 
199*993229b6Sjkunz 	int yy_more_flag;
200*993229b6Sjkunz 	int yy_more_len;
201*993229b6Sjkunz 	int yy_more_offset;
202*993229b6Sjkunz 	int yy_prev_more_offset;
203*993229b6Sjkunz };
204*993229b6Sjkunz 
205*993229b6Sjkunz }
206*993229b6Sjkunz 
207*993229b6Sjkunz #endif // yyFlexLexer || ! yyFlexLexerOnce
208*993229b6Sjkunz 
209