File indexing completed on 2024-05-05 04:37:08
0001 // -*-C++-*- 0002 // FlexLexer.h -- define interfaces for lexical analyzer classes generated 0003 // by flex 0004 0005 // Copyright (c) 1993 The Regents of the University of California. 0006 // All rights reserved. 0007 // 0008 // This code is derived from software contributed to Berkeley by 0009 // Kent Williams and Tom Epperly. 0010 // 0011 // Redistribution and use in source and binary forms, with or without 0012 // modification, are permitted provided that the following conditions 0013 // are met: 0014 0015 // 1. Redistributions of source code must retain the above copyright 0016 // notice, this list of conditions and the following disclaimer. 0017 // 2. Redistributions in binary form must reproduce the above copyright 0018 // notice, this list of conditions and the following disclaimer in the 0019 // documentation and/or other materials provided with the distribution. 0020 0021 // Neither the name of the University nor the names of its contributors 0022 // may be used to endorse or promote products derived from this software 0023 // without specific prior written permission. 0024 0025 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 0026 // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 0027 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0028 // PURPOSE. 0029 0030 // This file defines FlexLexer, an abstract class which specifies the 0031 // external interface provided to flex C++ lexer objects, and yyFlexLexer, 0032 // which defines a particular lexer class. 0033 // 0034 // If you want to create multiple lexer classes, you use the -P flag 0035 // to rename each yyFlexLexer to some other xxFlexLexer. You then 0036 // include <FlexLexer.h> in your other sources once per lexer class: 0037 // 0038 // #undef yyFlexLexer 0039 // #define yyFlexLexer xxFlexLexer 0040 // #include <FlexLexer.h> 0041 // 0042 // #undef yyFlexLexer 0043 // #define yyFlexLexer zzFlexLexer 0044 // #include <FlexLexer.h> 0045 // ... 0046 0047 #ifndef __FLEX_LEXER_H 0048 // Never included before - need to define base class. 0049 #define __FLEX_LEXER_H 0050 0051 #include <iostream> 0052 # ifndef FLEX_STD 0053 # define FLEX_STD std:: 0054 # endif 0055 0056 extern "C++" { 0057 0058 struct yy_buffer_state; 0059 typedef int yy_state_type; 0060 0061 class FlexLexer { 0062 public: 0063 virtual ~FlexLexer() { } 0064 0065 const char* YYText() const { return yytext; } 0066 int YYLeng() const { return yyleng; } 0067 0068 virtual void 0069 yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; 0070 virtual struct yy_buffer_state* 0071 yy_create_buffer( FLEX_STD istream* s, int size ) = 0; 0072 virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; 0073 virtual void yyrestart( FLEX_STD istream* s ) = 0; 0074 0075 virtual int yylex() = 0; 0076 0077 // Call yylex with new input/output sources. 0078 int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ) 0079 { 0080 switch_streams( new_in, new_out ); 0081 return yylex(); 0082 } 0083 0084 // Switch to new input/output streams. A nil stream pointer 0085 // indicates "keep the current one". 0086 virtual void switch_streams( FLEX_STD istream* new_in = 0, 0087 FLEX_STD ostream* new_out = 0 ) = 0; 0088 0089 int lineno() const { return yylineno; } 0090 0091 int debug() const { return yy_flex_debug; } 0092 void set_debug( int flag ) { yy_flex_debug = flag; } 0093 0094 protected: 0095 char* yytext; 0096 int yyleng; 0097 int yylineno; // only maintained if you use %option yylineno 0098 int yy_flex_debug; // only has effect with -d or "%option debug" 0099 }; 0100 0101 } 0102 #endif // FLEXLEXER_H 0103 0104 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) 0105 // Either this is the first time through (yyFlexLexerOnce not defined), 0106 // or this is a repeated include to define a different flavor of 0107 // yyFlexLexer, as discussed in the flex manual. 0108 #define yyFlexLexerOnce 0109 0110 extern "C++" { 0111 0112 class yyFlexLexer : public FlexLexer { 0113 public: 0114 // arg_yyin and arg_yyout default to the cin and cout, but we 0115 // only make that assignment when initializing in yylex(). 0116 yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 ); 0117 0118 virtual ~yyFlexLexer(); 0119 0120 void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); 0121 struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size ); 0122 void yy_delete_buffer( struct yy_buffer_state* b ); 0123 void yyrestart( FLEX_STD istream* s ); 0124 0125 void yypush_buffer_state( struct yy_buffer_state* new_buffer ); 0126 void yypop_buffer_state(); 0127 0128 virtual int yylex(); 0129 virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ); 0130 virtual int yywrap(); 0131 0132 protected: 0133 virtual int LexerInput( char* buf, int max_size ); 0134 virtual void LexerOutput( const char* buf, int size ); 0135 virtual void LexerError( const char* msg ); 0136 0137 void yyunput( int c, char* buf_ptr ); 0138 int yyinput(); 0139 0140 void yy_load_buffer_state(); 0141 void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s ); 0142 void yy_flush_buffer( struct yy_buffer_state* b ); 0143 0144 int yy_start_stack_ptr; 0145 int yy_start_stack_depth; 0146 int* yy_start_stack; 0147 0148 void yy_push_state( int new_state ); 0149 void yy_pop_state(); 0150 int yy_top_state(); 0151 0152 yy_state_type yy_get_previous_state(); 0153 yy_state_type yy_try_NUL_trans( yy_state_type current_state ); 0154 int yy_get_next_buffer(); 0155 0156 FLEX_STD istream* yyin; // input source for default LexerInput 0157 FLEX_STD ostream* yyout; // output sink for default LexerOutput 0158 0159 // yy_hold_char holds the character lost when yytext is formed. 0160 char yy_hold_char; 0161 0162 // Number of characters read into yy_ch_buf. 0163 int yy_n_chars; 0164 0165 // Points to current character in buffer. 0166 char* yy_c_buf_p; 0167 0168 int yy_init; // whether we need to initialize 0169 int yy_start; // start state number 0170 0171 // Flag which is used to allow yywrap()'s to do buffer switches 0172 // instead of setting up a fresh yyin. A bit of a hack ... 0173 int yy_did_buffer_switch_on_eof; 0174 0175 0176 size_t yy_buffer_stack_top; /**< index of top of stack. */ 0177 size_t yy_buffer_stack_max; /**< capacity of stack. */ 0178 struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ 0179 void yyensure_buffer_stack(void); 0180 0181 // The following are not always needed, but may be depending 0182 // on use of certain flex features (like REJECT or yymore()). 0183 0184 yy_state_type yy_last_accepting_state; 0185 char* yy_last_accepting_cpos; 0186 0187 yy_state_type* yy_state_buf; 0188 yy_state_type* yy_state_ptr; 0189 0190 char* yy_full_match; 0191 int* yy_full_state; 0192 int yy_full_lp; 0193 0194 int yy_lp; 0195 int yy_looking_for_trail_begin; 0196 0197 int yy_more_flag; 0198 int yy_more_len; 0199 int yy_more_offset; 0200 int yy_prev_more_offset; 0201 }; 0202 0203 } 0204 0205 #endif // yyFlexLexer || ! yyFlexLexerOnce 0206