/usr.bin/lex/FlexLexer.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 186 lines · 90 code · 41 blank · 55 comment · 1 complexity · 12e671e5e64701e0521642f2f120e358 MD5 · raw file

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