Re: C Compiler in C++

Joachim Durchholz <joachim_d@gmx.de>
23 May 2002 01:26:37 -0400

          From comp.compilers

Related articles
[5 earlier articles]
Re: C Compiler in C++ rbates@southwind.net (Rodney M. Bates) (2002-05-13)
Re: C Compiler in C++ lex@cc.gatech.edu (Lex Spoon) (2002-05-13)
Re: C Compiler in C++ alexc@world.std.com (2002-05-17)
Re: C Compiler in C++ alexc@world.std.com (2002-05-17)
Re: C Compiler in C++ journeyman@compilerguru.com (2002-05-17)
Re: C Compiler in C++ Bart.Vanhauwaert@nowhere.be (2002-05-17)
Re: C Compiler in C++ joachim_d@gmx.de (Joachim Durchholz) (2002-05-23)
Re: C Compiler in C++ lars@bearnip.com (Lars Duening) (2002-06-07)
| List of all articles for this month |
From: Joachim Durchholz <joachim_d@gmx.de>
Newsgroups: comp.compilers
Date: 23 May 2002 01:26:37 -0400
Organization: Compilers Central
References: 02-05-039 02-05-055 02-05-073 02-05-086
Keywords: C, OOP
Posted-Date: 23 May 2002 01:26:37 EDT

journeyman wrote:
> On 13 May 2002 01:09:33 -0400, Lex Spoon <lex@cc.gatech.edu> wrote:
>
>>journeyman@compilerguru.com (journeyman) writes:
>
> [snip]
>
>>>encapsulation) for each tree walking pass. Either way, it can get
>>>pretty ugly quickly if you're not careful.
>>
>>Isn't this the situation whenever you use inheritance? Is it more
>>often the case with parse tree nodes, that you want to know their
>>specific subclass?
>
> I don't know about more often. It would really depend on the problem
> domain.


It's an application of the Visitor pattern. A discussion of this
pattern, complete with advantages and drawbacks, can be found in
Gamma/Helms/Johnson/Vlissides, "Design Patterns", Addison-Wesley).


The pattern applies to all forms of tree processing where tree nodes
have a type. You can extend the available tree node types via
subclasses, or you can extend the operations that operate on the nodes,
but you have to design for one of them when you set up the tree types.
There are various hacks around this, but all are ugly.


The problem isn't related to OO. The base problem is that there is no
way to keep a matrix of MxN possibilities open to extensions in both the
M and N direction. (M being "number of node types" and N being "number
of things that can be done with a node" in this case.)
This isn't really compiler-related, but compilers tend to have this
problem more often than other types of software.


Regards,
Joachim


Post a followup to this message

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