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