FlexLexer.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. extern "C++" {
  46. struct yy_buffer_state;
  47. typedef int yy_state_type;
  48. class FlexLexer
  49. {
  50. public:
  51. virtual ~FlexLexer() { }
  52. const char* YYText() const { return yytext; }
  53. int YYLeng() const { return yyleng; }
  54. virtual void
  55. yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0;
  56. virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0;
  57. virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0;
  58. virtual void yy_delete_buffer( yy_buffer_state* b ) = 0;
  59. virtual void yyrestart( std::istream* s ) = 0;
  60. virtual void yyrestart( std::istream& s ) = 0;
  61. virtual int yylex() = 0;
  62. // Call yylex with new input/output sources.
  63. int yylex( std::istream& new_in, std::ostream& new_out )
  64. {
  65. switch_streams( new_in, new_out );
  66. return yylex();
  67. }
  68. int yylex( std::istream* new_in, std::ostream* new_out = 0)
  69. {
  70. switch_streams( new_in, new_out );
  71. return yylex();
  72. }
  73. // Switch to new input/output streams. A nil stream pointer
  74. // indicates "keep the current one".
  75. virtual void switch_streams( std::istream* new_in,
  76. std::ostream* new_out ) = 0;
  77. virtual void switch_streams( std::istream& new_in,
  78. std::ostream& new_out ) = 0;
  79. int lineno() const { return yylineno; }
  80. int debug() const { return yyflexdebug; }
  81. void set_debug( int flag ) { yyflexdebug = flag; }
  82. protected:
  83. char* yytext;
  84. int yyleng;
  85. int yylineno; // only maintained if you use %option yylineno
  86. int yyflexdebug; // only has effect with -d or "%option debug"
  87. };
  88. }
  89. #endif // FLEXLEXER_H
  90. #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
  91. // Either this is the first time through (yyFlexLexerOnce not defined),
  92. // or this is a repeated include to define a different flavor of
  93. // yyFlexLexer, as discussed in the flex manual.
  94. # define yyFlexLexerOnce
  95. extern "C++" {
  96. class yyFlexLexer : public FlexLexer {
  97. public:
  98. // arg_yyin and arg_yyout default to the cin and cout, but we
  99. // only make that assignment when initializing in yylex().
  100. yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout );
  101. yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 );
  102. private:
  103. void ctor_common();
  104. public:
  105. virtual ~yyFlexLexer();
  106. void yy_switch_to_buffer( yy_buffer_state* new_buffer );
  107. yy_buffer_state* yy_create_buffer( std::istream* s, int size );
  108. yy_buffer_state* yy_create_buffer( std::istream& s, int size );
  109. void yy_delete_buffer( yy_buffer_state* b );
  110. void yyrestart( std::istream* s );
  111. void yyrestart( std::istream& s );
  112. void yypush_buffer_state( yy_buffer_state* new_buffer );
  113. void yypop_buffer_state();
  114. virtual int yyread(char *buf, size_t);
  115. virtual int yylex();
  116. virtual void switch_streams( std::istream& new_in, std::ostream& new_out );
  117. virtual void switch_streams( std::istream* new_in = 0, std::ostream* new_out = 0 );
  118. virtual int yywrap();
  119. protected:
  120. virtual int LexerInput( char* buf, int max_size );
  121. virtual void LexerOutput( const char* buf, int size );
  122. virtual void LexerError( const char* msg );
  123. void yyunput_r( int c, char* buf_ptr );
  124. int yyinput();
  125. void yy_load_buffer_state();
  126. void yy_init_buffer( yy_buffer_state* b, std::istream& s );
  127. void yy_flush_buffer( yy_buffer_state* b );
  128. int yy_start_stack_ptr;
  129. int yy_start_stack_depth;
  130. int* yy_start_stack;
  131. void yy_push_state( int new_state );
  132. void yy_pop_state();
  133. int yy_top_state();
  134. yy_state_type yy_get_previous_state();
  135. yy_state_type yy_try_NUL_trans( yy_state_type current_state );
  136. int yy_get_next_buffer();
  137. std::istream yyin; // input source for default LexerInput
  138. std::ostream yyout; // output sink for default LexerOutput
  139. // yy_hold_char holds the character lost when yytext is formed.
  140. char yy_hold_char;
  141. // Number of characters read into yy_ch_buf.
  142. int yy_n_chars;
  143. // Points to current character in buffer.
  144. char* yy_c_buf_p;
  145. int yy_init; // whether we need to initialize
  146. int yy_start; // start state number
  147. // Flag which is used to allow yywrap()'s to do buffer switches
  148. // instead of setting up a fresh yyin. A bit of a hack ...
  149. int yy_did_buffer_switch_on_eof;
  150. size_t yy_buffer_stack_top; /**< index of top of stack. */
  151. size_t yy_buffer_stack_max; /**< capacity of stack. */
  152. yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
  153. void yyensure_buffer_stack(void);
  154. // The following are not always needed, but may be depending
  155. // on use of certain flex features (like REJECT or yymore()).
  156. yy_state_type yy_last_accepting_state;
  157. char* yy_last_accepting_cpos;
  158. yy_state_type* yy_state_buf;
  159. yy_state_type* yy_state_ptr;
  160. size_t yy_state_buf_max;
  161. char* yy_full_match;
  162. int* yy_full_state;
  163. int yy_full_lp;
  164. int yy_lp;
  165. int yy_looking_for_trail_begin;
  166. int yy_more_flag;
  167. int yy_more_len;
  168. int yy_more_offset;
  169. int yy_prev_more_offset;
  170. };
  171. }
  172. #endif // yyFlexLexer || ! yyFlexLexerOnce