Java 1.7

26 views
Skip to first unread message

Eli Gottlieb

unread,
Oct 18, 2012, 10:12:12 AM10/18/12
to sab...@googlegroups.com
Does a SableCC grammar for Java 1.7 exist somewhere? My advisor and I
are trying to find some way to parse Java 1.7 and analyze the syntax tree.

Thanks!
Eli

Etienne Gagnon

unread,
Oct 18, 2012, 3:01:02 PM10/18/12
to sab...@googlegroups.com
Hi Eli,

I have not taken the time to look at the Java 1.7 syntax changes. Do you
have a URL to the (full) modified language specification? I've found the
following list of improvements:
http://docs.oracle.com/javase/7/docs/technotes/guides/language/enhancements.html#javase7

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org

Etienne Gagnon

unread,
Oct 18, 2012, 3:04:52 PM10/18/12
to sab...@googlegroups.com
I should have looked harder:
http://docs.oracle.com/javase/specs/jls/se7/jls7.pdf

I'll look at the amount of work it would require to implement it.

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org

Eli Gottlieb

unread,
Oct 18, 2012, 8:19:06 PM10/18/12
to sab...@googlegroups.com
Wow, thanks, though given our time constraints we're almost definitely
making do with whatever parser we can produce.

By the way, is there any way to just retrieve the first token child of
an arbitrary AST node under Sable? I've got the
ASimpleConditionalOrExpression nodes in an AnalysisAdapter I'm writing,
and I just need some token, any token, to register as the "name" of the
expression and give its location in the source code. Any way to get
that information from nodes or extract a token without having to write
N-levels deep class-casting/pattern-matching to finally get down to a
production that directly contains a token?

Etienne Gagnon

unread,
Oct 18, 2012, 9:39:10 PM10/18/12
to sab...@googlegroups.com
Hi Eli,

There's a ReverseDepthFirstAdapter that you can use to get you name
token in few lines of code. Something like:

class FindLocations extends ReverseDepthFirstAdapter {
Node currentLocation;

// called on all token nodes
void defaultCase(Node node) {
currentLocation = node;
}
// called after visiting every alternative node
void defaulOut(Node node) {
setLocation(node, currentLocation); // remember location of alternative node
}
...
}

If your project is urgent, could you not use Java 1.5 grammar? Most Java
applications don't yet use any 1.7 syntax extensions.

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org

Le 12-10-18 20:19, Eli Gottlieb a �crit :

Eli Gottlieb

unread,
Oct 19, 2012, 4:18:49 AM10/19/12
to sab...@googlegroups.com
We are using the Java 1.5 grammar. 1.7 would be nice-to-have, but on
our time constraint I'm insisting we not wait for something perfect to
replace something good.

How is that FindLocations visitor working? I mean, it just visits every
node and calls an opaque setLocation method on every node with every
child of every node.

I can imagine if we check that node is a Token in defaultCase and save
currentLocation as a Token, check to make sure we don't overwrite it (or
don't care as long as it's overwritten with a Token)... but then
setLocation needs be able to actually save the Token associated with
each production/alternative node...

Hmm....

Etienne Gagnon

unread,
Oct 19, 2012, 8:23:22 AM10/19/12
to sab...@googlegroups.com
Hi Eli,

I was giving you the big picture and letting you figure out the details.
Hint: One way to implement setLocation() is to add a global hash table
to associate a location token (value) to each node (key).

Also, note that defaultCase is only called for tokens in SableCC 3.x
tree walkers. So, you don't need to add a test. You could cast the
parameter from Node to Token, if you wish, as it would be (dynamically)
safe.

You can read Chapter 5 of my M.Sc. thesis (
http://sablecc.sourceforge.net/thesis/thesis.html#PAGE52 ), then look at
the actual source code of ReverseDepthFirstAdapter and use a debugger to
trace through its execution to understand how it works.

Have fun!

Etienne

Etienne Gagnon, Ph.D.
http://sablecc.org

Etienne Gagnon

unread,
Oct 19, 2012, 8:26:49 AM10/19/12
to sab...@googlegroups.com
I meant Chapter 6.
> You can read Chapter 5 of my M.Sc. thesis [...]

Eli Gottlieb

unread,
Oct 19, 2012, 9:34:48 AM10/19/12
to sab...@googlegroups.com
Sorry, I'd just gotten up in the morning (weekend here is Fri-Sat).
I've pretty much figured it out now.

Thanks a ton!
Reply all
Reply to author
Forward
0 new messages