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