Re: OOP Parse tree generation?

George Nelan <nelan@home.com>
23 Mar 2000 22:42:57 -0500

          From comp.compilers

Related articles
OOP Parse tree generation? nojeda@my-deja.com (Nicolas) (2000-03-11)
Re: OOP Parse tree generation? qjackson@wave.home.com (Quinn Tyler Jackson) (2000-03-21)
Re: OOP Parse tree generation? floris@vangog.net (Floris 'Tamama' van Gog) (2000-03-23)
Re: OOP Parse tree generation? thp@roam-thp2.cs.ucr.edu (Tom Payne) (2000-03-23)
Re: OOP Parse tree generation? lojedaortiz@interlink.com.ar (Nicolas Ojeda Bar) (2000-03-23)
Re: OOP Parse tree generation? dara_gallagher@my-deja.com (2000-03-23)
Re: OOP Parse tree generation? nelan@home.com (George Nelan) (2000-03-23)
Re: OOP Parse tree generation? danwang+news@cs.princeton.edu (Daniel C. Wang) (2000-03-25)
Re: OOP Parse tree generation? cfc@world.std.com (Chris F Clark) (2000-04-03)
Re: OOP Parse tree generation? cfc@world.std.com (Chris F Clark) (2000-04-03)
| List of all articles for this month |
From: George Nelan <nelan@home.com>
Newsgroups: comp.compilers
Date: 23 Mar 2000 22:42:57 -0500
Organization: Compilers Central
References: 00-03-074 00-03-082
Keywords: parse, OOP

Quinn Tyler Jackson wrote:
>
> Nicolas asked:
>
> > How would you implement parse tree structures for a language that has
> > statements and expressions (a la Pascal), in an object oriented fashion ?
>
> > [Good question. I've never seen a very satisfactory OOP design for a
> > parser. -John]
>
> The biggest problem I have encountered with trying to convert the
> artifacts of a parse into an object oriented mass is that of class
> explosion. I considered, when implementing LPM, that each clause type
> would make a nice class, and each class would have an overridden Match
> member function, which would have allowed me to call Match through the
> base Clause class, for proper dispatching.


The number of resulting classes in tree generation methods comparable
to using algebraic data types is a linear function of grammar size;
"class explosion" should not be all that problematic these days except
perhaps for obscure cases - at least that's my experience and opinion.


I have a working example of using algebraic types to represent parse
trees, using a preprocessor for C++ that I wrote, and which is freely
available by the way (see url below). The example to which I refer
is the preprocessor itself - it is written in itself.


Algebraic types can be viewed as a way to implement certain kinds of
visitor-style patterns, so it is probably safe to say that the use of
such types is object oriented, at least to some extent. It works for
me but as usual your milage may vary.


--
George Nelan
mailto:nelan@home.com
http://www.primenet.com/~georgen/app.html


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.