Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Seeking bison/yacc grammar for Java language

709 views
Skip to first unread message

Evil B

unread,
Apr 29, 2004, 12:03:37 PM4/29/04
to
Hi,

Does anyone have a working yacc/bison grammar for the full java language?

I've been tinkering away at one for a few days, but have hit a roadblock:

When adding 'Type . class' to 'PrimaryNoNewArray' [1], I end up with 10
shift/reduce and 2 reduce/reduce conflicts, and most java sources fail
to parse.

But when I remove this, I only have 4 shift/reduce conflicts, and nearly
all sources parse successfully (except those with 'Type . class'
expressions.

I don't want to battle any longer, in case someone has already solved
the issues and is willing to share their work.

Cheers
EB

[1]
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html,
section 15.8

glen herrmannsfeldt

unread,
May 2, 2004, 9:50:22 PM5/2/04
to
Evil B wrote:

> Does anyone have a working yacc/bison grammar for the full java language?

> I've been tinkering away at one for a few days, but have hit a roadblock:

> When adding 'Type . class' to 'PrimaryNoNewArray' [1], I end up with 10
> shift/reduce and 2 reduce/reduce conflicts, and most java sources fail
> to parse.

It might be that there are some true conflicts in the grammar, resolved
only be the language definition, similar to the way that if-then-else
is resolved in C. (Each else closes the nearest preceding if.)

It is legal to have a class name, method name, and instance name,
and maybe package name all the same, though not recommended for style
reasons. Consider that, and the possible conflicts that might arise.

(I once wrote a JNI static method to read the x86 time stamp counter,
class and method both called rdtsc.)

-- glen

Scott Nicol

unread,
May 2, 2004, 9:48:40 PM5/2/04
to
>Does anyone have a working yacc/bison grammar for the full java language?

Always read the last chapter first, to see how it ends:

http://java.sun.com/docs/books/jls/second_edition/html/syntax.doc.html#52996

--
Scott Nicol
sni...@apk.net

Jose Antonio

unread,
May 8, 2004, 9:10:35 PM5/8/04
to
Evil B escribió:

> Hi,
>
> Does anyone have a working yacc/bison grammar for the full java language?

Compiler GCJ (GNU Compiler for Java) is a front-end of GCC, the parser
is implemented with bison. Source code can be browsed on CVS server.

Regards.


http://gcc.gnu.org/java/

link to parse.y
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/java/parse.y?rev=1.475&content-type=text/x-cvsweb-markup

0 new messages