bison-patches
[Top][All Lists]
Advanced

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

Re: Extract the action scanner from the grammar scanner


From: Akim Demaille
Subject: Re: Extract the action scanner from the grammar scanner
Date: Wed, 07 Jun 2006 09:09:49 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

>>> "Akim" == Akim Demaille <address@hidden> writes:

>>> "Akim" == Akim Demaille <address@hidden> writes:

 > I'm installing the patch now.  The work is almost done, but there
 > remains a couple of issues to address.  One significant issue is the
 > fail of the calc++ sample, due to the fact that we are still blindly
 > adding a `;' at the end of user actions.  Unfortunately this is
 > applied in a place where we are not having a user action, but rather a
 > specification of the extra arguments.

 > Of course I plan to solve this in the near future.

The installed fix follows.

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/scan-gram.l: Move the "add a trailing ; to actions" code
        to...
        * src/scan-code.l: here.
        * tests/input.at (Torturing the Scanner): Fix another location
        error.

Index: src/scan-code.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-code.l,v
retrieving revision 1.1
diff -u -u -r1.1 scan-code.l
--- src/scan-code.l 6 Jun 2006 16:40:06 -0000 1.1
+++ src/scan-code.l 7 Jun 2006 07:09:25 -0000
@@ -75,6 +75,9 @@
 %%
 
 %{
+  /* Nesting level of the current code in braces.  */
+  int braces_level IF_LINT (= 0);
+
   /* This scanner is special: it is invoked only once, henceforth
      is expected to return only once.  This initialization is
      therefore done once per action to translate. */
@@ -157,6 +160,30 @@
     warn_at (*loc, _("stray `@'"));
     obstack_sgrow (&obstack_for_string, "@@");
   }
+
+  "{"  STRING_GROW; ++braces_level;
+  "}"  {
+    bool outer_brace = --braces_level < 0;
+
+    /* As an undocumented Bison extension, append `;' before the last
+       brace in braced code, so that the user code can omit trailing
+       `;'.  But do not append `;' if emulating Yacc, since Yacc does
+       not append one.
+
+       FIXME: Bison should warn if a semicolon seems to be necessary
+       here, and should omit the semicolon if it seems unnecessary
+       (e.g., after ';', '{', or '}', each followed by comments or
+       white space).  Such a warning shouldn't depend on --yacc; it
+       should depend on a new --pedantic option, which would cause
+       Bison to warn if it detects an extension to POSIX.  --pedantic
+       should also diagnose other Bison extensions like %yacc.
+       Perhaps there should also be a GCC-style --pedantic-errors
+       option, so that such warnings are diagnosed as errors.  */
+    if (outer_brace && ! yacc_flag)
+      obstack_1grow (&obstack_for_string, ';');
+
+    STRING_GROW;
+  }
 }
 
 <SC_SYMBOL_ACTION>
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.87
diff -u -u -r1.87 scan-gram.l
--- src/scan-gram.l 6 Jun 2006 16:40:06 -0000 1.87
+++ src/scan-gram.l 7 Jun 2006 07:09:25 -0000
@@ -46,7 +46,7 @@
 #include "scan-gram.h"
 
 #define YY_DECL GRAM_LEX_DECL
-   
+
 #define YY_USER_INIT                                   \
    code_start = scanner_cursor = loc->start;           \
 
@@ -543,28 +543,10 @@
   "{"|"<"{splice}"%"  STRING_GROW; braces_level++;
   "%"{splice}">"      STRING_GROW; braces_level--;
   "}" {
-    bool outer_brace = --braces_level < 0;
-
-    /* As an undocumented Bison extension, append `;' before the last
-       brace in braced code, so that the user code can omit trailing
-       `;'.  But do not append `;' if emulating Yacc, since Yacc does
-       not append one.
-
-       FIXME: Bison should warn if a semicolon seems to be necessary
-       here, and should omit the semicolon if it seems unnecessary
-       (e.g., after ';', '{', or '}', each followed by comments or
-       white space).  Such a warning shouldn't depend on --yacc; it
-       should depend on a new --pedantic option, which would cause
-       Bison to warn if it detects an extension to POSIX.  --pedantic
-       should also diagnose other Bison extensions like %yacc.
-       Perhaps there should also be a GCC-style --pedantic-errors
-       option, so that such warnings are diagnosed as errors.  */
-    if (outer_brace && token_type == BRACED_CODE && ! yacc_flag)
-      obstack_1grow (&obstack_for_string, ';');
-
     obstack_1grow (&obstack_for_string, '}');
 
-    if (outer_brace)
+    --braces_level;
+    if (braces_level < 0)
       {
        STRING_FINISH;
        loc->start = code_start;
Index: tests/input.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/input.at,v
retrieving revision 1.44
diff -u -u -r1.44 input.at
--- tests/input.at 6 Jun 2006 16:40:06 -0000 1.44
+++ tests/input.at 7 Jun 2006 07:09:25 -0000
@@ -192,7 +192,7 @@
 [{}
 ])
 AT_CHECK([bison input.y], [1], [],
-[[input.y:1.1-2: syntax error, unexpected {...}
+[[input.y:1.0-1: syntax error, unexpected {...}
 ]])
 
 






reply via email to

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