[antlr-interest] Custom object tree from tree parser?
Sam Barnett-Cormack
s.barnett-cormack at lancaster.ac.uk
Sun Sep 25 07:23:28 PDT 2011
I once had a very simple case where the parse tree and AST were
uninteresting, but I needed to build a roughly tree-like data structure,
and I just used actions and return types in the parser to handle it.
That was in an older version, of course, back when I was an undergrad,
but I see no reason why it wouldn't be an appropriate thing to do with a
tree parser - building data as you walk the tree.
Fundamentally, though, there's very rarely a single 'right way' to do
things.
Sam
On 23/09/2011 10:33, Mari Matinlassi wrote:
> Hello,
>
> I want to build custom object trees from text. As a simplified example,
> parser input is
>
> Car Seat;
> Car Audi;
> Customer John;
>
> Parser output shall be an object tree where e.g. Car object is an
> instantiation of a class below (Respectively, Customer class would be
> something similar):
>
> public class Car
> {
> private string brand;
> public Car(string _brand)
> {
> this.brand = _brand;
> }
> public string Brand
> {
> get { return brand; }
> }
> }
>
> What is the best way to do this? Custom AST node and custom TreeAdaptor?
> Tree parser with actions embedded in rules? What about the problem that not
> all the nodes are similar? Could you please give me some hint to the right
> direction?
>
> Kind regards,
>
> Mari
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list