[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A lot of prduction classes
Hi,
I have been playing around with the java grammars for ANTLR and SableCC for
a week and have come up with some questions.
In ANTLR I am able to control the creation of the AST a lot (at the cost of
more coding), but it feels like I have missed something with SableCC. I get
a feeling that there is a lot of redundant nodes/classes in the SableCC
generated AST’s.
As an example take the import_declaration part of the j11.sablecc:
goal = import_declaration;
import_declaration =
{single_type_import_declaration} single_type_import_declaration |
{type_import_on_demand_declaration} single_import_on_demand_declaration;
single_type_import_declaration = import name semicolon;
type_import_on_demand_declaration = import name dot star semicolon;
The code will generate the following production classes:
AGoal :: PGoal.java
ASingleTypeImportDeclaration :: PSingleTypeImportDeclaration
ASingleTypeImportDeclarationImportDeclaration :: PImportDeclaration
ATypeImportOnDemandDeclaration :: PTypeImportOnDemandDeclaration
ATypeImportOnDemandDeclarationImportDeclaration :: PImportDeclaration
I can understand the need for production classes, but I do not understand
what I (miss)understand as the duplication of them.
For all import statements the parser will generate a tree rooted with an
ASingleTypeImportDeclaration or an
ATypeImportOnDemandDeclarationImportDeclaration. They in there turn always
included an ASingleTypeImportDeclaration or an
ATypedImportOnDemandDeclaration respectively.
I can see the usage of the ASingleTypeImportDeclarationImportDeclaration and
typedImportOnDemandDeclaration as they share the same superclass, so that
the can be identified as the same type.
I can also see the usage of the AsingleTypeImportDeclaration and the
AsingleTypeImportDeclaration as they hold the part that makes the
production.
Why can’t each of these pars of classes/nodes be consolidated into only one?
/Mattias
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.