Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members

FlexLexer.h

00001 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
00002 //                by flex
00003 
00004 // Copyright (c) 1993 The Regents of the University of California.
00005 // All rights reserved.
00006 //
00007 // This code is derived from software contributed to Berkeley by
00008 // Kent Williams and Tom Epperly.
00009 //
00010 // Redistribution and use in source and binary forms with or without
00011 // modification are permitted provided that: (1) source distributions retain
00012 // this entire copyright notice and comment, and (2) distributions including
00013 // binaries display the following acknowledgement:  ``This product includes
00014 // software developed by the University of California, Berkeley and its
00015 // contributors'' in the documentation or other materials provided with the
00016 // distribution and in all advertising materials mentioning features or use
00017 // of this software.  Neither the name of the University nor the names of
00018 // its contributors may be used to endorse or promote products derived from
00019 // this software without specific prior written permission.
00020 
00021 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
00022 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00023 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00024 
00025 // This file defines FlexLexer, an abstract class which specifies the
00026 // external interface provided to flex C++ lexer objects, and yyFlexLexer,
00027 // which defines a particular lexer class.
00028 //
00029 // If you want to create multiple lexer classes, you use the -P flag
00030 // to rename each yyFlexLexer to some other xxFlexLexer.  You then
00031 // include <FlexLexer.h> in your other sources once per lexer class:
00032 //
00033 //      #undef yyFlexLexer
00034 //      #define yyFlexLexer xxFlexLexer
00035 //      #include <FlexLexer.h>
00036 //
00037 //      #undef yyFlexLexer
00038 //      #define yyFlexLexer zzFlexLexer
00039 //      #include <FlexLexer.h>
00040 //      ...
00041 
00042 /**
00043 From:
00044 Frank P.E. Vanris
00045 Subject: Modification of FlexLexer.h
00046 
00047 Date: Thu, 17 Jan 2002 14:35:26 -0600
00048 
00049 I modified FlexLexer.h a bit.
00050 
00051 To prevent a compiler warning (complaining that yylex() was hiding this
00052 function) I added in class yyFlexLexer the following:
00053 
00054 
00055         int yylex( istream* new_in, ostream* new_out = 0 ) {
00056           return FlexLexer::yylex(new_in, new_out);
00057         }
00058 
00059 Also in the class yyFlexLexer I added a protected method:
00060 
00061         // Function that can be used by subclasses during yylex()
00062         virtual int actionHook(void* data = 0) {
00063           return data == 0;
00064         }
00065 
00066 I override this function in a subclass of yyFlexLexer and I use it in
00067 the lex file to call my subclass. Any data I have to save (e.g.
00068 character count) I can now keep in my own subclass as memberfields
00069 instead of global variables in the lex file.
00070 
00071 I attached the FlexLexer.h file.
00072 
00073 I don't know whether Flex is still maintained since the last tarfile is
00074 from July 27th 1997, but I thought I at least pass it on.
00075 
00076 Frank Vanris.
00077 */
00078 
00079 /**
00080 Sept 2003: changes by stephan@wanderinghorse.net
00081    - added 'using' statements for istream/ostreams, so gcc 3.x can play, too.
00082    - replace iostream.h with iostream, so gcc 3.x won't bitch about backwards-compatibility headers.
00083 
00084 */
00085 
00086 #ifndef __FLEX_LEXER_H
00087 // Never included before - need to define base class.
00088 #define __FLEX_LEXER_H
00089 #include <iostream>
00090 
00091 //////////////////////////////////////////////////////////////////////
00092 // workarounds for the (very outdated) flex output:
00093 using std::istream;
00094 using std::ostream;
00095 using std::cin;
00096 using std::cout;
00097 using std::cerr;
00098 using std::endl;
00099 //////////////////////////////////////////////////////////////////////
00100 
00101 extern "C++" {
00102 
00103 struct yy_buffer_state;
00104 typedef int yy_state_type;
00105 
00106 class FlexLexer {
00107 public:
00108         virtual ~FlexLexer()    { }
00109 
00110         const char* YYText()    { return yytext; }
00111         int YYLeng()            { return yyleng; }
00112 
00113         virtual void
00114                 yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
00115         virtual struct yy_buffer_state*
00116                 yy_create_buffer( istream* s, int size ) = 0;
00117         virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
00118         virtual void yyrestart( istream* s ) = 0;
00119 
00120         virtual int yylex() = 0;
00121 
00122         // Call yylex with new input/output sources.
00123         int yylex( istream* new_in, ostream* new_out = 0 )
00124                 {
00125                 switch_streams( new_in, new_out );
00126                 return yylex();
00127                 }
00128 
00129         // Switch to new input/output streams.  A nil stream pointer
00130         // indicates "keep the current one".
00131         virtual void switch_streams( istream* new_in = 0,
00132                                         ostream* new_out = 0 ) = 0;
00133 
00134         int lineno() const              { return yylineno; }
00135 
00136         int debug() const               { return yy_flex_debug; }
00137         void set_debug( int flag )      { yy_flex_debug = flag; }
00138 
00139 protected:
00140         char* yytext;
00141         int yyleng;
00142         int yylineno;           // only maintained if you use %option yylineno
00143         int yy_flex_debug;      // only has effect with -d or "%option debug"
00144 };
00145 
00146 }
00147 #endif
00148 
00149 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
00150 // Either this is the first time through (yyFlexLexerOnce not defined),
00151 // or this is a repeated include to define a different flavor of
00152 // yyFlexLexer, as discussed in the flex man page.
00153 #define yyFlexLexerOnce
00154 
00155 class yyFlexLexer : public FlexLexer {
00156 public:
00157         // arg_yyin and arg_yyout default to the cin and cout, but we
00158         // only make that assignment when initializing in yylex().
00159         yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 );
00160 
00161         virtual ~yyFlexLexer();
00162 
00163         void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
00164         struct yy_buffer_state* yy_create_buffer( istream* s, int size );
00165         void yy_delete_buffer( struct yy_buffer_state* b );
00166         void yyrestart( istream* s );
00167 
00168         virtual int yylex();
00169         virtual void switch_streams( istream* new_in, ostream* new_out );
00170 
00171         int yylex( istream* new_in, ostream* new_out = 0 ) {
00172           return FlexLexer::yylex(new_in, new_out);
00173         }
00174 
00175 protected:
00176         virtual int LexerInput( char* buf, int max_size );
00177         virtual void LexerOutput( const char* buf, int size );
00178         virtual void LexerError( const char* msg );
00179 
00180         // Function that can be used by subclasses during yylex()
00181         virtual int actionHook(void* data = 0) {
00182           return data == 0;
00183         }
00184 
00185         void yyunput( int c, char* buf_ptr );
00186         int yyinput();
00187 
00188         void yy_load_buffer_state();
00189         void yy_init_buffer( struct yy_buffer_state* b, istream* s );
00190         void yy_flush_buffer( struct yy_buffer_state* b );
00191 
00192         int yy_start_stack_ptr;
00193         int yy_start_stack_depth;
00194         int* yy_start_stack;
00195 
00196         void yy_push_state( int new_state );
00197         void yy_pop_state();
00198         int yy_top_state();
00199 
00200         yy_state_type yy_get_previous_state();
00201         yy_state_type yy_try_NUL_trans( yy_state_type current_state );
00202         int yy_get_next_buffer();
00203 
00204         istream* yyin;  // input source for default LexerInput
00205         ostream* yyout; // output sink for default LexerOutput
00206 
00207         struct yy_buffer_state* yy_current_buffer;
00208 
00209         // yy_hold_char holds the character lost when yytext is formed.
00210         char yy_hold_char;
00211 
00212         // Number of characters read into yy_ch_buf.
00213         int yy_n_chars;
00214 
00215         // Points to current character in buffer.
00216         char* yy_c_buf_p;
00217 
00218         int yy_init;            // whether we need to initialize
00219         int yy_start;           // start state number
00220 
00221         // Flag which is used to allow yywrap()'s to do buffer switches
00222         // instead of setting up a fresh yyin.  A bit of a hack ...
00223         int yy_did_buffer_switch_on_eof;
00224 
00225         // The following are not always needed, but may be depending
00226         // on use of certain flex features (like REJECT or yymore()).
00227 
00228         yy_state_type yy_last_accepting_state;
00229         char* yy_last_accepting_cpos;
00230 
00231         yy_state_type* yy_state_buf;
00232         yy_state_type* yy_state_ptr;
00233 
00234         char* yy_full_match;
00235         int* yy_full_state;
00236         int yy_full_lp;
00237 
00238         int yy_lp;
00239         int yy_looking_for_trail_begin;
00240 
00241         int yy_more_flag;
00242         int yy_more_len;
00243         int yy_more_offset;
00244         int yy_prev_more_offset;
00245 };
00246 
00247 #endif

Generated on Thu Jun 16 16:18:12 2005 for s11n by  doxygen 1.4.3-20050530