Related articles |
---|
object oriented implementations of rec. descent parsers hnkst2+@pitt.edu (1996-10-10) |
Re: object oriented implementations of rec. descent parsers scotts@metaware.com (Scott Stanchfield) (1996-10-12) |
Re: object oriented implementations of rec. descent parsers parrt@MageLang.com (Terence Parr) (1996-10-12) |
Re: object oriented implementations of rec. descent parsers wolff@inf.fu-berlin.de (1996-10-12) |
Re: object oriented implementations of rec. descent parsers anund@rebecca.nr.no (1996-10-15) |
Re: object oriented implementations of rec. descent parsers dlmoore@ix.netcom.com (David L Moore) (1996-10-15) |
Re: object oriented implementations of rec. descent parsers Hans.Walheim@Nexus.SE (Hans T Walheim) (1996-10-16) |
From: | David L Moore <dlmoore@ix.netcom.com> |
Newsgroups: | comp.compilers |
Date: | 15 Oct 1996 09:40:20 -0400 |
Organization: | Netcom |
References: | 96-10-033 96-10-045 |
Keywords: | parse, OOP |
Hanhwe N Kim wrote:
> I'm trying to find source code examples that
> implement recursive descent parsers in an
> object oriented language (C++ / smalltalk).
Terence Parr wrote:
> PCCTS generates C++ parsers. Grammars ...
> result in a CParser class with member functions for each
> rule
This is, of course, using a module structure rather than a class
structure - that is, the class is being used to create a package.
Using classes to emulate packages is a common and valid use of C++
classes, but it is not really object oriented.
A more object oriented approach would be to build a set of classes
representing the static semantics of the language. It seems that
each class should contain a constructor which accepts a file as
parameter and parses it, constructing an appropriate object.
However, there are some problems with this which I think make such an
approach unworkable for a real programming language:
i/ Backtracking will require throwing of exceptions, which tends to
be quite expensive. You probably need to avoid backtracking to get
decent performance (ANTLR will backtrack, I believe)
ii/ Error recovery will be similarly slow.
iii/ You would like to derive more specific objects from more general
objects. For example, an if statement class should be derived from a
general statement class. You would like to be able to add new
syntactic forms solely by derivation. I know of no elegant way to
achieve this.
So, making the parsing part of the behaviour of the classes, which is
what you would want to claim true "object oriented parsing" seems to be
hard.
David Moore.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.