home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / flex254.zip / FlexLexer.h < prev    next >
C/C++ Source or Header  |  1997-07-26  |  6KB  |  187 lines

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