home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / useful / include / flexlexer.h < prev    next >
C/C++ Source or Header  |  1993-12-13  |  5KB  |  165 lines

  1. // $Header: /home/daffy/u0/vern/flex/RCS/FlexLexer.h,v 1.8 93/12/11 10:27:02 vern Exp $
  2.  
  3. // FlexLexer.h -- define classes for lexical analyzers generated by flex
  4.  
  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.  
  25. #ifndef __FLEX_LEXER_H
  26. #define __FLEX_LEXER_H
  27.  
  28.  
  29. // This file defines two classes.  The first, FlexLexer, is an abstract
  30. // class which specifies the external interface provided to flex C++
  31. // lexer objects.  The second, yyFlexLexer, fills out most of the meat
  32. // of the lexer class; its internals may vary from lexer to lexer
  33. // depending on things like whether REJECT is used.
  34. //
  35. // If you want to create multiple lexer classes, you use the -P flag
  36. // to rename each yyFlexLexer to some other xxFlexLexer.
  37.  
  38. extern "C++" {
  39.  
  40. #include <iostream.h>
  41.  
  42. struct yy_buffer_state;
  43. typedef int yy_state_type;
  44.  
  45. class FlexLexer {
  46. public:
  47.     virtual ~FlexLexer()    { }
  48.  
  49.     const char* YYText()    { return yytext; }
  50.     int YYLeng()        { return yyleng; }
  51.  
  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( istream* s, int size ) = 0;
  56.     virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
  57.     virtual void yyrestart( istream* s ) = 0;
  58.  
  59.     virtual int yylex() = 0;
  60.  
  61. protected:
  62.     char* yytext;
  63.     int yyleng;
  64. };
  65.  
  66.  
  67. class yyFlexLexer : public FlexLexer {
  68. public:
  69.     // arg_yyin and arg_yyout default to the cin and cout, but we
  70.     // only make that assignment when initializing in yylex().
  71.     yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
  72.         {
  73.         yyin = arg_yyin;
  74.         yyout = arg_yyout;
  75.         yy_c_buf_p = 0;
  76.         yy_init = 1;
  77.         yy_start = 0;
  78.  
  79.         yy_did_buffer_switch_on_eof = 0;
  80.  
  81.         yy_looking_for_trail_begin = 0;
  82.         yy_more_flag = 0;
  83.         yy_more_len = 0;
  84.  
  85.         yy_current_buffer = 0;
  86.  
  87. #ifdef YY_USES_REJECT
  88.         yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
  89. #else
  90.         yy_state_buf = 0;
  91. #endif
  92.         }
  93.  
  94.     virtual ~yyFlexLexer()
  95.         {
  96.         delete yy_state_buf;
  97.         }
  98.  
  99.     void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
  100.     struct yy_buffer_state* yy_create_buffer( istream* s, int size );
  101.     void yy_delete_buffer( struct yy_buffer_state* b );
  102.     void yyrestart( istream* s );
  103.  
  104.     virtual int yylex();
  105.  
  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.  
  111.     void yyunput( int c, char* buf_ptr );
  112.     int yyinput();
  113.  
  114.     void yy_load_buffer_state();
  115.     void yy_init_buffer( struct yy_buffer_state* b, istream* s );
  116.  
  117.     yy_state_type yy_get_previous_state();
  118.     yy_state_type yy_try_NUL_trans( yy_state_type current_state );
  119.     int yy_get_next_buffer();
  120.  
  121.     istream* yyin;    // input source for default LexerInput
  122.     ostream* yyout;    // output sink for default LexerOutput
  123.  
  124.     struct yy_buffer_state* yy_current_buffer;
  125.  
  126.     // yy_hold_char holds the character lost when yytext is formed.
  127.     char yy_hold_char;
  128.  
  129.     // Number of characters read into yy_ch_buf.
  130.     int yy_n_chars;
  131.  
  132.     // Points to current character in buffer.
  133.     char* yy_c_buf_p;
  134.  
  135.     int yy_init;        // whether we need to initialize
  136.     int yy_start;        // start state number
  137.  
  138.     // Flag which is used to allow yywrap()'s to do buffer switches
  139.     // instead of setting up a fresh yyin.  A bit of a hack ...
  140.     int yy_did_buffer_switch_on_eof;
  141.  
  142.     // The following are not always needed, but may be depending
  143.     // on use of certain flex features (like REJECT or yymore()).
  144.  
  145.     yy_state_type yy_last_accepting_state;
  146.     char* yy_last_accepting_cpos;
  147.  
  148.     yy_state_type* yy_state_buf;
  149.     yy_state_type* yy_state_ptr;
  150.  
  151.     char* yy_full_match;
  152.     int* yy_full_state;
  153.     int yy_full_lp;
  154.  
  155.     int yy_lp;
  156.     int yy_looking_for_trail_begin;
  157.  
  158.     int yy_more_flag;
  159.     int yy_more_len;
  160. };
  161.  
  162. }
  163.  
  164. #endif
  165.