[antlr-interest] Java 1.5 grammar updated
John Ridgway
john at jacelridge.com
Tue Apr 8 15:44:56 PDT 2008
What compiler are you using? It works for me with javac 1.5.0_13 on
MacOS X 10.5.2. I thought I noticed a message going by that said that
gcj has a problem with it; but that may be my imagination.
Peace
- John
On Apr 8, 2008, at 4:18 PM, Diane Nkonyereza wrote:
>
> Thanks for the replies.
>
> But if it's valid, why wouldn't it work for me. Could be because of
> the java version I'm using (1.5)?
>
> Diane.
> CC: john at jacelridge.com; nkodidi at hotmail.com; antlr-interest at antlr.org
> From: john at jacelridge.com
> To: SWatt at infobal.com
> Subject: Re: [antlr-interest] Java 1.5 grammar updated
> Date: Tue, 8 Apr 2008 15:27:30 -0400
>
> I think that the reason for this is basically historical. It comes
> from C++, where a class definition must be followed by a ";". Java
> decided not to require that semicolon, but then needed some way to
> allow it. If you read the Java Language Specification (3rd edition,
> 2005) by James Gosling et al., section 7.6 specifically says that
> ";" is a valid type declaration; that is, a TypeDeclaration is
> defined as a ClassDeclaration or an InterfaceDeclaration or a ";".
>
> Furthermore it is entirely reasonable to have a Java file with no
> types declared in it. In fact the JLS suggests that package
> annotations occur in a file whose only other content is the package
> declaration. The JLS suggests that "The sole annotated package
> declaration, if it exists, is placed in a source file called package-
> info.java in the directory containing the source files for the
> package. ... Typically package-info.java contains only a package
> declaration, preceded immediately by the annotations on the
> package. While the file could technically contain the source code
> for one or more package-private classes, it would be very bad
> form." (ibid, pp. 158-159).
>
> Peace
> - John
>
>
> On Apr 8, 2008, at 1:04 PM, Stuart Watt wrote:
> Curious! I just replicated this on a different version, so both Sun
> JDK Java 6 on Windows and Sun JDK Java 5 on Linux compiled this file
> OK; interestingly no class file seems to have been created.
>
> I also tried gcj, and managed to break that:
> stuart at stuart-desktop:~$ gcj test.java
> /tmp/ccIIuwWz.jar:0: internal compiler error: in java_parse_file, at
> java/jcf-parse.c:1951
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> For Debian GNU/Linux specific bug reporting instructions,
> see <URL:file:///usr/share/doc/gcc-4.2/README.Bugs>.
> It looks like a good grammar should accept this, but clearly not all
> compilers comply.
>
> It's been ages since my last "internal compiler error" - it's made
> my day!!!
>
> --S
>
>
> Diane Nkonyereza wrote:
> That's strange. I can't compile such a file, I get error : 'class'
> or 'interface' expected.
>
> Diane.
>
>
>
> Date: Tue, 8 Apr 2008 12:43:30 -0400
> From: swatt at infobal.com
> To: nkodidi at hotmail.com
> CC: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Java 1.5 grammar updated
>
> This is the same as the grammar rule in the Java spec at: http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html
>
> I was surprised by this, and being curious, I just successfully
> compiled a Java source file containing only a single semicolon. It
> seems a bit pointless to me, but it is valid Java!
>
> All the best
> Stuart
>
>
> Diane Nkonyereza wrote:
> Hi all,
>
> I have a question on the latest Java grammar. The question is
> related to the typeDeclaration rule.
>
> - What is the ';' in the typeDeclaration Rule? Can someone please
> gives me an example of when the ';' could be an option or is it
> possible to just have ';' in java file and compile it successfully?
>
> typeDeclaration
> : classOrInterfaceDeclaration
> | ';'
> ;
> Regards,
> Diane.
>
>
> > To: antlr-interest at antlr.org
> > From: parrt at cs.usfca.edu
> > Date: Wed, 19 Mar 2008 18:24:45 -0600
> > Subject: [antlr-interest] Java 1.5 grammar updated
> >
> > Hi, thanks to John Ridgway, we have a major set of fixes to Java.g
> >
> > http://www.antlr.org/grammar/1152141644268/Java.g
> >
> > Parses JDK 1.5 source he says.
> >
> > Terence
>
> Get fish-slapping on Messenger Play now!
> --
> This message was scanned by ESVA and is believed to be clean.
> Click here to report this message as spam.
>
> A prize an hour, 24 hours a day. Try Big Snap now!
> --
> This message was scanned by ESVA and is believed to be clean.
> Click here to report this message as spam.
>
>
> A prize an hour, 24 hours a day. Try Big Snap now!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080408/68c0e1a9/attachment.html
More information about the antlr-interest
mailing list