bison-patches
[Top][All Lists]
Advanced

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

Re: ** SPAM? (5.865) ** Re: [RFA] Java skeleton


From: Paolo Bonzini
Subject: Re: ** SPAM? (5.865) ** Re: [RFA] Java skeleton
Date: Mon, 26 Feb 2007 09:37:30 +0100
User-agent: Thunderbird 1.5.0.9 (Macintosh/20061207)


I find it hard to understand when you choose to use the yy prefix and when you don't. For example, what's the difference between yyerror and error when the lexer interface resides in the parser class?

I used it for (almost) all the private members, so that they don't clash with user private members. There are a couple of missing ones for which I attach a patch. Public members are not prefixed.

Instead of "union_name", how about "value_superclass" or something else that's Java-oriented?

What about just "stype"?

IMHO, this is a strange twist on the %pure-parser directive with which Bison users are already familiar. To stay true to the original meaning, I think it would be better for the Java skeleton to ignore %pure-parser as a redundant declaration just as the C++ skeletons do. Some new Java-specific boolean %define's would be better suited to your purposes, I think.

Ok; it's also ok for me, for sure, to remove single_class.  What about this:

1) If a "%code lexer" is given, Bison uses it to define a class YYParser.Lexer class, which is public and non-abstract. If it is not given, Bison defines an interface YYParser.Lexer.

2) If a "%lex-param" is given, a constructor is made which accepts both the lex-param and the parse-param, and creates the YYLexer. The "%lex-param" is an error if "%code lexer" is not given.

4. Provide "%define parser_class_modifiers" and "%define lexer_class_modifiers" to specify abstract, interface, final, or other modifiers on these classes. Contains just public by default?

I don't think the lexer_class_modifiers are necessary. In general, before thinking about this last suggestion I'd like to implement the rest. By the way, the only valid modifiers for the parser are public, and at most one of abstract/final.

Paolo
2007-02-26  Paolo Bonzini  <address@hidden>

        * data/lalr1.java (Stack): Rename to YYStack.
        (debugStream): Rename to yyDebugStream.
        (yyrecovering): Rename to recovering.

Index: data/lalr1.java
===================================================================
RCS file: /sources/bison/bison/data/lalr1.java,v
retrieving revision 1.2
diff -u -r1.2 lalr1.java
--- data/lalr1.java     5 Feb 2007 09:58:04 -0000       1.2
+++ data/lalr1.java     26 Feb 2007 08:34:49 -0000
@@ -95,7 +95,7 @@
 b4_token_enums(b4_tokens)
 
   b4_locations_if([[
-  private ]b4_location_type[ yylloc (Stack rhs, int n)
+  private ]b4_location_type[ yylloc (YYStack rhs, int n)
   {
     if (n > 0)
       return new ]b4_location_type[ (rhs.locationAt (1).begin, rhs.locationAt 
(n).end);
@@ -170,19 +170,19 @@
     b4_parse_param_cons[
   }
 
-  private java.io.PrintStream debugStream = System.err;
+  private java.io.PrintStream yyDebugStream = System.err;
 
   /**
    * Return the <tt>PrintStream</tt> on which the debugging output is
    * printed.
    */
-  public final java.io.PrintStream getDebugStream () { return debugStream; }
+  public final java.io.PrintStream getDebugStream () { return yyDebugStream; }
 
   /**
    * Set the <tt>PrintStream</tt> on which the debug output is printed.
    * @@param s The stream that is used for debugging output.
    */
-  public final void setDebugStream(java.io.PrintStream s) { debugStream = s; }
+  public final void setDebugStream(java.io.PrintStream s) { yyDebugStream = s; 
}
 
   private int yydebug = 0;
 
@@ -216,10 +216,10 @@
 
   [protected final void yycdebug (String s) {
     if (yydebug > 0)
-      debugStream.println (s);
+      yyDebugStream.println (s);
   }
 
-  private final class Stack {
+  private final class YYStack {
     private int[] stateStack = new int[16];
     ]b4_locations_if([[private ]b4_location_type[[] locStack = new 
]b4_location_type[[16];]])[
     private ]b4_union_name[[] valueStack = new ]b4_union_name[[16];
@@ -323,12 +323,12 @@
    * Return whether error recovery is being done.  In this state, the parser
    * reads token until it reaches a known state, and then restarts normal
    * operation.  */
-  public final boolean yyrecovering ()
+  public final boolean recovering ()
   {
     return yyerrstatus_ == 0;
   }
 
-  private int yyaction (int yyn, Stack yystack, int yylen)
+  private int yyaction (int yyn, YYStack yystack, int yylen)
   {
     ]b4_union_name[ yyval;
     ]b4_locations_if([b4_location_type[ yyloc = yylloc (yystack, yylen);]])[
@@ -438,7 +438,7 @@
     int yylen = 0;
     int yystate = 0;
 
-    Stack yystack = new Stack ();
+    YYStack yystack = new YYStack ();
 
     /* Error handling.  */
     int yynerrs_ = 0;
@@ -479,7 +479,7 @@
       case YYNEWSTATE:
         yycdebug ("Entering state " + yystate + "\n");
         if (yydebug > 0)
-          yystack.print (debugStream);
+          yystack.print (yyDebugStream);
     
         /* Accept?  */
         if (yystate == yyfinal_)
@@ -651,7 +651,7 @@
            yystack.pop ();
            yystate = yystack.stateAt (0);
            if (yydebug > 0)
-             yystack.print (debugStream);
+             yystack.print (yyDebugStream);
           }
     
        ]b4_locations_if([
@@ -827,7 +827,7 @@
   };
 
   // Report on the debug stream that the rule yyrule is going to be reduced.
-  private void yy_reduce_print (int yyrule, Stack yystack)
+  private void yy_reduce_print (int yyrule, YYStack yystack)
   {
     if (yydebug == 0)
       return;

reply via email to

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