summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Millaway <john43@users.sourceforge.net>2003-03-04 23:43:53 +0000
committerJohn Millaway <john43@users.sourceforge.net>2003-03-04 23:43:53 +0000
commitc066ba3cf3d69bbd95981410aafb7b84a7310da9 (patch)
tree786a67a6df65be6053b09ae03d12c018f71d31e6
parentf4121c7bbf44465afb6cee00677084132aa5df0f (diff)
Added growable buffer stack to C++ scanner as well.
yyensure_buffer_stack is now static.
-rw-r--r--FlexLexer.h11
-rw-r--r--flex.skl43
2 files changed, 43 insertions, 11 deletions
diff --git a/FlexLexer.h b/FlexLexer.h
index e2d764f..12e0dc4 100644
--- a/FlexLexer.h
+++ b/FlexLexer.h
@@ -122,6 +122,9 @@ public:
void yy_delete_buffer( struct yy_buffer_state* b );
void yyrestart( FLEX_STD istream* s );
+ void yypush_buffer_state( struct yy_buffer_state* new_buffer );
+ void yypop_buffer_state(void);
+
virtual int yylex();
virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out );
@@ -152,8 +155,6 @@ protected:
FLEX_STD istream* yyin; // input source for default LexerInput
FLEX_STD ostream* yyout; // output sink for default LexerOutput
- struct yy_buffer_state* yy_current_buffer;
-
// yy_hold_char holds the character lost when yytext is formed.
char yy_hold_char;
@@ -170,6 +171,12 @@ protected:
// instead of setting up a fresh yyin. A bit of a hack ...
int yy_did_buffer_switch_on_eof;
+
+ size_t yy_buffer_stack_top; /*<< index of top of stack. */
+ size_t yy_buffer_stack_max; /*<< capacity of stack. */
+ struct yy_buffer_state ** yy_buffer_stack; /*<< Stack as an array. */
+ void yyensure_buffer_stack(void);
+
// The following are not always needed, but may be depending
// on use of certain flex features (like REJECT or yymore()).
diff --git a/flex.skl b/flex.skl
index 7400974..06f7456 100644
--- a/flex.skl
+++ b/flex.skl
@@ -57,7 +57,8 @@ m4_include(`flexint.h')
/* begin standard C++ headers. */
#include <iostream>
#include <errno.h>
-#include <stdlib.h>
+#include <cstdlib>
+#include <cstring>
/* end standard C++ headers. */
%endif
@@ -441,7 +442,10 @@ void yy_init_buffer YY_PARAMS(( YY_BUFFER_STATE b, FILE *file YY_PROTO_LAST_ARG
void yy_flush_buffer YY_PARAMS(( YY_BUFFER_STATE b YY_PROTO_LAST_ARG ));
void yypush_buffer_state YY_PARAMS(( YY_BUFFER_STATE new_buffer YY_PROTO_LAST_ARG ));
void yypop_buffer_state YY_PARAMS(( YY_PROTO_ONLY_ARG ));
-void yyensure_buffer_stack YY_PARAMS(( YY_PROTO_ONLY_ARG ));
+
+%not-for-header
+static void yyensure_buffer_stack YY_PARAMS(( YY_PROTO_ONLY_ARG ));
+%ok-for-header
#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER YY_CALL_LAST_ARG)
@@ -1129,7 +1133,10 @@ yyFlexLexer::yyFlexLexer( std::istream* arg_yyin, std::ostream* arg_yyout )
yy_start_stack_ptr = yy_start_stack_depth = 0;
yy_start_stack = 0;
- yy_current_buffer = 0;
+ YY_G(yy_buffer_stack) = 0;
+ YY_G(yy_buffer_stack_top) = 0;
+ YY_G(yy_buffer_stack_max) = 0;
+
#ifdef YY_USES_REJECT
yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2];
@@ -1142,14 +1149,14 @@ yyFlexLexer::~yyFlexLexer()
{
delete [] yy_state_buf;
yyfree( yy_start_stack YY_CALL_LAST_ARG );
- yy_delete_buffer( yy_current_buffer YY_CALL_LAST_ARG);
+ yy_delete_buffer( YY_CURRENT_BUFFER YY_CALL_LAST_ARG);
}
void yyFlexLexer::switch_streams( std::istream* new_in, std::ostream* new_out )
{
if ( new_in )
{
- yy_delete_buffer( yy_current_buffer YY_CALL_LAST_ARG);
+ yy_delete_buffer( YY_CURRENT_BUFFER YY_CALL_LAST_ARG);
yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE YY_CALL_LAST_ARG) YY_CALL_LAST_ARG);
}
@@ -1702,12 +1709,17 @@ void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, std::istream* file )
yy_load_buffer_state( YY_CALL_ONLY_ARG );
}
-%if-c-only
+%if-c-or-c++
/** Pushes the new state onto the stack. The new state becomes
* the current state. This function will allocate the stack
* if necessary.
*/
+%if-c-only
void yypush_buffer_state YYFARGS1(YY_BUFFER_STATE,new_buffer)
+%endif
+%if-c++-only
+void yyFlexLexer::yypush_buffer_state (YY_BUFFER_STATE new_buffer)
+%endif
{
if (new_buffer == NULL)
return;
@@ -1734,11 +1746,17 @@ void yypush_buffer_state YYFARGS1(YY_BUFFER_STATE,new_buffer)
}
%endif
-%if-c-only
+
+%if-c-or-c++
/** Removes and DELETES the top of the stack, if present.
* The next element becomes the new top, if present.
*/
+%if-c-only
void yypop_buffer_state YYFARGS0(void)
+%endif
+%if-c++-only
+void yyFlexLexer::yypop_buffer_state (void)
+%endif
{
if (!YY_CURRENT_BUFFER)
return;
@@ -1755,11 +1773,17 @@ void yypop_buffer_state YYFARGS0(void)
}
%endif
-%if-c-only
+
+%if-c-or-c++
/** Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
-void yyensure_buffer_stack YYFARGS0(void)
+%if-c-only
+static void yyensure_buffer_stack YYFARGS0(void)
+%endif
+%if-c++-only
+void yyFlexLexer::yyensure_buffer_stack(void)
+%endif
{
int num_to_alloc;
@@ -1801,6 +1825,7 @@ void yyensure_buffer_stack YYFARGS0(void)
+
#ifndef YY_NO_SCAN_BUFFER
%if-c-only
YY_BUFFER_STATE yy_scan_buffer YYFARGS2( char *,base, yy_size_t ,size)