Poll: Analyzers rebuilding the parse tree - bug or feature?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Poll: Analyzers rebuilding the parse tree - bug or feature?

Oliver Gramberg

Dear Grammatica users,

in the current implementation of Grammatica, Analyzers that are run on an existing parse tree (using Analyzer's Analyze(Node node)) completely rebuild the parse tree; meaning: new nodes are created, the old ones discarded, all values attached to the nodes (using Node's AddValue(object value)) are removed.

--- Is there anybody out there who relies on this behaviour?
--- Would it be of help to anybody if this were different?

I am using Grammatica to build an application where I need at least two extra passes on the parse tree: one to propagate information top-down, one to collect information bottom-up again. I have a patch that makes my Analyzers keep the tree and any values attached to the nodes.

--- Is this something somebody could use/have used?

Some theory: I see three different applications for Analyzers.
- Building an initial tree during parsing. The current Analyzer supports this by adding to the tree whatever Exit...() returns.
- Re-building the tree in a later phase as part of a tree transformation. This could be a complete rebuild as it currently is; one may want values attached to nodes to be retained, then the traversal algorithm must be changed to replace each node by what Exit...() returns.
- Analyzing a tree without modifying it. Ideally, the Exit...() methods would be defined to return void, resulting in cleaner code in overridden methods in Analyzer subclasses. Alternatively, the traversal algorithm must be changed to ignore the value returned from Exit...().

--- Does anybody see a need for any of the latter two?
--- What kind of interface would you like to have for these alternatives?
- Constructor arguments that tell the Analyzer to rebuild/replace/ignore, retain/remove values attached.
- Public members that let you configure the Analyzer to rebuild/replace/ignore, retain/remove values attached.
- Three different (sub)classes.

I suggest the following:
- Make clearing the values attached to nodes configurable.
- Keep the current implementation of Analyzer (rebuilds the tree from scratch, clears the values by default), maybe rename it to TreeBuilder (because that's what it actually does).
- Introduce a rebuilding analyzer (replaces nodes with what is returned from Exit...(), does not clear the values by default), named TreeTransformer.
- Introduce a non-rebuilding analyzer (leaves the tree untouched, does not clear the values by default), possibly named Analyzer (because that's what it is for). Define the grammar-specific Exit...() callback methods of this Analyzer to return void.
- Introduce a common superclass for the three styles.

Please let me know your opinion on this!

Regards
Oliver



Oliver Gramberg
ABB AG
Forschungszentrum Deutschland
DECRC/I2
Wallstadter Str. 59
D-68526 Ladenburg

Phone: +49 6203/71-6461
Fax: +49 6203/71-6253
E-mail:
oliver.gramberg@...

Sitz/Head Office: Mannheim
Registergericht/Registry Court: Mannheim
Handelsregisternummer/Commercial Register No.: HRB 4664

Vorstand/Managing Board: Peter Smits (Vorsitzender/Chairman), Heinz-Peter Paffenholz, Dr. Joachim Schneider, Hendrik Weiler
Vorsitzender des Aufsichtsrats/Chairman of Supervisory Board: Bernhard Jucker

Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail.
Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail.
Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
Grammatica-users mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/grammatica-users