Related articles |
---|
Interface between Parse Tree and translators kvrao@m-net.arbornet.org (1994-10-15) |
Re: Interface between Parse Tree and translators danhicks@aol.com (1994-10-21) |
Re: Interface between Parse Tree and translators marks@orb.mincom.oz.au (1994-10-19) |
Re: Interface between Parse Tree and translators kvrao@m-net.arbornet.org (1994-10-22) |
Newsgroups: | comp.compilers |
From: | danhicks@aol.com (DanHicks) |
Keywords: | design, OOP |
Organization: | America Online, Inc. (1-800-827-6364) |
References: | 94-10-119 |
Date: | Fri, 21 Oct 1994 02:34:30 GMT |
kvrao@m-net.arbornet.org (Venkateswara Rao) writes:
>I am involved in a compiler project using OO methodology. I am facing
>the following problem :
The parser reads a language and creates the parse tree. Now I need to
call translators of 4 other languages each of which has their CodeGen
functions which expect data in some form. So the xlators have to create
the required data structures out of parse tree and call codegen function
of the respective language. As the parse tree can not have any thing
specific to any language, how can I design the interface to all xlators
in "truly" object-oriented way?<<<
Don't know about OO, but the "intuitive" way to generate code is to design
an interpreter for the source language and then, for each interpretative
action, substitute logic that generates code to accomplish the same
action. (Yes, this takes some creativity when you deal with control flow,
but a reasonably clever programmer can accomplish the mapping.) So, you
can design your interpreter to be generic, and then (looking at it from a
non-OO viewpoint) develop N libraries for each of the N target languages,
where each library contains the same entry points -- one for each
"interpretative action". You can even go this one further, and first
write out the stream of "interpretative actions" to a file (speaking
conceptually now), then read that file into a different program and
optimize it (after which you do the target-specific code generation).
I'm sure the OO-literate can map this concept of a set of interpretative
actions to a class definition, with specific implementations of that class
for each of the target languages.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.