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
> 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
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
> 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.
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