FlexLexer.h 6.7 KB

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