3 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
6 // Copyright (c) 1993 The Regents of the University of California.
7 // All rights reserved.
9 // This code is derived from software contributed to Berkeley by
10 // Kent Williams and Tom Epperly.
12 // Redistribution and use in source and binary forms with or without
13 // modification are permitted provided that: (1) source distributions retain
14 // this entire copyright notice and comment, and (2) distributions including
15 // binaries display the following acknowledgement: ``This product includes
16 // software developed by the University of California, Berkeley and its
17 // contributors'' in the documentation or other materials provided with the
18 // distribution and in all advertising materials mentioning features or use
19 // of this software. Neither the name of the University nor the names of
20 // its contributors may be used to endorse or promote products derived from
21 // this software without specific prior written permission.
23 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
24 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
25 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 // This file defines FlexLexer, an abstract class which specifies the
28 // external interface provided to flex C++ lexer objects, and yyFlexLexer,
29 // which defines a particular lexer class.
31 // If you want to create multiple lexer classes, you use the -P flag
32 // to rename each yyFlexLexer to some other xxFlexLexer. You then
33 // include <FlexLexer.h> in your other sources once per lexer class:
36 // #define yyFlexLexer xxFlexLexer
37 // #include <FlexLexer.h>
40 // #define yyFlexLexer zzFlexLexer
41 // #include <FlexLexer.h>
44 #ifndef __FLEX_LEXER_H
45 // Never included before - need to define base class.
46 #define __FLEX_LEXER_H
51 struct yy_buffer_state
;
52 typedef int yy_state_type
;
56 virtual ~FlexLexer() { }
58 const char* YYText() { return yytext
; }
59 int YYLeng() { return yyleng
; }
62 yy_switch_to_buffer( struct yy_buffer_state
* new_buffer
) = 0;
63 virtual struct yy_buffer_state
*
64 yy_create_buffer( istream
* s
, int size
) = 0;
65 virtual void yy_delete_buffer( struct yy_buffer_state
* b
) = 0;
66 virtual void yyrestart( istream
* s
) = 0;
68 virtual int yylex() = 0;
70 // Call yylex with new input/output sources.
71 int yylex( istream
* new_in
, ostream
* new_out
= 0 )
73 switch_streams( new_in
, new_out
);
77 // Switch to new input/output streams. A nil stream pointer
78 // indicates "keep the current one".
79 virtual void switch_streams( istream
* new_in
= 0,
80 ostream
* new_out
= 0 ) = 0;
82 int lineno() const { return yylineno
; }
84 int debug() const { return yy_flex_debug
; }
85 void set_debug( int flag
) { yy_flex_debug
= flag
; }
90 int yylineno
; // only maintained if you use %option yylineno
91 int yy_flex_debug
; // only has effect with -d or "%option debug"
97 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
98 // Either this is the first time through (yyFlexLexerOnce not defined),
99 // or this is a repeated include to define a different flavor of
100 // yyFlexLexer, as discussed in the flex man page.
101 #define yyFlexLexerOnce
103 class yyFlexLexer
: public FlexLexer
{
105 // arg_yyin and arg_yyout default to the cin and cout, but we
106 // only make that assignment when initializing in yylex().
107 yyFlexLexer( istream
* arg_yyin
= 0, ostream
* arg_yyout
= 0 );
109 virtual ~yyFlexLexer();
111 void yy_switch_to_buffer( struct yy_buffer_state
* new_buffer
);
112 struct yy_buffer_state
* yy_create_buffer( istream
* s
, int size
);
113 void yy_delete_buffer( struct yy_buffer_state
* b
);
114 void yyrestart( istream
* s
);
117 virtual void switch_streams( istream
* new_in
, ostream
* new_out
);
120 virtual int LexerInput( char* buf
, int max_size
);
121 virtual void LexerOutput( const char* buf
, int size
);
122 virtual void LexerError( const char* msg
);
124 void yyunput( int c
, char* buf_ptr
);
127 void yy_load_buffer_state();
128 void yy_init_buffer( struct yy_buffer_state
* b
, istream
* s
);
129 void yy_flush_buffer( struct yy_buffer_state
* b
);
131 int yy_start_stack_ptr
;
132 int yy_start_stack_depth
;
135 void yy_push_state( int new_state
);
139 yy_state_type
yy_get_previous_state();
140 yy_state_type
yy_try_NUL_trans( yy_state_type current_state
);
141 int yy_get_next_buffer();
143 istream
* yyin
; // input source for default LexerInput
144 ostream
* yyout
; // output sink for default LexerOutput
146 struct yy_buffer_state
* yy_current_buffer
;
148 // yy_hold_char holds the character lost when yytext is formed.
151 // Number of characters read into yy_ch_buf.
154 // Points to current character in buffer.
157 int yy_init
; // whether we need to initialize
158 int yy_start
; // start state number
160 // Flag which is used to allow yywrap()'s to do buffer switches
161 // instead of setting up a fresh yyin. A bit of a hack ...
162 int yy_did_buffer_switch_on_eof
;
164 // The following are not always needed, but may be depending
165 // on use of certain flex features (like REJECT or yymore()).
167 yy_state_type yy_last_accepting_state
;
168 char* yy_last_accepting_cpos
;
170 yy_state_type
* yy_state_buf
;
171 yy_state_type
* yy_state_ptr
;
178 int yy_looking_for_trail_begin
;
183 int yy_prev_more_offset
;