2 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
5 // Copyright (c) 1993 The Regents of the University of California.
6 // All rights reserved.
8 // This code is derived from software contributed to Berkeley by
9 // Kent Williams and Tom Epperly.
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
21 // Neither the name of the University nor the names of its contributors
22 // may be used to endorse or promote products derived from this software
23 // without specific prior written permission.
25 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
26 // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
27 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // This file defines FlexLexer, an abstract class which specifies the
31 // external interface provided to flex C++ lexer objects, and yyFlexLexer,
32 // which defines a particular lexer class.
34 // If you want to create multiple lexer classes, you use the -P flag
35 // to rename each yyFlexLexer to some other xxFlexLexer. You then
36 // include <FlexLexer.h> in your other sources once per lexer class:
39 // #define yyFlexLexer xxFlexLexer
40 // #include <FlexLexer.h>
43 // #define yyFlexLexer zzFlexLexer
44 // #include <FlexLexer.h>
47 #ifndef __FLEX_LEXER_H
48 // Never included before - need to define base class.
49 #define __FLEX_LEXER_H
55 struct yy_buffer_state;
56 typedef int yy_state_type;
61 virtual ~FlexLexer() { }
63 const char* YYText() const { return yytext; }
64 int YYLeng() const { return yyleng; }
67 yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0;
68 virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0;
69 virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0;
70 virtual void yy_delete_buffer( yy_buffer_state* b ) = 0;
71 virtual void yyrestart( std::istream* s ) = 0;
72 virtual void yyrestart( std::istream& s ) = 0;
74 virtual int yylex() = 0;
76 // Call yylex with new input/output sources.
77 int yylex( std::istream& new_in, std::ostream& new_out )
79 switch_streams( new_in, new_out );
83 int yylex( std::istream* new_in, std::ostream* new_out = 0)
85 switch_streams( new_in, new_out );
89 // Switch to new input/output streams. A nil stream pointer
90 // indicates "keep the current one".
91 virtual void switch_streams( std::istream* new_in,
92 std::ostream* new_out ) = 0;
93 virtual void switch_streams( std::istream& new_in,
94 std::ostream& new_out ) = 0;
96 int lineno() const { return yylineno; }
98 int debug() const { return yy_flex_debug; }
99 void set_debug( int flag ) { yy_flex_debug = flag; }
104 int yylineno; // only maintained if you use %option yylineno
105 int yy_flex_debug; // only has effect with -d or "%option debug"
109 #endif // FLEXLEXER_H
111 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
112 // Either this is the first time through (yyFlexLexerOnce not defined),
113 // or this is a repeated include to define a different flavor of
114 // yyFlexLexer, as discussed in the flex manual.
115 # define yyFlexLexerOnce
119 class yyFlexLexer : public FlexLexer {
121 // arg_yyin and arg_yyout default to the cin and cout, but we
122 // only make that assignment when initializing in yylex().
123 yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout );
124 yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 );
130 virtual ~yyFlexLexer();
132 void yy_switch_to_buffer( yy_buffer_state* new_buffer );
133 yy_buffer_state* yy_create_buffer( std::istream* s, int size );
134 yy_buffer_state* yy_create_buffer( std::istream& s, int size );
135 void yy_delete_buffer( yy_buffer_state* b );
136 void yyrestart( std::istream* s );
137 void yyrestart( std::istream& s );
139 void yypush_buffer_state( yy_buffer_state* new_buffer );
140 void yypop_buffer_state();
143 virtual void switch_streams( std::istream& new_in, std::ostream& new_out );
144 virtual void switch_streams( std::istream* new_in = 0, std::ostream* new_out = 0 );
145 virtual int yywrap();
148 virtual int LexerInput( char* buf, int max_size );
149 virtual void LexerOutput( const char* buf, int size );
150 virtual void LexerError( const char* msg );
152 void yyunput( int c, char* buf_ptr );
155 void yy_load_buffer_state();
156 void yy_init_buffer( yy_buffer_state* b, std::istream& s );
157 void yy_flush_buffer( yy_buffer_state* b );
159 int yy_start_stack_ptr;
160 int yy_start_stack_depth;
163 void yy_push_state( int new_state );
167 yy_state_type yy_get_previous_state();
168 yy_state_type yy_try_NUL_trans( yy_state_type current_state );
169 int yy_get_next_buffer();
171 std::istream yyin; // input source for default LexerInput
172 std::ostream yyout; // output sink for default LexerOutput
174 // yy_hold_char holds the character lost when yytext is formed.
177 // Number of characters read into yy_ch_buf.
180 // Points to current character in buffer.
183 int yy_init; // whether we need to initialize
184 int yy_start; // start state number
186 // Flag which is used to allow yywrap()'s to do buffer switches
187 // instead of setting up a fresh yyin. A bit of a hack ...
188 int yy_did_buffer_switch_on_eof;
191 size_t yy_buffer_stack_top; /**< index of top of stack. */
192 size_t yy_buffer_stack_max; /**< capacity of stack. */
193 yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
194 void yyensure_buffer_stack(void);
196 // The following are not always needed, but may be depending
197 // on use of certain flex features (like REJECT or yymore()).
199 yy_state_type yy_last_accepting_state;
200 char* yy_last_accepting_cpos;
202 yy_state_type* yy_state_buf;
203 yy_state_type* yy_state_ptr;
210 int yy_looking_for_trail_begin;
215 int yy_prev_more_offset;
220 #endif // yyFlexLexer || ! yyFlexLexerOnce