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