[892] in java-interest
Complete LALR grammar for Java now available
daemon@ATHENA.MIT.EDU (Scott Hudson)
Mon Aug 14 04:38:11 1995
From: hudson@cc.gatech.edu (Scott Hudson)
To: java-interest@java.sun.com
Date: Mon, 14 Aug 1995 00:40:37 -0400 (EDT)
Cc: java-interest@cc.gatech.edu
I have now finished (what I hope is) a complete LALR grammar for Java
in the form a yacc specification. Its based on the current language
spec grammar, the ANSI C expression grammar by Jeff Lee, a bit of the
C++ grammar from the ARM (for "for" statements which were omitted from
the language spec grammar) and a little bit of filling in the blanks
(for example "void" is not mentioned in the language spec grammar). It
reflects the discussions and "(semi-)official verdicts" that have
happened up to now as best I understand them.
With the yacc spec is a lex spec (based heavily on the ANSI C scanner
by Jeff Lee) and a make file. The resulting parser has been run
against the complete alpha 3 sources and produces no errors -- this
isn't a guarantee that its right, but it is a reasonable first test. I
would greatly appreciate any corrections or improvements. Also samples
of code that doesn't parse, but should, or does parse, but shouldn't,
would be extremely helpful.
Yacc produces 6 shift/reduce conflicts in generating the parser, all of
which are properly resolved by shifting. Two of these involve what I'm
guessing is an error in the language spec (regarding try statements).
One is the classical dangling else. Two are associated with the casts
(which are syntactically ambiguous in Java), and the last one involves
new (and is caused by this weird placement of new at higher precedence
than "." and "[]").
Also be aware that the parser accepts a slight superset language which
assumes that additional syntactic checking is done after parsing in a
couple of places. This is *extremely* bad form in my book, but
unfortunately I think this may be inherent in the language. If you can
figure out a way to tighten up some or all of these areas, I'd truly
love to hear about it. Read the header comments for details on all
these matters.
Since the grammar is over 1K lines, I'm putting it out for ftp rather than
posting it directly. The relevant files are:
ftp://ftp.cc.gatech.edu/people/hudson/java_grammar/java_parse.y
ftp://ftp.cc.gatech.edu/people/hudson/java_grammar/java_scan.l
ftp://ftp.cc.gatech.edu/people/hudson/java_grammar/Makefile
Scott
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com