bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

yyrestart


From: Akim Demaille
Subject: yyrestart
Date: Sat, 29 Mar 2003 14:29:18 +0100
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.2 (gnu/linux)

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * doc/bison.texinfo (How Can I Reset @code{yyparse}): New.

Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.103
diff -u -u -r1.103 bison.texinfo
--- doc/bison.texinfo 29 Mar 2003 11:26:46 -0000 1.103
+++ doc/bison.texinfo 29 Mar 2003 13:27:44 -0000
@@ -284,6 +284,7 @@
 Frequently Asked Questions
 
 * Parser Stack Overflow::      Breaking the Stack Limits
+* How Can I Reset @code{yyparse}::    @code{yyparse} Keeps some State
 * Strings are Destroyed::      @code{yylval} Loses Track of Strings
 
 Copying This Manual
@@ -6353,6 +6354,7 @@
 
 @menu
 * Parser Stack Overflow::      Breaking the Stack Limits
+* How Can I Reset @code{yyparse}::    @code{yyparse} Keeps some State
 * Strings are Destroyed::      @code{yylval} Loses Track of Strings
 @end menu
 
@@ -6366,6 +6368,89 @@
 
 This question is already addressed elsewhere, @xref{Recursion,
 ,Recursive Rules}.
+
address@hidden How Can I Reset @code{yyparse}
address@hidden How Can I Reset @code{yyparse}
+
+The following phenomenon gives raise to several incarnations,
+resulting in the following typical questions:
+
address@hidden
+I invoke @code{yyparse} several times, and on correct input it works
+properly; but when a parse error is found, all the other calls fail
+too.  How can I reset @code{yyparse}'s error flag?
address@hidden display
+
address@hidden
+or
+
address@hidden
+My parser includes support for a @samp{#include} like feature, in
+which case I run @code{yyparse} from @code{yyparse}.  This fails
+although I did specify I needed a @code{%pure-parser}.
address@hidden display
+
+These problems are not related to Bison itself, but with the Lex
+generated scanners.  Because these scanners use large buffers for
+speed, they might not notice a change of input file.  As a
+demonstration, consider the following source file,
address@hidden:
+
address@hidden
+%{
+#include <stdio.h>
+#include <stdlib.h>
+%}
+%%
+.*\n    ECHO; return 1;
+%%
+int
+yyparse (const char *file)
+{
+  yyin = fopen (file, "r");
+  if (!yyin)
+    exit (2);
+  /* One token only. */
+  yylex ();
+  if (!fclose (yyin))
+    exit (3);
+  return 0;
+}
+
+int
+main ()
+{
+  yyparse ("input");
+  yyparse ("input");
+  return 0;
+}
address@hidden verbatim
+
address@hidden
+If the file @file{input} contains
+
address@hidden
+input:1: Hello,
+input:2: World!
address@hidden verbatim
+
address@hidden
+then instead of getting twice the first line, you get:
+
address@hidden
+$ @kbd{flex -ofirst-line.c first-line.l}
+$ @kbd{gcc  -ofirst-line   first-line.c -ll}
+$ @kbd{./first-line}
+input:1: Hello,
+input:2: World!
address@hidden example
+
+Therefore, whenever you change @code{yyin}, you must tell the Lex
+generated scanner to discard its current buffer, and to switch to the
+new one.  This depends upon your implementation of Lex, see its
+documentation for more.  For instance, in the case of Flex, a simple
+call @samp{yyrestart (yyin)} suffices after each change to
address@hidden
 
 @node Strings are Destroyed
 @section Strings are Destroyed




reply via email to

[Prev in Thread] Current Thread [Next in Thread]