FlexLexer.h 5.8 KB

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