help-bison
[Top][All Lists]
Advanced

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

Re: Proposals for various changes to the Java parser


From: Di-an JAN
Subject: Re: Proposals for various changes to the Java parser
Date: Sat, 8 Nov 2008 11:09:37 -0800 (PST)

On Tue, 28 Oct 2008, Paolo Bonzini wrote:

Date: Tue, 28 Oct 2008 18:59:16 +0100
From: Paolo Bonzini <address@hidden>
To: address@hidden, address@hidden
Subject: Proposals for various changes to the Java parser

Ideas for changing the generated Java parsers.  I can implement most of
these.  Comments on the interface and semantics would be appreciated.

This is great material, thanks.

1. The parser class can be declared public and/or abstract by using the
``%define public'' and ``%define abstract'' directives.  I can add the
other Java class modifiers with ``%define final'' and ``%define strictfp''
and ``%define annotations "@..."'' directives (plural, since %define's
are not combined, but must be specified in the same %define) to be complete.
Or, we can have a single ``%define parser_class_modifiers "..."'' to
specify all modifiers together.  Or both.
Implemented ``%define final/strictfp''.

I already have your patch for these, right?  For (1), Annotations would
be nice, but not high priority of course.

9. Document ``bisonVersion'' and ``bisonSkeleton'' as part of the ``public''
interface.

Yes, thanks.

10. If ``%verbose-error'' is not used, do not generate code for it.

Not top priority, but I would not oppose this.  I thought javac could in
principle elide it, but maybe it does not because native methods can set
final and private fields.

Document that ``errorVerbose'' can be changed given ``%verbose-error''.
Or make it ``yyErrorVerbose'' and provide getter and setter like ``%debug''.

Latter option is definitely better.

13. Make the yyerror functions public.  Otherwise, it's a member function
of the lexer, which is not available if defined with ``%code lexer {...}''.
Even without ``%code lexer {...}'', users shouldn't have to save a reference
to the lexer just to call its yyerror when it's already saved in the parser.

Ok.

17. Allow gcj version < 4.3 to be used in the testsuite.  Currently
(in gnulib/m4/javacomp.m4), for gcj version < 4.3, only
``-source 1.4 && -target 1.4'' and ``-source 1.3 && -target 1.4''
are allowed.  According th the comments there, these gcj really does
target 1.4.  I guess we can relax that, or use -source 1.3 -target 1.4
for bison's configure.ac ``gt_JAVACOMP([1.3], [1.4])''.
I check that ``javac -source 1.3 -target 1.4'' works with JDK 1.6.
By the way, gcj 3.4.4 is the ``system'' compiler on Cygwin.

Good.

On Wed, 29 Oct 2008, Paolo Bonzini wrote:

Date: Wed, 29 Oct 2008 20:06:16 +0100
From: Paolo Bonzini <address@hidden>
To: Di-an JAN <address@hidden>
Cc: address@hidden
Subject: Re: Proposals for various changes to the Java parser

20. Put EOF and other token type names in the Lexer interface instead.
These names are supposed to be returned from the Lexer, so why require
extra qualification (when not using ``%code lexer {...}'')? Also, there
is no use for these names in the parser except to pass to yy_translate_
to get the internal symbol number and get some info on the grammar.
And
YYBACKUP and yychar is not currently supported by Java.
In any case, use within the lexer would be much more common than in the
parser.

Okay.

21. Add ``$code init {...}'' for code added to the start of the
generated parser constructor.  This is particularly important with
``%define extends'' to allow the superclass to be initialized. Also
add
``%define init_throws''.

Okay.

Paolo

Here's what I have completed.  I also added the autotest keyword "java"
so we can do:

make check TESTSUITEFLAGS="-k java"

2008-11-07  Di-an Jan  <address@hidden>

        General Java skeleton improvements.
        * configure.ac (gt_JAVACOMP): Request target of 1.4, which allows
        using gcj < 4.3 in the testsuite, according to comments in
        gnulib/m4/javacomp.m4.
        * data/java.m4 (stype, parser_class_name, lex_throws, throws,
        location_type, position_type): Remove extraneous brackets from
        b4_percent_define_default.
        (b4_lex_param, b4_parse_param): Remove extraneous brackets from
        m4_define and m4_define_default.
        * data/lalr1.java (b4_pre_prologue): Change to b4_user_post_prologue,
        which marks the end of user code with appropriate syncline, like all
        the other skeletons.
        (b4_user_post_prologue): Add.  Don't silently drop.
        (yylex): Remove.
        (parse): Inline yylex.
        * doc/bison.texinfo (bisonVersion, bisonSkeleton): Document.
        (%{...%}): Fix typo of %code imports.
        * tests/java.at (AT_JAVA_COMPILE): Add "java" keyword.

        Support annotations on parser class with %define annotations.
        * data/lalr1.java (annotations): Add to parser class modifier.
        * doc/bison.texinfo (Java Parser Interface): Document
        %define annotations.
        (Java Declarations Summary): Document %define annotations.
        * tests/java.at (Java parser class modifiers): Test annotations.

        Do not generate code for %error-verbose unless requested.
        * data/lalr1.java (errorVerbose): Rename to yyErrorVerbose.
        Make private.  Make conditional on %error-verbose.
        (getErrorVerbose, setErrorVerbose): New.
        (yytnamerr_): Make conditional on %error-verbose.
        (yysyntax_error): Make some code conditional on %error-verbose.
        * doc/bison.texinfo (Java Bison Interface): Remove the parts
        about %error-verbose having no effect.
        (getErrorVerbose, setErrorVerbose): Document.

        Move constants for token names to Lexer interface.
        * data/lalr1.java (Lexer): Move EOF, b4_token_enums(b4_tokens) here.
        * data/java.m4 (b4_token_enum): Indent for move to Lexer interface.
        (parse): Qualify EOF to Lexer.EOF.
        * doc/bison.texinfo (Java Parser Interface): Move documentation of
        EOF and token names to Java Lexer Interface.
        * tests/java.at (_AT_DATA_JAVA_CALC_Y): Remove Calc qualifier.

        Make yyerror public.
        * data/lalr1.java (Lexer.yyerror): Use longer parameter name.
        (yyerror): Change to public.  Add Javadoc comments.  Use longer
        parameter names.  Make the body rather than the declarator
        conditional on %locations.
        * doc/bison.texinfo (yyerror): Document.  Don't mark as protected.

        Allow user to add code to the constructor with %code init.
        * data/java.m4 (b4_init_throws): New, for %define init_throws.
        * data/lalr1.java (YYParser.YYParser): Add b4_init_throws.
        Add %code init to the front of the constructor body.
        * doc/bison.texinfo (YYParser.YYParser): Document %code init
        and %define init_throws.
        (Java Declarations Summary): Document %code init and
        %define init_throws.
        * tests/java.at (Java %parse-param and %lex-param): Adjust grep.
        (Java constructor init and init_throws): Add tests.



 data/java.m4      |   25 +++++++------
 data/lalr1.java   |  100 ++++++++++++++++++++++++++++++++++++-----------------
 doc/bison.texinfo |   73 ++++++++++++++++++++++++++++++--------
 tests/java.at     |   61 ++++++++++++++++++++++++--------
 4 files changed, 185 insertions(+), 74 deletions(-)

diff --git a/data/java.m4 b/data/java.m4
index b3dbd3b..9c2835d 100644
--- a/data/java.m4
+++ b/data/java.m4
@@ -125,8 +125,8 @@ m4_define([b4_null], [null])
 # ---------------------------------------
 # Output the definition of this token as an enum.
 m4_define([b4_token_enum],
-[  /** Token number, to be returned by the scanner.  */
-  public static final int $1 = $2;
+[    /** Token number, to be returned by the scanner.  */
+    static final int $1 = $2;
 ])


@@ -154,24 +154,27 @@ m4_define([b4_case], [  case $1:
 ## ---------------- ##

 m4_define([b4_yystype], [b4_percent_define_get([[stype]])])
-b4_percent_define_default([[stype]], [[Object]])])
+b4_percent_define_default([[stype]], [[Object]])

 # %name-prefix
 m4_define_default([b4_prefix], [[YY]])

-b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])])
+b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
 m4_define([b4_parser_class_name], 
[b4_percent_define_get([[parser_class_name]])])

-b4_percent_define_default([[lex_throws]], [[java.io.IOException]])])
+b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
 m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])

-b4_percent_define_default([[throws]], [])])
+b4_percent_define_default([[throws]], [])
 m4_define([b4_throws], [b4_percent_define_get([[throws]])])

-b4_percent_define_default([[location_type]], [Location])])
+b4_percent_define_default([[init_throws]], [])
+m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])])
+
+b4_percent_define_default([[location_type]], [Location])
 m4_define([b4_location_type], [b4_percent_define_get([[location_type]])])

-b4_percent_define_default([[position_type]], [Position])])
+b4_percent_define_default([[position_type]], [Position])
 m4_define([b4_position_type], [b4_percent_define_get([[position_type]])])


@@ -218,9 +221,9 @@ m4_define([b4_rhs_location],
 # it to be single quoted.  Same for b4_parse_param.

 # TODO: should be in bison.m4
-m4_define_default([b4_lex_param], [[]]))
-m4_define([b4_lex_param], b4_lex_param))
-m4_define([b4_parse_param], b4_parse_param))
+m4_define_default([b4_lex_param], [[]])
+m4_define([b4_lex_param], b4_lex_param)
+m4_define([b4_parse_param], b4_parse_param)

 # b4_lex_param_decl
 # -------------------
diff --git a/data/lalr1.java b/data/lalr1.java
index c855a75..f4a861b 100644
--- a/data/lalr1.java
+++ b/data/lalr1.java
@@ -29,14 +29,16 @@ b4_copyright([Skeleton implementation for Bison LALR(1) 
parsers in Java],

 b4_percent_define_ifdef([package], [package b4_percent_define_get([package]);
 ])[/* First part of user declarations.  */
-]b4_pre_prologue
+]b4_user_pre_prologue
+b4_user_post_prologue
 b4_percent_code_get([[imports]])
 [/**
  * A Bison parser, automatically generated from <tt>]m4_bpatsubst(b4_file_name, 
[^"\(.*\)"$], [\1])[</tt>.
  *
  * @@author LALR (1) parser skeleton written by Paolo Bonzini.
  */
-]b4_public_if([public ])dnl
+]b4_percent_define_get3([annotations], [], [ ])dnl
+b4_public_if([public ])dnl
 b4_abstract_if([abstract ])dnl
 b4_final_if([final ])dnl
 b4_strictfp_if([strictfp ])dnl
@@ -45,9 +47,22 @@ b4_percent_define_get3([extends], [ extends ])dnl
 b4_percent_define_get3([implements], [ implements ])[
 {
   ]b4_identification[
-
+]b4_error_verbose_if([[
   /** True if verbose error messages are enabled.  */
-  public boolean errorVerbose = ]b4_flag_value([error_verbose]);
+  private boolean yyErrorVerbose = true;
+
+  /**
+   * Return whether verbose error messages are enabled.
+   */
+  public final boolean getErrorVerbose() { return yyErrorVerbose; }
+
+  /**
+   * Set the verbosity of error messages.
+   * @@param verbose True to request verbose error messages.
+   */
+  public final void setErrorVerbose(boolean verbose)
+  { yyErrorVerbose = verbose; }
+]])

 b4_locations_if([[
   /**
@@ -93,11 +108,6 @@ b4_locations_if([[

 ]])

-[  /** Token returned by the scanner to signal the end of its input.  */
-  public static final int EOF = 0;]
-
-b4_token_enums(b4_tokens)
-
   b4_locations_if([[
   private ]b4_location_type[ yylloc (YYStack rhs, int n)
   {
@@ -112,6 +122,11 @@ b4_token_enums(b4_tokens)
    * parser <tt>]b4_parser_class_name[</tt>.
    */
   public interface Lexer {
+    /** Token returned by the scanner to signal the end of its input.  */
+    public static final int EOF = 0;
+
+]b4_token_enums(b4_tokens)[
+
     ]b4_locations_if([[/**
      * Method to retrieve the beginning position of the last scanned token.
      * @@return the position at which the last scanned token starts.  */
@@ -140,8 +155,8 @@ b4_token_enums(b4_tokens)
      *
      * ]b4_locations_if([[@@param loc The location of the element to which the
      *                error message is related]])[
-     * @@param s The string for the error message.  */
-     void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String s);]
+     * @@param msg The string for the error message.  */
+     void yyerror (]b4_locations_if([b4_location_type[ loc, ]])[String msg);]
   }

   b4_lexer_if([[private class YYLexer implements Lexer {
@@ -157,7 +172,9 @@ b4_lexer_if([[
   /**
    * Instantiates the Bison-generated parser.
    */
-  public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) {
+  public ]b4_parser_class_name (b4_parse_param_decl([b4_lex_param_decl])[) 
]b4_maybe_throws([b4_init_throws])[
+  {
+    ]b4_percent_code_get([[init]])[
     this.yylexer = new YYLexer(]b4_lex_param_call[);
     ]b4_parse_param_cons[
   }
@@ -167,7 +184,9 @@ b4_lexer_if([[
    * Instantiates the Bison-generated parser.
    * @@param yylexer The scanner that will supply tokens to the parser.
    */
-  b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ 
(]b4_parse_param_decl([[Lexer yylexer]])[) {
+  b4_lexer_if([[protected]], [[public]]) b4_parser_class_name[ 
(]b4_parse_param_decl([[Lexer yylexer]])[) ]b4_maybe_throws([b4_init_throws])[
+  {
+    ]b4_percent_code_get([[init]])[
     this.yylexer = yylexer;
     ]b4_parse_param_cons[
   }
@@ -201,20 +220,35 @@ b4_lexer_if([[
    */
   public final void setDebugLevel(int level) { yydebug = level; }

-  private final int yylex () ]b4_maybe_throws([b4_lex_throws]) [{
-    return yylexer.yylex ();
+  /**
+   * Print an error message via the lexer.
+   *]b4_locations_if([[ Use a <code>null</code> location.]])[
+   * @@param msg The error message.
+   */
+  public final void yyerror (String msg)
+  {
+    yylexer.yyerror (]b4_locations_if([[(]b4_location_type[)null, ]])[msg);
   }
-  protected final void yyerror (]b4_locations_if([b4_location_type[ loc, 
]])[String s) {
-    yylexer.yyerror (]b4_locations_if([loc, ])[s);
+]b4_locations_if([[
+  /**
+   * Print an error message via the lexer.
+   * @@param loc The location associated with the message.
+   * @@param msg The error message.
+   */
+  public final void yyerror (]b4_location_type[ loc, String msg)
+  {
+    yylexer.yyerror (loc, msg);
   }

-  ]b4_locations_if([
-  protected final void yyerror (String s) {
-    yylexer.yyerror ((]b4_location_type[)null, s);
-  }
-  protected final void yyerror (]b4_position_type[ loc, String s) {
-    yylexer.yyerror (new ]b4_location_type[ (loc), s);
-  }])
+  /**
+   * Print an error message via the lexer.
+   * @@param pos The position associated with the message.
+   * @@param msg The error message.
+   */
+  public final void yyerror (]b4_position_type[ pos, String msg)
+  {
+    yylexer.yyerror (new ]b4_location_type[ (pos), msg);
+  }]])

   [protected final void yycdebug (String s) {
     if (yydebug > 0)
@@ -372,6 +406,7 @@ b4_lexer_if([[
     return YYNEWSTATE;
   }

+]b4_error_verbose_if([[
   /* Return YYSTR after stripping away unnecessary quotes and
      backslashes, so that it's suitable for yyerror.  The heuristic is
      that double-quoting is unnecessary unless the string contains an
@@ -406,6 +441,7 @@ b4_lexer_if([[

     return yystr;
   }
+]])[

   /*--------------------------------.
   | Print this symbol on YYOUTPUT.  |
@@ -499,7 +535,7 @@ m4_popdef([b4_at_dollar])])dnl
         if (yychar == yyempty_)
           {
            yycdebug ("Reading a token: ");
-           yychar = yylex ();]
+           yychar = yylexer.yylex ();]
             b4_locations_if([[
            yylloc = new ]b4_location_type[(yylexer.getStartPos (),
                                            yylexer.getEndPos ());]])
@@ -507,9 +543,9 @@ m4_popdef([b4_at_dollar])])dnl
           }

         /* Convert token to internal form.  */
-        if (yychar <= EOF)
+        if (yychar <= Lexer.EOF)
           {
-           yychar = yytoken = EOF;
+           yychar = yytoken = Lexer.EOF;
            yycdebug ("Now at end of input.\n");
           }
         else
@@ -594,10 +630,10 @@ m4_popdef([b4_at_dollar])])dnl
            /* If just tried and failed to reuse lookahead token after an
             error, discard it.  */

-           if (yychar <= EOF)
+           if (yychar <= Lexer.EOF)
              {
              /* Return failure if at end of input.  */
-             if (yychar == EOF)
+             if (yychar == Lexer.EOF)
                return false;
              }
            else
@@ -682,8 +718,8 @@ m4_popdef([b4_at_dollar])])dnl

   // Generate an error message.
   private String yysyntax_error (int yystate, int tok)
-  {
-    if (errorVerbose)
+  {]b4_error_verbose_if([[
+    if (yyErrorVerbose)
       {
         int yyn = yypact_[yystate];
         if (yypact_ninf_ < yyn && yyn <= yylast_)
@@ -719,7 +755,7 @@ m4_popdef([b4_at_dollar])])dnl
            return res.toString ();
           }
       }
-
+]])[
     return "syntax error";
   }

diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index 6570c0c..c137a25
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -8780,12 +8780,12 @@ No header file can be generated for Java parsers.  Do 
not use the
 @code{%defines} directive or the @option{-d}/@option{--defines} options.

 @c FIXME: Possible code change.
-Currently, support for debugging and verbose errors are always compiled
+Currently, support for debugging is always compiled
 in.  Thus the @code{%debug} and @code{%token-table} directives and the
 @option{-t}/@option{--debug} and @option{-k}/@option{--token-table}
 options have no effect.  This may change in the future to eliminate
-unused code in the generated parser, so use @code{%debug} and
address@hidden explicitly if needed.  Also, in the future the
+unused code in the generated parser, so use @code{%debug} explicitly
+if needed.  Also, in the future the
 @code{%token-table} directive might enable a public interface to
 access the token names and codes.

@@ -8895,6 +8895,8 @@ according to the Java language specification, the name of 
the @file{.java}
 file should match the name of the class in this case.  Similarly, you can
 use @code{abstract}, @code{final} and @code{strictfp} with the
 @code{%define} declaration to add other modifiers to the parser class.
+A single @code{%define annotations "@var{annotations}"} directive can
+be used to add any number of annotations to the parser class.

 The Java package name of the parser class can be specified using the
 @code{%define package} directive.  The superclass and the implemented
@@ -8908,21 +8910,19 @@ these inner class/interface, and the members described 
in the interface
 below, all the other members and fields are preceded with a @code{yy} or
 @code{YY} prefix to avoid clashes with user code.

address@hidden FIXME: The following constants and variables are still 
undocumented:
address@hidden @code{bisonVersion}, @code{bisonSkeleton} and 
@code{errorVerbose}.
-
 The parser class can be extended using the @code{%parse-param}
 directive. Each occurrence of the directive will add a @code{protected
 final} field to the parser class, and an argument to its constructor,
 which initialize them automatically.

-Token names defined by @code{%token} and the predefined @code{EOF} token
-name are added as constant fields to the parser class.
-
 @deftypeop {Constructor} {YYParser} {} YYParser (@var{lex_param}, @dots{}, 
@var{parse_param}, @dots{})
 Build a new parser object with embedded @code{%code lexer}.  There are
 no parameters, unless @code{%parse-param}s and/or @code{%lex-param}s are
 used.
+
+Use @code{%code init} for code added to the start of the constructor
+body. This is especially useful to initialize superclasses. Use
address@hidden init_throws} to specify any uncatch exceptions.
 @end deftypeop

 @deftypeop {Constructor} {YYParser} {} YYParser (Lexer @var{lexer}, 
@var{parse_param}, @dots{})
@@ -8932,6 +8932,10 @@ additional parameters unless @code{%parse-param}s are 
used.
 If the scanner is defined by @code{%code lexer}, this constructor is
 declared @code{protected} and is called automatically with a scanner
 created with the correct @code{%lex-param}s.
+
+Use @code{%code init} for code added to the start of the constructor
+body. This is especially useful to initialize superclasses. Use
address@hidden init_throws} to specify any uncatch exceptions.
 @end deftypeop

 @deftypemethod {YYParser} {boolean} parse ()
@@ -8939,6 +8943,21 @@ Run the syntactic analysis, and return @code{true} on 
success,
 @code{false} otherwise.
 @end deftypemethod

address@hidden {YYParser} {boolean} getErrorVerbose ()
address@hidden {YYParser} {void} setErrorVerbose (boolean @var{verbose})
+Get or set the option to produce verbose error messages.  These are only
+available with the @code{%error-verbose} directive, which also turn on
+verbose error messages.
address@hidden deftypemethod
+
address@hidden {YYParser} {void} yyerror (String @var{msg})
address@hidden {YYParser} {void} yyerror (Position @var{pos}, String @var{msg})
address@hidden {YYParser} {void} yyerror (Location @var{loc}, String @var{msg})
+Print an error message using the @code{yyerror} method of the scanner
+instance in use. The @code{Location} and @code{Position} parameters are
+available only if location tracking is active.
address@hidden deftypemethod
+
 @deftypemethod {YYParser} {boolean} recovering ()
 During the syntactic analysis, return @code{true} if recovering
 from a syntax error.
@@ -8957,6 +8976,11 @@ Get or set the tracing level.  Currently its value is 
either 0, no trace,
 or nonzero, full tracing.
 @end deftypemethod

address@hidden {Constant} {YYParser} {String} {bisonVersion}
address@hidden {Constant} {YYParser} {String} {bisonSkeleton}
+Identify the Bison version and skeleton used to generate this parser.
address@hidden deftypecv
+

 @node Java Scanner Interface
 @subsection Java Scanner Interface
@@ -8967,7 +8991,9 @@ or nonzero, full tracing.
 There are two possible ways to interface a Bison-generated Java parser
 with a scanner: the scanner may be defined by @code{%code lexer}, or
 defined elsewhere.  In either case, the scanner has to implement the
address@hidden inner interface of the parser class.
address@hidden inner interface of the parser class.  This interface also
+contain constants for all user-defined token names and the predefined
address@hidden token.

 In the first case, the body of the scanner class is placed in
 @code{%code lexer} blocks.  If you want to pass parameters from the
@@ -9091,11 +9117,12 @@ operation.
 @xref{Error Recovery}.
 @end deftypefn

address@hidden  {Function} {protected void} yyerror (String msg)
address@hidden {Function} {protected void} yyerror (Position pos, String msg)
address@hidden {Function} {protected void} yyerror (Location loc, String msg)
address@hidden  {Function} {void} yyerror (String @var{msg})
address@hidden {Function} {void} yyerror (Position @var{loc}, String @var{msg})
address@hidden {Function} {void} yyerror (Location @var{loc}, String @var{msg})
 Print an error message using the @code{yyerror} method of the scanner
-instance in use.
+instance in use. The @code{Location} and @code{Position} parameters are
+available only if location tracking is active.
 @end deftypefn


@@ -9211,6 +9238,11 @@ Code inserted just after the @code{package} declaration.
 @xref{Java Differences}.
 @end deffn

address@hidden {Directive} {%code init} @{ @var{code} @dots{} @}
+Code inserted at the beginning of the parser constructor body.
address@hidden Parser Interface}.
address@hidden deffn
+
 @deffn {Directive} {%code lexer} @{ @var{code} @dots{} @}
 Code added to the body of a inner lexer class within the parser class.
 @xref{Java Scanner Interface}.
@@ -9223,7 +9255,7 @@ Code (after the second @code{%%}) appended to the end of 
the file,
 @end deffn

 @deffn {Directive} address@hidden @var{code} @dots{} address@hidden
-Not supported.  Use @code{%code import} instead.
+Not supported.  Use @code{%code imports} instead.
 @xref{Java Differences}.
 @end deffn

@@ -9232,6 +9264,11 @@ Whether the parser class is declared @code{abstract}.  
Default is false.
 @xref{Java Bison Interface}.
 @end deffn

address@hidden {Directive} {%define annotations} "@var{annotations}"
+The Java annotations for the parser class.  Default is none.
address@hidden Bison Interface}.
address@hidden deffn
+
 @deffn {Directive} {%define extends} "@var{superclass}"
 The superclass of the parser class.  Default is none.
 @xref{Java Bison Interface}.
@@ -9248,6 +9285,12 @@ Default is none.
 @xref{Java Bison Interface}.
 @end deffn

address@hidden {Directive} {%define init_throws} "@var{exceptions}"
+The exceptions thrown by @code{%code init} from the parser class
+constructor.  Default is none.
address@hidden Parser Interface}.
address@hidden deffn
+
 @deffn {Directive} {%define lex_throws} "@var{exceptions}"
 The exceptions thrown by the @code{yylex} method of the lexer, a
 comma-separated list.  Default is @code{java.io.IOException}.
diff --git a/tests/java.at b/tests/java.at
index a3e1a0e..1e05d13 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -148,7 +148,7 @@ AT_LOCATION_IF([[
     int ttype = st.nextToken ();
     ]AT_LOCATION_IF([[yystartpos = yyendpos;]])[
     if (ttype == st.TT_EOF)
-      return Calc.EOF;
+      return EOF;

     else if (ttype == st.TT_EOL)
       {
@@ -159,7 +159,7 @@ AT_LOCATION_IF([[
     else if (ttype == st.TT_WORD)
       {
         yylval = new Integer (st.sval);
-        return Calc.NUM;
+        return NUM;
       }

     else
@@ -225,7 +225,8 @@ m4_define([AT_DATA_JAVA_CALC_Y],
 # Compile SOURCES into Java class files.  Skip the test if java or javac is
 # not installed.
 m4_define([AT_JAVA_COMPILE],
-[AT_CHECK([test -n "$CONF_JAVA" || exit 77
+[AT_KEYWORDS(java)
+AT_CHECK([test -n "$CONF_JAVA" || exit 77
 test -n "$CONF_JAVAC" || exit 77])
 AT_CHECK([$SHELL ../../../javacomp.sh $1],
          0, [ignore], [ignore])])
@@ -549,6 +550,12 @@ AT_CHECK_JAVA_MINIMAL([[
 %define strictfp]])
 AT_CHECK_JAVA_GREP([[public final strictfp class YYParser]])

+# FIXME: Can't do a Java compile because javacomp.sh is configured for 1.3
+AT_CHECK_JAVA_MINIMAL([[
+%define annotations "/address@hidden @SupressWarnings(\"unchecked\") @SupressWarnings({\"unchecked\", 
\"deprecation\"}) @SupressWarnings(value={\"unchecked\", \"deprecation\"})*/"
+%define public]])
+AT_CHECK_JAVA_GREP([[/address@hidden @SupressWarnings("unchecked") @SupressWarnings({"unchecked", 
"deprecation"}) @SupressWarnings(value={"unchecked", "deprecation"})\*/ public class YYParser]])
+
 AT_CLEANUP


@@ -579,11 +586,11 @@ AT_CLEANUP
 AT_SETUP([Java %parse-param and %lex-param])

 AT_CHECK_JAVA_MINIMAL([])
-AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer) *]])

 AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param1 = parse_param1;]])

 AT_CHECK_JAVA_MINIMAL([[
@@ -591,19 +598,19 @@ AT_CHECK_JAVA_MINIMAL([[
 %parse-param {long parse_param2}]])
 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, 
*long parse_param2) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, 
*long parse_param2) *]])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param1 = parse_param1;]])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param2 = parse_param2;]])

 AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
-AT_CHECK_JAVA_GREP([[ *public YYParser () {]])
-AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
+AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer) *]])

 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%parse-param {int parse_param1}]],
        [], [[return EOF;]])
 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) {]])
-AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) 
{]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
+AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) 
*]])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param1 = parse_param1;]], [2])

 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
@@ -612,21 +619,21 @@ AT_CHECK_JAVA_MINIMAL_W_LEXER([[
        [], [[return EOF;]])
 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) 
{]])
-AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, 
*long parse_param2) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) 
*]])
+AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, 
*long parse_param2) *]])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param1 = parse_param1;]], [2])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param2 = parse_param2;]], [2])

 AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
        [], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1) *]])
 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1);]])

 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
 %lex-param {char lex_param1}
 %lex-param {short lex_param2}]],
        [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) 
{]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2) 
*]])
 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])

 AT_CHECK_JAVA_MINIMAL_W_LEXER([[
@@ -637,9 +644,9 @@ AT_CHECK_JAVA_MINIMAL_W_LEXER([[
        [], [[return EOF;]], [[YYLexer (char lex_param1, short lex_param2) {}]])
 AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
 AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
-AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, 
*int parse_param1, *long parse_param2) {]])
+AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, 
*int parse_param1, *long parse_param2) *]])
 AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
-AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, 
*long parse_param2) {]])
+AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, 
*long parse_param2) *]])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param1 = parse_param1;]], [2])
 AT_CHECK_JAVA_GREP([[[         ]*this.parse_param2 = parse_param2;]], [2])

@@ -735,6 +742,28 @@ AT_CHECK_JAVA_GREP([[ *public boolean parse 
()]AT_JT_parse_throws[ *]])
 AT_CLEANUP


+# ------------------------------------- #
+# Java constructor init and init_throws #
+# ------------------------------------- #
+
+AT_SETUP([Java constructor init and init_throws])
+
+AT_CHECK_JAVA_MINIMAL([[
+%define extends "Thread"
+%code init { super("Test Thread"); if (true) throw new InterruptedException(); 
}
+%define init_throws "InterruptedException"
+%lex-param {int lex_param}]])
+AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new 
InterruptedException();' YYParser.java]])
+
+AT_CHECK_JAVA_MINIMAL_W_LEXER([[
+%define extends "Thread"
+%code init { super("Test Thread"); if (true) throw new InterruptedException(); 
}
+%define init_throws "InterruptedException"]], [], [[return EOF;]])
+AT_CHECK([[grep -q 'super("Test Thread"); if (true) throw new 
InterruptedException();' YYParser.java]])
+
+AT_CLEANUP
+
+
 # --------------------------------------------- #
 # Java stype, position_class and location_class #
 # --------------------------------------------- #
diff --git a/configure.ac b/configure.ac
index adb5271..1a52b34 100644
--- a/configure.ac
+++ b/configure.ac
@@ -145,7 +145,7 @@ AC_SUBST([GCC])
 AC_SUBST([O0CFLAGS],   [`echo $CFLAGS   | sed 's/-O[[0-9]] *//'`])
 AC_SUBST([O0CXXFLAGS], [`echo $CXXFLAGS | sed 's/-O[[0-9]] *//'`])

-gt_JAVACOMP([1.3])
+gt_JAVACOMP([1.3], [1.4])
 gt_JAVAEXEC

 AC_CONFIG_FILES([Makefile




reply via email to

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