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