FlexLexer.h 6.0 KB

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