summaryrefslogtreecommitdiffstats
path: root/usr.bin/lex/FlexLexer.h
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/lex/FlexLexer.h')
-rw-r--r--usr.bin/lex/FlexLexer.h96
1 files changed, 53 insertions, 43 deletions
diff --git a/usr.bin/lex/FlexLexer.h b/usr.bin/lex/FlexLexer.h
index feb40b6..6c9a950 100644
--- a/usr.bin/lex/FlexLexer.h
+++ b/usr.bin/lex/FlexLexer.h
@@ -1,6 +1,7 @@
-// $Header: FlexLexer.h,v 1.2 94/01/04 14:57:26 vern Exp $
+// $Header: /home/daffy/u0/vern/flex/RCS/FlexLexer.h,v 1.19 96/05/25 20:43:02 vern Exp $
-// FlexLexer.h -- define classes for lexical analyzers generated by flex
+// FlexLexer.h -- define interfaces for lexical analyzer classes generated
+// by flex
// Copyright (c) 1993 The Regents of the University of California.
// All rights reserved.
@@ -22,19 +23,26 @@
// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-#ifndef __FLEX_LEXER_H
-#define __FLEX_LEXER_H
-
-
-// This file defines two classes. The first, FlexLexer, is an abstract
-// class which specifies the external interface provided to flex C++
-// lexer objects. The second, yyFlexLexer, fills out most of the meat
-// of the lexer class; its internals may vary from lexer to lexer
-// depending on things like whether REJECT is used.
+// This file defines FlexLexer, an abstract class which specifies the
+// external interface provided to flex C++ lexer objects, and yyFlexLexer,
+// which defines a particular lexer class.
//
// If you want to create multiple lexer classes, you use the -P flag
-// to rename each yyFlexLexer to some other xxFlexLexer.
+// to rename each yyFlexLexer to some other xxFlexLexer. You then
+// include <FlexLexer.h> in your other sources once per lexer class:
+//
+// #undef yyFlexLexer
+// #define yyFlexLexer xxFlexLexer
+// #include <FlexLexer.h>
+//
+// #undef yyFlexLexer
+// #define yyFlexLexer zzFlexLexer
+// #include <FlexLexer.h>
+// ...
+#ifndef __FLEX_LEXER_H
+// Never included before - need to define base class.
+#define __FLEX_LEXER_H
#include <iostream.h>
extern "C++" {
@@ -58,46 +66,46 @@ public:
virtual int yylex() = 0;
+ // Call yylex with new input/output sources.
+ int yylex( istream* new_in, ostream* new_out = 0 )
+ {
+ switch_streams( new_in, new_out );
+ return yylex();
+ }
+
+ // Switch to new input/output streams. A nil stream pointer
+ // indicates "keep the current one".
+ virtual void switch_streams( istream* new_in = 0,
+ ostream* new_out = 0 ) = 0;
+
+ int lineno() const { return yylineno; }
+
+ int debug() const { return yy_flex_debug; }
+ void set_debug( int flag ) { yy_flex_debug = flag; }
+
protected:
char* yytext;
int yyleng;
+ int yylineno; // only maintained if you use %option yylineno
+ int yy_flex_debug; // only has effect with -d or "%option debug"
};
+}
+#endif
+
+#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
+// Either this is the first time through (yyFlexLexerOnce not defined),
+// or this is a repeated include to define a different flavor of
+// yyFlexLexer, as discussed in the flex man page.
+#define yyFlexLexerOnce
class yyFlexLexer : public FlexLexer {
public:
// arg_yyin and arg_yyout default to the cin and cout, but we
// only make that assignment when initializing in yylex().
- yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 )
- {
- yyin = arg_yyin;
- yyout = arg_yyout;
- yy_c_buf_p = 0;
- yy_init = 1;
- yy_start = 0;
-
- yy_did_buffer_switch_on_eof = 0;
-
- yy_looking_for_trail_begin = 0;
- yy_more_flag = 0;
- yy_more_len = 0;
-
- yy_start_stack_ptr = yy_start_stack_depth = 0;
- yy_start_stack = 0;
-
- yy_current_buffer = 0;
+ yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 );
-#ifdef YY_USES_REJECT
- yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
-#else
- yy_state_buf = 0;
-#endif
- }
-
- virtual ~yyFlexLexer()
- {
- delete yy_state_buf;
- }
+ virtual ~yyFlexLexer();
void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
struct yy_buffer_state* yy_create_buffer( istream* s, int size );
@@ -105,6 +113,7 @@ public:
void yyrestart( istream* s );
virtual int yylex();
+ virtual void switch_streams( istream* new_in, ostream* new_out );
protected:
virtual int LexerInput( char* buf, int max_size );
@@ -116,6 +125,7 @@ protected:
void yy_load_buffer_state();
void yy_init_buffer( struct yy_buffer_state* b, istream* s );
+ void yy_flush_buffer( struct yy_buffer_state* b );
int yy_start_stack_ptr;
int yy_start_stack_depth;
@@ -168,8 +178,8 @@ protected:
int yy_more_flag;
int yy_more_len;
+ int yy_more_offset;
+ int yy_prev_more_offset;
};
-}
-
#endif
OpenPOWER on IntegriCloud