Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to generate a valid abstract syntax tree with "..jdt.core.dom"(With "...jdt.core.dom", construction of AST tree can be programmable.My question is "can it make sure the generated ast conforms to the grammar?")
How to generate a valid abstract syntax tree with "..jdt.core.dom" [message #910312] Sun, 09 September 2012 08:00 Go to next message
jing yang is currently offline jing yangFriend
Messages: 2
Registered: September 2012
Junior Member
With "...jdt.core.dom", construction of AST tree can be programmable.My question is "can it make sure the generated ast conforms to the grammar?" Or "is it the programmer's job to ensure the generated AST tree is valid "? So the programmer need to check if the written program generates a valid or invalid ast tree
Re: How to generate a valid abstract syntax tree with "..jdt.core.dom" [message #910408 is a reply to message #910312] Sun, 09 September 2012 15:04 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1036
Registered: July 2009
Senior Member
jing yang wrote on Sun, 09 September 2012 10:00
With "...jdt.core.dom", construction of AST tree can be programmable.My question is "can it make sure the generated ast conforms to the grammar?" Or "is it the programmer's job to ensure the generated AST tree is valid "? So the programmer need to check if the written program generates a valid or invalid ast tree


Basic validity is of course ensured by the AST, e.g., a field declaration can only occur in the body of a class, but contextual validity is not checked when creating an AST, e.g., it is possible to create an interface method with illegal modifiers like "static", "synchronized" etc.

I'm not quite sure which level of validatity you are interested in. Note, that Java syntax can be described by different grammars, where one grammar may already reject programs that another grammer would allow (deferring checks to later phases during compilation).

To get full error checking you'd need to actually create the compilation unit and feed it to the compiler.

best,
Stephan
Re: How to generate a valid abstract syntax tree with "..jdt.core.dom" [message #910578 is a reply to message #910408] Mon, 10 September 2012 02:57 Go to previous message
jing yang is currently offline jing yangFriend
Messages: 2
Registered: September 2012
Junior Member
Many thanks for your help,Stephan. Actually, what I want to do is to devise a method to automatically generate any syntactically correct Java program based on "...jdt.core.dom". So the contextual validity is what I need. I guess I should figure out some controlling ways in the generation method
Previous Topic:Breakpoints are all crossed out in Juno but in Helios not
Next Topic:Java incremental build unexpected behaviour
Goto Forum:
  


Current Time: Fri Nov 28 13:47:36 GMT 2014

Powered by FUDForum. Page generated in 0.03159 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software