home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / include / FlexLexer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-12  |  4.7 KB  |  174 lines

  1. // FlexLexer.h -- define classes for lexical analyzers generated by flex
  2.  
  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 are permitted provided
  10. // that: (1) source distributions retain this entire copyright notice and
  11. // comment, and (2) distributions including binaries display the following
  12. // acknowledgement:  ``This product includes software developed by the
  13. // University of California, Berkeley and its contributors'' in the
  14. // documentation or other materials provided with the distribution and in
  15. // all advertising materials mentioning features or use of this software.
  16. // Neither the name of the University nor the names of its contributors may
  17. // be used to endorse or promote products derived from this software without
  18. // 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.  
  23. #ifndef __FLEX_LEXER_H
  24. #define __FLEX_LEXER_H
  25.  
  26.  
  27. // This file defines two classes.  The first, FlexLexer, is an abstract
  28. // class which specifies the external interface provided to flex C++
  29. // lexer objects.  The second, yyFlexLexer, fills out most of the meat
  30. // of the lexer class; its internals may vary from lexer to lexer
  31. // depending on things like whether REJECT is used.
  32. //
  33. // If you want to create multiple lexer classes, you use the -P flag
  34. // to rename each yyFlexLexer to some other xxFlexLexer.
  35.  
  36. #include <iostream.h>
  37.  
  38. extern "C++" {
  39.  
  40. struct yy_buffer_state;
  41. typedef int yy_state_type;
  42.  
  43. class FlexLexer {
  44. public:
  45.     virtual ~FlexLexer()    { }
  46.  
  47.     const char* YYText()    { return yytext; }
  48.     int YYLeng()        { return yyleng; }
  49.  
  50.     virtual void
  51.         yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
  52.     virtual struct yy_buffer_state*
  53.         yy_create_buffer( istream* s, int size ) = 0;
  54.     virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
  55.     virtual void yyrestart( istream* s ) = 0;
  56.  
  57.     virtual int yylex() = 0;
  58.  
  59. protected:
  60.     char* yytext;
  61.     int yyleng;
  62. };
  63.  
  64.  
  65. class yyFlexLexer : public FlexLexer {
  66. public:
  67.     // arg_yyin and arg_yyout default to the cin and cout, but we
  68.     // only make that assignment when initializing in yylex().
  69.     yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
  70.         {
  71.         yyin = arg_yyin;
  72.         yyout = arg_yyout;
  73.         yy_c_buf_p = 0;
  74.         yy_init = 1;
  75.         yy_start = 0;
  76.  
  77.         yy_did_buffer_switch_on_eof = 0;
  78.  
  79.         yy_looking_for_trail_begin = 0;
  80.         yy_more_flag = 0;
  81.         yy_more_len = 0;
  82.  
  83.         yy_start_stack_ptr = yy_start_stack_depth = 0;
  84.         yy_start_stack = 0;
  85.  
  86.         yy_current_buffer = 0;
  87.  
  88. #ifdef YY_USES_REJECT
  89.         yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
  90. #else
  91.         yy_state_buf = 0;
  92. #endif
  93.         }
  94.  
  95.     virtual ~yyFlexLexer()
  96.         {
  97.         delete yy_state_buf;
  98.         }
  99.  
  100.     void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
  101.     struct yy_buffer_state* yy_create_buffer( istream* s, int size );
  102.     void yy_delete_buffer( struct yy_buffer_state* b );
  103.     void yyrestart( istream* s );
  104.  
  105.     virtual int yylex();
  106.  
  107. protected:
  108.     virtual int LexerInput( char* buf, int max_size );
  109.     virtual void LexerOutput( const char* buf, int size );
  110.     virtual void LexerError( const char* msg );
  111.  
  112.     void yyunput( int c, char* buf_ptr );
  113.     int yyinput();
  114.  
  115.     void yy_load_buffer_state();
  116.     void yy_init_buffer( struct yy_buffer_state* b, istream* s );
  117.  
  118.     int yy_start_stack_ptr;
  119.     int yy_start_stack_depth;
  120.     int* yy_start_stack;
  121.  
  122.     void yy_push_state( int new_state );
  123.     void yy_pop_state();
  124.     int yy_top_state();
  125.  
  126.     yy_state_type yy_get_previous_state();
  127.     yy_state_type yy_try_NUL_trans( yy_state_type current_state );
  128.     int yy_get_next_buffer();
  129.  
  130.     istream* yyin;    // input source for default LexerInput
  131.     ostream* yyout;    // output sink for default LexerOutput
  132.  
  133.     struct yy_buffer_state* yy_current_buffer;
  134.  
  135.     // yy_hold_char holds the character lost when yytext is formed.
  136.     char yy_hold_char;
  137.  
  138.     // Number of characters read into yy_ch_buf.
  139.     int yy_n_chars;
  140.  
  141.     // Points to current character in buffer.
  142.     char* yy_c_buf_p;
  143.  
  144.     int yy_init;        // whether we need to initialize
  145.     int yy_start;        // start state number
  146.  
  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.  
  151.     // The following are not always needed, but may be depending
  152.     // on use of certain flex features (like REJECT or yymore()).
  153.  
  154.     yy_state_type yy_last_accepting_state;
  155.     char* yy_last_accepting_cpos;
  156.  
  157.     yy_state_type* yy_state_buf;
  158.     yy_state_type* yy_state_ptr;
  159.  
  160.     char* yy_full_match;
  161.     int* yy_full_state;
  162.     int yy_full_lp;
  163.  
  164.     int yy_lp;
  165.     int yy_looking_for_trail_begin;
  166.  
  167.     int yy_more_flag;
  168.     int yy_more_len;
  169. };
  170.  
  171. }
  172.  
  173. #endif
  174.