1 // $Header: /home/daffy/u0/vern/flex/RCS/FlexLexer.h,v 1.19 96/05/25 20:43:02 vern Exp $
4 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
7 // Copyright (c) 1993 The Regents of the University of California.
8 // All rights reserved.
10 // This code is derived from software contributed to Berkeley by
11 // Kent Williams and Tom Epperly.
13 // Redistribution and use in source and binary forms are permitted provided
14 // that: (1) source distributions retain this entire copyright notice and
15 // comment, and (2) distributions including binaries display the following
16 // acknowledgement: ``This product includes software developed by the
17 // University of California, Berkeley and its contributors'' in the
18 // documentation or other materials provided with the distribution and in
19 // all advertising materials mentioning features or use of this software.
20 // Neither the name of the University nor the names of its contributors may
21 // be used to endorse or promote products derived from this software without
22 // 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( std::istream* s, int size ) = 0;
65 virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
66 virtual void yyrestart( std::istream* s ) = 0;
68 virtual int yylex() = 0;
70 // Call yylex with new input/output sources.
71 int yylex( std::istream* new_in, std::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( std::istream* new_in = 0,
80 std::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( std::istream* arg_yyin = 0, std::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( std::istream* s, int size );
113 void yy_delete_buffer( struct yy_buffer_state* b );
114 void yyrestart( std::istream* s );
117 virtual void switch_streams( std::istream* new_in, std::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, std::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 std::istream* yyin; // input source for default LexerInput
144 std::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;