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