[antlr-interest] Building a tree of objects

lognez2000 corno at dds.nl
Tue Jul 9 06:46:41 PDT 2002


Hi all,

I have to construct a tree of objects in C++ (using the
"Composite" pattern) from an input file with a defined syntax.
Somebody pointed me in the direction of ANTLR.
I worked through a tutorial and skimmed the book but did not find 
what I needed.
Can somebody please explain me if (and if so how) this can be done?
If somebody would even be so kind to post a small example, I would be 
a happy man (at least for the coming days).

Here's a simplified example of what I need:

BAR will be a 'leaf' class with a member varible (string) 
representing a name.
FOO will be a 'composite' base class with an int representing its 
unique identifier and a string that gives a desription.
FOOA and FOOB are both derived from FOO.
FOOA has exactly 1 component, namely a BAR class.
FOOB can have multiple components, both of type FOO or of type BAR.

the rules in BNF could look like this:
DEFINITIONS := FOO*
FOO :=  '{' digit ',' string ',' ( FOOAadditional | 
FOOBadditional ) '}'
FOOAadditional := 'A' ',' BAR
FOOBadditional := 'B' ',' ( BAR | FOO)*
BAR := '{' string '}'

Thanx,

Corno


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list