FlexLexer.h revision 228072
1228072Sbapt// -*-C++-*- 2228072Sbapt// FlexLexer.h -- define interfaces for lexical analyzer classes generated 3228072Sbapt// by flex 4228072Sbapt 5228072Sbapt// Copyright (c) 1993 The Regents of the University of California. 6228072Sbapt// All rights reserved. 7228072Sbapt// 8228072Sbapt// This code is derived from software contributed to Berkeley by 9228072Sbapt// Kent Williams and Tom Epperly. 10228072Sbapt// 11228072Sbapt// Redistribution and use in source and binary forms, with or without 12228072Sbapt// modification, are permitted provided that the following conditions 13228072Sbapt// are met: 14228072Sbapt 15228072Sbapt// 1. Redistributions of source code must retain the above copyright 16228072Sbapt// notice, this list of conditions and the following disclaimer. 17228072Sbapt// 2. Redistributions in binary form must reproduce the above copyright 18228072Sbapt// notice, this list of conditions and the following disclaimer in the 19228072Sbapt// documentation and/or other materials provided with the distribution. 20228072Sbapt 21228072Sbapt// Neither the name of the University nor the names of its contributors 22228072Sbapt// may be used to endorse or promote products derived from this software 23228072Sbapt// without specific prior written permission. 24228072Sbapt 25228072Sbapt// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 26228072Sbapt// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 27228072Sbapt// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28228072Sbapt// PURPOSE. 29228072Sbapt 30228072Sbapt// This file defines FlexLexer, an abstract class which specifies the 31228072Sbapt// external interface provided to flex C++ lexer objects, and yyFlexLexer, 32228072Sbapt// which defines a particular lexer class. 33228072Sbapt// 34228072Sbapt// If you want to create multiple lexer classes, you use the -P flag 35228072Sbapt// to rename each yyFlexLexer to some other xxFlexLexer. You then 36228072Sbapt// include <FlexLexer.h> in your other sources once per lexer class: 37228072Sbapt// 38228072Sbapt// #undef yyFlexLexer 39228072Sbapt// #define yyFlexLexer xxFlexLexer 40228072Sbapt// #include <FlexLexer.h> 41228072Sbapt// 42228072Sbapt// #undef yyFlexLexer 43228072Sbapt// #define yyFlexLexer zzFlexLexer 44228072Sbapt// #include <FlexLexer.h> 45228072Sbapt// ... 46228072Sbapt 47228072Sbapt#ifndef __FLEX_LEXER_H 48228072Sbapt// Never included before - need to define base class. 49228072Sbapt#define __FLEX_LEXER_H 50228072Sbapt 51228072Sbapt#include <iostream> 52228072Sbapt# ifndef FLEX_STD 53228072Sbapt# define FLEX_STD std:: 54228072Sbapt# endif 55228072Sbapt 56228072Sbaptextern "C++" { 57228072Sbapt 58228072Sbaptstruct yy_buffer_state; 59228072Sbapttypedef int yy_state_type; 60228072Sbapt 61228072Sbaptclass FlexLexer { 62228072Sbaptpublic: 63228072Sbapt virtual ~FlexLexer() { } 64228072Sbapt 65228072Sbapt const char* YYText() const { return yytext; } 66228072Sbapt int YYLeng() const { return yyleng; } 67228072Sbapt 68228072Sbapt virtual void 69228072Sbapt yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; 70228072Sbapt virtual struct yy_buffer_state* 71228072Sbapt yy_create_buffer( FLEX_STD istream* s, int size ) = 0; 72228072Sbapt virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; 73228072Sbapt virtual void yyrestart( FLEX_STD istream* s ) = 0; 74228072Sbapt 75228072Sbapt virtual int yylex() = 0; 76228072Sbapt 77228072Sbapt // Call yylex with new input/output sources. 78228072Sbapt int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ) 79228072Sbapt { 80228072Sbapt switch_streams( new_in, new_out ); 81228072Sbapt return yylex(); 82228072Sbapt } 83228072Sbapt 84228072Sbapt // Switch to new input/output streams. A nil stream pointer 85228072Sbapt // indicates "keep the current one". 86228072Sbapt virtual void switch_streams( FLEX_STD istream* new_in = 0, 87228072Sbapt FLEX_STD ostream* new_out = 0 ) = 0; 88228072Sbapt 89228072Sbapt int lineno() const { return yylineno; } 90228072Sbapt 91228072Sbapt int debug() const { return yy_flex_debug; } 92228072Sbapt void set_debug( int flag ) { yy_flex_debug = flag; } 93228072Sbapt 94228072Sbaptprotected: 95228072Sbapt char* yytext; 96228072Sbapt int yyleng; 97228072Sbapt int yylineno; // only maintained if you use %option yylineno 98228072Sbapt int yy_flex_debug; // only has effect with -d or "%option debug" 99228072Sbapt}; 100228072Sbapt 101228072Sbapt} 102228072Sbapt#endif // FLEXLEXER_H 103228072Sbapt 104228072Sbapt#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) 105228072Sbapt// Either this is the first time through (yyFlexLexerOnce not defined), 106228072Sbapt// or this is a repeated include to define a different flavor of 107228072Sbapt// yyFlexLexer, as discussed in the flex manual. 108228072Sbapt#define yyFlexLexerOnce 109228072Sbapt 110228072Sbaptextern "C++" { 111228072Sbapt 112228072Sbaptclass yyFlexLexer : public FlexLexer { 113228072Sbaptpublic: 114228072Sbapt // arg_yyin and arg_yyout default to the cin and cout, but we 115228072Sbapt // only make that assignment when initializing in yylex(). 116228072Sbapt yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 ); 117228072Sbapt 118228072Sbapt virtual ~yyFlexLexer(); 119228072Sbapt 120228072Sbapt void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); 121228072Sbapt struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size ); 122228072Sbapt void yy_delete_buffer( struct yy_buffer_state* b ); 123228072Sbapt void yyrestart( FLEX_STD istream* s ); 124228072Sbapt 125228072Sbapt void yypush_buffer_state( struct yy_buffer_state* new_buffer ); 126228072Sbapt void yypop_buffer_state(); 127228072Sbapt 128228072Sbapt virtual int yylex(); 129228072Sbapt virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 ); 130228072Sbapt virtual int yywrap(); 131228072Sbapt 132228072Sbaptprotected: 133228072Sbapt virtual int LexerInput( char* buf, int max_size ); 134228072Sbapt virtual void LexerOutput( const char* buf, int size ); 135228072Sbapt virtual void LexerError( const char* msg ); 136228072Sbapt 137228072Sbapt void yyunput( int c, char* buf_ptr ); 138228072Sbapt int yyinput(); 139228072Sbapt 140228072Sbapt void yy_load_buffer_state(); 141228072Sbapt void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s ); 142228072Sbapt void yy_flush_buffer( struct yy_buffer_state* b ); 143228072Sbapt 144228072Sbapt int yy_start_stack_ptr; 145228072Sbapt int yy_start_stack_depth; 146228072Sbapt int* yy_start_stack; 147228072Sbapt 148228072Sbapt void yy_push_state( int new_state ); 149228072Sbapt void yy_pop_state(); 150228072Sbapt int yy_top_state(); 151228072Sbapt 152228072Sbapt yy_state_type yy_get_previous_state(); 153228072Sbapt yy_state_type yy_try_NUL_trans( yy_state_type current_state ); 154228072Sbapt int yy_get_next_buffer(); 155228072Sbapt 156228072Sbapt FLEX_STD istream* yyin; // input source for default LexerInput 157228072Sbapt FLEX_STD ostream* yyout; // output sink for default LexerOutput 158228072Sbapt 159228072Sbapt // yy_hold_char holds the character lost when yytext is formed. 160228072Sbapt char yy_hold_char; 161228072Sbapt 162228072Sbapt // Number of characters read into yy_ch_buf. 163228072Sbapt int yy_n_chars; 164228072Sbapt 165228072Sbapt // Points to current character in buffer. 166228072Sbapt char* yy_c_buf_p; 167228072Sbapt 168228072Sbapt int yy_init; // whether we need to initialize 169228072Sbapt int yy_start; // start state number 170228072Sbapt 171228072Sbapt // Flag which is used to allow yywrap()'s to do buffer switches 172228072Sbapt // instead of setting up a fresh yyin. A bit of a hack ... 173228072Sbapt int yy_did_buffer_switch_on_eof; 174228072Sbapt 175228072Sbapt 176228072Sbapt size_t yy_buffer_stack_top; /**< index of top of stack. */ 177228072Sbapt size_t yy_buffer_stack_max; /**< capacity of stack. */ 178228072Sbapt struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ 179228072Sbapt void yyensure_buffer_stack(void); 180228072Sbapt 181228072Sbapt // The following are not always needed, but may be depending 182228072Sbapt // on use of certain flex features (like REJECT or yymore()). 183228072Sbapt 184228072Sbapt yy_state_type yy_last_accepting_state; 185228072Sbapt char* yy_last_accepting_cpos; 186228072Sbapt 187228072Sbapt yy_state_type* yy_state_buf; 188228072Sbapt yy_state_type* yy_state_ptr; 189228072Sbapt 190228072Sbapt char* yy_full_match; 191228072Sbapt int* yy_full_state; 192228072Sbapt int yy_full_lp; 193228072Sbapt 194228072Sbapt int yy_lp; 195228072Sbapt int yy_looking_for_trail_begin; 196228072Sbapt 197228072Sbapt int yy_more_flag; 198228072Sbapt int yy_more_len; 199228072Sbapt int yy_more_offset; 200228072Sbapt int yy_prev_more_offset; 201228072Sbapt}; 202228072Sbapt 203228072Sbapt} 204228072Sbapt 205228072Sbapt#endif // yyFlexLexer || ! yyFlexLexerOnce 206228072Sbapt 207