Re: object oriented implementations of rec. descent parsers

Hans T Walheim <Hans.Walheim@Nexus.SE>
16 Oct 1996 17:51:50 -0400

          From comp.compilers

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)
| List of all articles for this month |
From: Hans T Walheim <Hans.Walheim@Nexus.SE>
Newsgroups: comp.compilers
Date: 16 Oct 1996 17:51:50 -0400
Organization: Compilers Central
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).
> --- snip ---
>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.


I do not think either that you can do an 'ideal OO parsing', because
of the performance problem, but you can at least take real advantage
of OO for a parser. I have written a program that can read and
interpret C++ declarations using a parser that is object oriented. I
have also written a commercial translator using OO (sorry, I cannot
tell more). The approach I have taken is to have one class for reading
declarations (that is more or less to traverse the grammar) and
depending on context making an appropiate 'container' that interprets
the grammar, e.g. there is a specific 'container' for class-members so
if the declaration-reader reads the keyword 'static' the container
class makes an appropiate judgement if 'static' is allowed and how it
should be interpreted. This way you have the advantage of putting all
rules for e.g. class-members in a specific class. Then when all rules
are passed the container can construct a specific object (for class
members the objects may be 'attributes', 'methods' and 'types')
holding the gathered information.


Using OO you also have the benefit of marking some declarations as
having errors and then you can always simulate that these declarations
are compatible with everything else, i.e. you do not have to
distribute the code testing for erronous objects all over your parser
to implement error-recovery.


So my advice is to try to put the specific knowledge of the semantics
in specific classes but keep the more static syntax and general
semantics in a general 'parser-class'. There is no use in over-doing
things, be pragmatic.


Hans Walheim
--


Post a followup to this message

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