Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.bin / lex / FlexLexer.h
1 // $Header: /home/daffy/u0/vern/flex/RCS/FlexLexer.h,v 1.19 96/05/25 20:43:02 vern Exp $
2 // $FreeBSD: src/usr.bin/lex/FlexLexer.h,v 1.3 1999/10/27 07:56:43 obrien Exp $
3
4 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
5 //                by flex
6
7 // Copyright (c) 1993 The Regents of the University of California.
8 // All rights reserved.
9 //
10 // This code is derived from software contributed to Berkeley by
11 // Kent Williams and Tom Epperly.
12 //
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.
26
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.
30 //
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:
34 //
35 //      #undef yyFlexLexer
36 //      #define yyFlexLexer xxFlexLexer
37 //      #include <FlexLexer.h>
38 //
39 //      #undef yyFlexLexer
40 //      #define yyFlexLexer zzFlexLexer
41 //      #include <FlexLexer.h>
42 //      ...
43
44 #ifndef __FLEX_LEXER_H
45 // Never included before - need to define base class.
46 #define __FLEX_LEXER_H
47 #include <iostream.h>
48
49 extern "C++" {
50
51 struct yy_buffer_state;
52 typedef int yy_state_type;
53
54 class FlexLexer {
55 public:
56         virtual ~FlexLexer()    { }
57
58         const char* YYText()    { return yytext; }
59         int YYLeng()            { return yyleng; }
60
61         virtual void
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;
67
68         virtual int yylex() = 0;
69
70         // Call yylex with new input/output sources.
71         int yylex( istream* new_in, ostream* new_out = 0 )
72                 {
73                 switch_streams( new_in, new_out );
74                 return yylex();
75                 }
76
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;
81
82         int lineno() const              { return yylineno; }
83
84         int debug() const               { return yy_flex_debug; }
85         void set_debug( int flag )      { yy_flex_debug = flag; }
86
87 protected:
88         char* yytext;
89         int yyleng;
90         int yylineno;           // only maintained if you use %option yylineno
91         int yy_flex_debug;      // only has effect with -d or "%option debug"
92 };
93
94 }
95 #endif
96
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
102
103 class yyFlexLexer : public FlexLexer {
104 public:
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 );
108
109         virtual ~yyFlexLexer();
110
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 );
115
116         virtual int yylex();
117         virtual void switch_streams( istream* new_in, ostream* new_out );
118
119 protected:
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 );
123
124         void yyunput( int c, char* buf_ptr );
125         int yyinput();
126
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 );
130
131         int yy_start_stack_ptr;
132         int yy_start_stack_depth;
133         int* yy_start_stack;
134
135         void yy_push_state( int new_state );
136         void yy_pop_state();
137         int yy_top_state();
138
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();
142
143         istream* yyin;  // input source for default LexerInput
144         ostream* yyout; // output sink for default LexerOutput
145
146         struct yy_buffer_state* yy_current_buffer;
147
148         // yy_hold_char holds the character lost when yytext is formed.
149         char yy_hold_char;
150
151         // Number of characters read into yy_ch_buf.
152         int yy_n_chars;
153
154         // Points to current character in buffer.
155         char* yy_c_buf_p;
156
157         int yy_init;            // whether we need to initialize
158         int yy_start;           // start state number
159
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;
163
164         // The following are not always needed, but may be depending
165         // on use of certain flex features (like REJECT or yymore()).
166
167         yy_state_type yy_last_accepting_state;
168         char* yy_last_accepting_cpos;
169
170         yy_state_type* yy_state_buf;
171         yy_state_type* yy_state_ptr;
172
173         char* yy_full_match;
174         int* yy_full_state;
175         int yy_full_lp;
176
177         int yy_lp;
178         int yy_looking_for_trail_begin;
179
180         int yy_more_flag;
181         int yy_more_len;
182         int yy_more_offset;
183         int yy_prev_more_offset;
184 };
185
186 #endif