|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
| Stephan Herrmann
Registered: July 2009
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.
Powered by FUDForum
. Page generated in 0.03158 seconds