summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flex.skl16
-rw-r--r--flex.texi4
-rw-r--r--gen.c54
3 files changed, 49 insertions, 25 deletions
diff --git a/flex.skl b/flex.skl
index debc996..7af8c62 100644
--- a/flex.skl
+++ b/flex.skl
@@ -521,6 +521,13 @@ struct yyguts_t
int yylineno_r;
int yy_flex_debug_r;
+#ifdef YY_USES_REJECT
+ yy_state_type *yy_state_buf;
+ yy_state_type *yy_state_ptr;
+ char *yy_full_match;
+ int yy_lp;
+#endif
+
#ifdef YY_TEXT_IS_ARRAY
char yytext_r[YYLMAX];
char *yytext_ptr;
@@ -816,6 +823,11 @@ YY_DECL
YY_USER_INIT;
#endif
+#ifdef YY_USES_REJECT
+ if ( ! YY_G(yy_state_buf) )
+ YY_G(yy_state_buf) = yyalloc(YY_BUF_SIZE + 2 YY_CALL_LAST_ARG);
+#endif
+
if ( ! YY_G(yy_start) )
YY_G(yy_start) = 1; /* first start state */
@@ -1969,6 +1981,10 @@ int yylex_destroy YYFARGS0(void)
}
#endif
+#ifdef YY_USES_REJECT
+ yyfree ( YY_G(yy_state_buf) YY_CALL_LAST_ARG);
+#endif
+
#ifdef YY_REENTRANT
/* Destroy the main struct (reentrant only). */
yyfree ( yyscanner YY_CALL_LAST_ARG );
diff --git a/flex.texi b/flex.texi
index 61cc1a8..cfce223 100644
--- a/flex.texi
+++ b/flex.texi
@@ -4441,6 +4441,10 @@ buffer (16384 bytes) is almost always too large. The ideal size for this
buffer is the length of the longest token expected. Flex will allocate a few
extra bytes for housekeeping.
+@item 16kb for the REJECT state. This will only be allocated if you use REJECT.
+The size is the same as the input buffer, so if you override the size of the
+input buffer, then you automatically override the size of this buffer as well.
+
@item 100 bytes for the start condition stack.
Flex allocates memory for the start condition stack. This is the stack used
for pushing start states, i.e., with yy_push_state(). It will grow if
diff --git a/gen.c b/gen.c
index ef03f99..a8f095a 100644
--- a/gen.c
+++ b/gen.c
@@ -300,8 +300,8 @@ void gen_find_action()
else if ( reject )
{
- indent_puts( "yy_current_state = *--yy_state_ptr;" );
- indent_puts( "yy_lp = yy_accept[yy_current_state];" );
+ indent_puts( "yy_current_state = *--YY_G(yy_state_ptr);" );
+ indent_puts( "YY_G(yy_lp) = yy_accept[yy_current_state];" );
outn(
"find_rule: /* we branch to this label when backing up */" );
@@ -314,10 +314,10 @@ void gen_find_action()
indent_puts( "{" );
indent_puts(
- "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
+ "if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )" );
indent_up();
indent_puts( "{" );
- indent_puts( "yy_act = yy_acclist[yy_lp];" );
+ indent_puts( "yy_act = yy_acclist[YY_G(yy_lp)];" );
if ( variable_trailing_context_rules )
{
@@ -352,9 +352,9 @@ void gen_find_action()
/* Remember matched text in case we back up
* due to REJECT.
*/
- indent_puts( "yy_full_match = yy_cp;" );
- indent_puts( "yy_full_state = yy_state_ptr;" );
- indent_puts( "yy_full_lp = yy_lp;" );
+ indent_puts( "YY_G(yy_full_match) = yy_cp;" );
+ indent_puts( "yy_full_state = YY_G(yy_state_ptr);" );
+ indent_puts( "yy_full_lp = YY_G(yy_lp);" );
}
indent_puts( "}" );
@@ -363,14 +363,14 @@ void gen_find_action()
indent_puts( "else" );
indent_up();
indent_puts( "{" );
- indent_puts( "yy_full_match = yy_cp;" );
- indent_puts( "yy_full_state = yy_state_ptr;" );
- indent_puts( "yy_full_lp = yy_lp;" );
+ indent_puts( "YY_G(yy_full_match) = yy_cp;" );
+ indent_puts( "yy_full_state = YY_G(yy_state_ptr);" );
+ indent_puts( "yy_full_lp = YY_G(yy_lp);" );
indent_puts( "break;" );
indent_puts( "}" );
indent_down();
- indent_puts( "++yy_lp;" );
+ indent_puts( "++YY_G(yy_lp);" );
indent_puts( "goto find_rule;" );
}
@@ -381,7 +381,7 @@ void gen_find_action()
*/
indent_up();
indent_puts( "{" );
- indent_puts( "yy_full_match = yy_cp;" );
+ indent_puts( "YY_G(yy_full_match) = yy_cp;" );
indent_puts( "break;" );
indent_puts( "}" );
indent_down();
@@ -396,8 +396,8 @@ void gen_find_action()
* the beginning, but at the cost of complaints that we're
* branching inside a loop.
*/
- indent_puts( "yy_current_state = *--yy_state_ptr;" );
- indent_puts( "yy_lp = yy_accept[yy_current_state];" );
+ indent_puts( "yy_current_state = *--YY_G(yy_state_ptr);" );
+ indent_puts( "YY_G(yy_lp) = yy_accept[yy_current_state];" );
indent_puts( "}" );
@@ -678,7 +678,7 @@ int worry_about_NULs;
gen_backing_up();
if ( reject )
- indent_puts( "*yy_state_ptr++ = yy_current_state;" );
+ indent_puts( "*YY_G(yy_state_ptr)++ = yy_current_state;" );
}
@@ -747,7 +747,7 @@ void gen_NUL_trans()
*/
indent_puts( "if ( ! yy_is_jam )" );
indent_up();
- indent_puts( "*yy_state_ptr++ = yy_current_state;" );
+ indent_puts( "*YY_G(yy_state_ptr)++ = yy_current_state;" );
indent_down();
}
}
@@ -795,8 +795,10 @@ void gen_start_state()
if ( reject )
{
/* Set up for storing up states. */
- indent_puts( "yy_state_ptr = yy_state_buf;" );
- indent_puts( "*yy_state_ptr++ = yy_current_state;" );
+ outn("#ifdef YY_USES_REJECT");
+ indent_puts( "YY_G(yy_state_ptr) = YY_G(yy_state_buf);" );
+ indent_puts( "*YY_G(yy_state_ptr)++ = yy_current_state;" );
+ outn("#endif");
}
}
}
@@ -1229,11 +1231,12 @@ void make_tables()
if ( reject )
{
+ outn("#ifdef YY_USES_REJECT");
/* Declare state buffer variables. */
- if ( ! C_plus_plus )
+ if ( ! C_plus_plus && ! reentrant )
{
outn(
- "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
+ "static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;" );
outn( "static char *yy_full_match;" );
outn( "static int yy_lp;" );
}
@@ -1259,22 +1262,23 @@ void make_tables()
outn(
"*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\" );
outn(
- "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
+ "yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\" );
if ( variable_trailing_context_rules )
{
outn(
- "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
+ "YY_G(yy_lp) = yy_full_lp; /* restore orig. accepting pos. */ \\" );
outn(
- "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
+ "YY_G(yy_state_ptr) = yy_full_state; /* restore orig. state */ \\" );
outn(
- "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
+ "yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\" );
}
- outn( "++yy_lp; \\" );
+ outn( "++YY_G(yy_lp); \\" );
outn( "goto find_rule; \\" );
outn( "}" );
+ outn("#endif");
}
else