1 /* $NetBSD: FlexLexer.h,v 1.2 2016/01/09 17:38:57 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: ~FlexLexer()65 virtual ~FlexLexer() { } 66 YYText()67 const char* YYText() const { return yytext; } YYLeng()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 struct yy_buffer_state* 75 yy_create_buffer( FLEX_STD istream& s, int size ) = 0; 76 virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; 77 virtual void yyrestart( FLEX_STD istream* s ) = 0; 78 virtual void yyrestart( FLEX_STD istream& s ) = 0; 79 80 virtual int yylex() = 0; 81 82 // Call yylex with new input/output sources. yylex(FLEX_STD istream & new_in,FLEX_STD ostream & new_out)83 int yylex( FLEX_STD istream& new_in, FLEX_STD ostream& new_out ) 84 { 85 switch_streams( new_in, new_out ); 86 return yylex(); 87 } 88 89 int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0) 90 { 91 switch_streams( new_in, new_out ); 92 return yylex(); 93 } 94 95 // Switch to new input/output streams. A nil stream pointer 96 // indicates "keep the current one". 97 virtual void switch_streams( FLEX_STD istream* new_in, 98 FLEX_STD ostream* new_out ) = 0; 99 virtual void switch_streams( FLEX_STD istream& new_in, 100 FLEX_STD ostream& new_out ) = 0; 101 lineno()102 int lineno() const { return yylineno; } 103 debug()104 int debug() const { return yy_flex_debug; } set_debug(int flag)105 void set_debug( int flag ) { yy_flex_debug = flag; } 106 107 protected: 108 char* yytext; 109 int yyleng; 110 int yylineno; // only maintained if you use %option yylineno 111 int yy_flex_debug; // only has effect with -d or "%option debug" 112 }; 113 114 } 115 #endif // FLEXLEXER_H 116 117 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) 118 // Either this is the first time through (yyFlexLexerOnce not defined), 119 // or this is a repeated include to define a different flavor of 120 // yyFlexLexer, as discussed in the flex manual. 121 #define yyFlexLexerOnce 122 123 extern "C++" { 124 125 class yyFlexLexer : public FlexLexer { 126 public: 127 // arg_yyin and arg_yyout default to the cin and cout, but we 128 // only make that assignment when initializing in yylex(). 129 yyFlexLexer( FLEX_STD istream& arg_yyin, FLEX_STD ostream& arg_yyout ); 130 yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 ); 131 private: 132 void ctor_common(); 133 134 public: 135 136 virtual ~yyFlexLexer(); 137 138 void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); 139 struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size ); 140 struct yy_buffer_state* yy_create_buffer( FLEX_STD istream& s, int size ); 141 void yy_delete_buffer( struct yy_buffer_state* b ); 142 void yyrestart( FLEX_STD istream* s ); 143 void yyrestart( FLEX_STD istream& s ); 144 145 void yypush_buffer_state( struct yy_buffer_state* new_buffer ); 146 void yypop_buffer_state(); 147 148 virtual int yylex(); 149 virtual void switch_streams( FLEX_STD istream& new_in, FLEX_STD ostream& new_out ); 150 virtual void switch_streams( FLEX_STD istream* new_in = 0, FLEX_STD ostream* new_out = 0 ); 151 virtual int yywrap(); 152 153 protected: 154 virtual int LexerInput( char* buf, int max_size ); 155 virtual void LexerOutput( const char* buf, int size ); 156 virtual void LexerError( const char* msg ); 157 158 void yyunput( int c, char* buf_ptr ); 159 int yyinput(); 160 161 void yy_load_buffer_state(); 162 void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream& s ); 163 void yy_flush_buffer( struct yy_buffer_state* b ); 164 165 int yy_start_stack_ptr; 166 int yy_start_stack_depth; 167 int* yy_start_stack; 168 169 void yy_push_state( int new_state ); 170 void yy_pop_state(); 171 int yy_top_state(); 172 173 yy_state_type yy_get_previous_state(); 174 yy_state_type yy_try_NUL_trans( yy_state_type current_state ); 175 int yy_get_next_buffer(); 176 177 FLEX_STD istream yyin; // input source for default LexerInput 178 FLEX_STD ostream yyout; // output sink for default LexerOutput 179 180 // yy_hold_char holds the character lost when yytext is formed. 181 char yy_hold_char; 182 183 // Number of characters read into yy_ch_buf. 184 int yy_n_chars; 185 186 // Points to current character in buffer. 187 char* yy_c_buf_p; 188 189 int yy_init; // whether we need to initialize 190 int yy_start; // start state number 191 192 // Flag which is used to allow yywrap()'s to do buffer switches 193 // instead of setting up a fresh yyin. A bit of a hack ... 194 int yy_did_buffer_switch_on_eof; 195 196 197 size_t yy_buffer_stack_top; /**< index of top of stack. */ 198 size_t yy_buffer_stack_max; /**< capacity of stack. */ 199 struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ 200 void yyensure_buffer_stack(void); 201 202 // The following are not always needed, but may be depending 203 // on use of certain flex features (like REJECT or yymore()). 204 205 yy_state_type yy_last_accepting_state; 206 char* yy_last_accepting_cpos; 207 208 yy_state_type* yy_state_buf; 209 yy_state_type* yy_state_ptr; 210 211 char* yy_full_match; 212 int* yy_full_state; 213 int yy_full_lp; 214 215 int yy_lp; 216 int yy_looking_for_trail_begin; 217 218 int yy_more_flag; 219 int yy_more_len; 220 int yy_more_offset; 221 int yy_prev_more_offset; 222 }; 223 224 } 225 226 #endif // yyFlexLexer || ! yyFlexLexerOnce 227 228