Re: Definitive grammar for Java 1.1?

"Etienne Gagnon" <>
11 Jul 1998 23:43:54 -0400

          From comp.compilers

Related articles
Definitive grammar for Java 1.1? (James Powell) (1998-07-10)
Re: Definitive grammar for Java 1.1? (Etienne Gagnon) (1998-07-11)
Re: Definitive grammar for Java 1.1? (Glenn Kasten) (1998-07-13)
Re: Definitive grammar for Java 1.1? (Joerg Brunsmann) (1998-07-17)
Re: Definitive grammar for Java 1.1? (James Powell) (1998-07-20)
Re: Definitive grammar for Java 1.1? (1998-07-20)
Re: Definitive grammar for Java 1.1? (Scott Stanchfield) (1998-07-21)
| List of all articles for this month |

From: "Etienne Gagnon" <>
Newsgroups: comp.compilers
Date: 11 Jul 1998 23:43:54 -0400
Organization: Compilers Central
References: 98-07-097
Keywords: parse, Java

>Does anyone know if a BNF grammar has been published for Java 1.1? I
>can only find the Java 1.0 grammar at
>, with some notes
>pertaining to 1.1.
>Any pointers or help would be appreciated, thanks,James,

I have included a LALR(1) grammar for Java 1.1 in the SableCC distribution
( This grammar is based on the LALR(1)
grammar from chapter 19 of the Java Language Specification (JLS), to which I
have added the changes proposed in the Inner Classes Specification(ICS)
document, pages 19 to 23. I had to resolve a couple of LALR(1) conflicts
introduced by these changes.

I did run your example through this grammar and I've found 2 errors
according to the specification.

(1) The spurious ";" following the declaration of class A is not allowed by
the grammar of the JLS + ICS.
(2) The construct A() is not allowed, because the grammar for a class
instance creation expression is:

class_instance_creation_expression =
      primary dot new identifier l_parenthese argument_list[opt] r_parenthese

and a "primary" cannot be a simple name.

A semantically equivalent program that can be parsed by the JLS + ICS
grammar would be:

class DemoErrors
{ static class A { }
    synchronized void AMethod()
    { DemoErrors de = new DemoErrors();
        A a = (de).new A();

This version runs without any problem. So what is the real Java 1.1 grammar?
Is it the officially documented grammar, or the grammar accepted by Sun
Microsystems inc. "javac"? I hope it is the former, since the number of bugs
in the later (specially in the area of inner classes) would mean that the
Java 1.1 grammar is a relatively unknown and changing target...

My guts feeling is that the ICS is as buggy (and ambiguous) as javac. I am
still waiting for a complete and precise ISO standard specification for
Java;-) Meanwhile, I will continue to distribute the documented grammar with
SableCC, and hope for the open process to take place.

Etienne Gagnon
Sable Research Group
McGill University

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.