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

FlexLexer.h

Go to the documentation of this file.
00001 // $Header: /cvsroot/gforge/freeling/freeling/src/include/FlexLexer.h,v 1.1.1.1 2006/02/11 13:48:58 lluisp Exp $
00002 
00003 // FlexLexer.h -- define interfaces for lexical analyzer classes generated
00004 //                by flex
00005 
00006 // Copyright (c) 1993 The Regents of the University of California.
00007 // All rights reserved.
00008 //
00009 // This code is derived from software contributed to Berkeley by
00010 // Kent Williams and Tom Epperly.
00011 //
00012 // Redistribution and use in source and binary forms with or without
00013 // modification are permitted provided that: (1) source distributions retain
00014 // this entire copyright notice and comment, and (2) distributions including
00015 // binaries display the following acknowledgement:  ``This product includes
00016 // software developed by the University of California, Berkeley and its
00017 // contributors'' in the documentation or other materials provided with the
00018 // distribution and in all advertising materials mentioning features or use
00019 // of this software.  Neither the name of the University nor the names of
00020 // its contributors may be used to endorse or promote products derived from
00021 // this software without specific prior written permission.
00022 
00023 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
00024 // WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00025 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00026 
00027 // This file defines FlexLexer, an abstract class which specifies the
00028 // external interface provided to flex C++ lexer objects, and yyFlexLexer,
00029 // which defines a particular lexer class.
00030 //
00031 // If you want to create multiple lexer classes, you use the -P flag
00032 // to rename each yyFlexLexer to some other xxFlexLexer.  You then
00033 // include <FlexLexer.h> in your other sources once per lexer class:
00034 //
00035 //      #undef yyFlexLexer
00036 //      #define yyFlexLexer xxFlexLexer
00037 //      #include <FlexLexer.h>
00038 //
00039 //      #undef yyFlexLexer
00040 //      #define yyFlexLexer zzFlexLexer
00041 //      #include <FlexLexer.h>
00042 //      ...
00043 
00044 #ifndef __FLEX_LEXER_H
00045 // Never included before - need to define base class.
00046 #define __FLEX_LEXER_H
00047 using namespace std;
00048 #include <iostream>
00049 
00050 extern "C++" {
00051 
00052 struct yy_buffer_state;
00053 typedef int yy_state_type;
00054 
00055 class FlexLexer {
00056 public:
00057         virtual ~FlexLexer()    { }
00058 
00059         const char* YYText()    { return yytext; }
00060         int YYLeng()            { return yyleng; }
00061 
00062         virtual void
00063                 yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
00064         virtual struct yy_buffer_state*
00065                 yy_create_buffer( istream* s, int size ) = 0;
00066         virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
00067         virtual void yyrestart( istream* s ) = 0;
00068 
00069         virtual int yylex() = 0;
00070 
00071         // Call yylex with new input/output sources.
00072         int yylex( istream* new_in, ostream* new_out = 0 )
00073                 {
00074                 switch_streams( new_in, new_out );
00075                 return yylex();
00076                 }
00077 
00078         // Switch to new input/output streams.  A nil stream pointer
00079         // indicates "keep the current one".
00080         virtual void switch_streams( istream* new_in = 0,
00081                                         ostream* new_out = 0 ) = 0;
00082 
00083         int lineno() const              { return yylineno; }
00084 
00085         int debug() const               { return yy_flex_debug; }
00086         void set_debug( int flag )      { yy_flex_debug = flag; }
00087 
00088 protected:
00089         char* yytext;
00090         int yyleng;
00091         int yylineno;           // only maintained if you use %option yylineno
00092         int yy_flex_debug;      // only has effect with -d or "%option debug"
00093 };
00094 
00095 }
00096 #endif
00097 
00098 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
00099 // Either this is the first time through (yyFlexLexerOnce not defined),
00100 // or this is a repeated include to define a different flavor of
00101 // yyFlexLexer, as discussed in the flex man page.
00102 #define yyFlexLexerOnce
00103 
00104 class yyFlexLexer : public FlexLexer {
00105 public:
00106         // arg_yyin and arg_yyout default to the cin and cout, but we
00107         // only make that assignment when initializing in yylex().
00108         yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 );
00109 
00110         virtual ~yyFlexLexer();
00111 
00112         void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
00113         struct yy_buffer_state* yy_create_buffer( istream* s, int size );
00114         void yy_delete_buffer( struct yy_buffer_state* b );
00115         void yyrestart( istream* s );
00116 
00117         virtual int yylex();
00118         virtual void switch_streams( istream* new_in, ostream* new_out );
00119 
00120 protected:
00121         virtual int LexerInput( char* buf, int max_size );
00122         virtual void LexerOutput( const char* buf, int size );
00123         virtual void LexerError( const char* msg );
00124 
00125         void yyunput( int c, char* buf_ptr );
00126         int yyinput();
00127 
00128         void yy_load_buffer_state();
00129         void yy_init_buffer( struct yy_buffer_state* b, istream* s );
00130         void yy_flush_buffer( struct yy_buffer_state* b );
00131 
00132         int yy_start_stack_ptr;
00133         int yy_start_stack_depth;
00134         int* yy_start_stack;
00135 
00136         void yy_push_state( int new_state );
00137         void yy_pop_state();
00138         int yy_top_state();
00139 
00140         yy_state_type yy_get_previous_state();
00141         yy_state_type yy_try_NUL_trans( yy_state_type current_state );
00142         int yy_get_next_buffer();
00143 
00144         istream* yyin;  // input source for default LexerInput
00145         ostream* yyout; // output sink for default LexerOutput
00146 
00147         struct yy_buffer_state* yy_current_buffer;
00148 
00149         // yy_hold_char holds the character lost when yytext is formed.
00150         char yy_hold_char;
00151 
00152         // Number of characters read into yy_ch_buf.
00153         int yy_n_chars;
00154 
00155         // Points to current character in buffer.
00156         char* yy_c_buf_p;
00157 
00158         int yy_init;            // whether we need to initialize
00159         int yy_start;           // start state number
00160 
00161         // Flag which is used to allow yywrap()'s to do buffer switches
00162         // instead of setting up a fresh yyin.  A bit of a hack ...
00163         int yy_did_buffer_switch_on_eof;
00164 
00165         // The following are not always needed, but may be depending
00166         // on use of certain flex features (like REJECT or yymore()).
00167 
00168         yy_state_type yy_last_accepting_state;
00169         char* yy_last_accepting_cpos;
00170 
00171         yy_state_type* yy_state_buf;
00172         yy_state_type* yy_state_ptr;
00173 
00174         char* yy_full_match;
00175         int* yy_full_state;
00176         int yy_full_lp;
00177 
00178         int yy_lp;
00179         int yy_looking_for_trail_begin;
00180 
00181         int yy_more_flag;
00182         int yy_more_len;
00183         int yy_more_offset;
00184         int yy_prev_more_offset;
00185 };
00186 
00187 #endif

Generated on Wed Apr 26 12:55:30 2006 for FreeLing by  doxygen 1.4.4