Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generating Code for Compound Conditional Expressions from an Abstract Syntax Tree?

5 views
Skip to first unread message

sees...@gmail.com

unread,
Jun 3, 2009, 12:42:55 AM6/3/09
to
Does anyone know of any links to any really good examples of:
Generating Code for Compound Conditional Expressions from an Abstract
Syntax Tree?

Torben Ægidius Mogensen

unread,
Jun 3, 2009, 8:51:55 AM6/3/09
to
sees...@gmail.com writes:

Read chapter 7 of "Basics of Compiler Design", which you can download
from http://www.diku.dk/~torbenm/Basics/ . It shows how logical
expressions, including sequential operators, can be compiled.

Torben

Gene

unread,
Jun 3, 2009, 10:47:18 PM6/3/09
to

The Red Dragon Book (Aho Sethi and Ullman) does a nice job with this.

SeeScreen

unread,
Jun 14, 2009, 2:22:09 PM6/14/09
to

Yes, the Red Dragon Book did prove to be an excellent source, this
time after spending weeks trying to figure this out on my own and re-
reading chapter eight yet another time, it was quite clear.

Although section on compound conditional expressions (pages 500-503)
provided a superb solution, it seems that I was able to improve upon
the way to process control flow statements discussed on pages 504-506.
I found no use what-so-ever for the nextlist construct, thus my
solution was exactly this much simpler.

Another aspect that I improved upon (that would certainly be out of
the scope of the original author's intention) was that I found a very
simple way to generate optimal jump code on the first pass.

SeeScreen

unread,
Jun 20, 2009, 11:52:06 AM6/20/09
to
On Jun 14, 1:22 pm, SeeScreen <seescr...@gmail.com> wrote:
> On Jun 3, 9:47 pm, Gene <gene.ress...@gmail.com> wrote:
>
> > On Jun 3, 12:42 am, seescr...@gmail.com wrote:
>
> > > Does anyone know of any links to any really good examples of:
> > > Generating Code for Compound Conditional Expressions from an Abstract
> > > Syntax Tree?
>
> > The Red Dragon Book (Aho Sethi and Ullman) does a nice job with this.
>
> Yes, the Red Dragon Book did prove to be an excellent source, this
> time after spending weeks trying to figure this out on my own and re-
> reading chapter eight yet another time, it was quite clear.
>
> Although section on compound conditional expressions (pages 500-503)
> provided a superb solution, it seems that I was able to improve upon
> the way to process control flow statements discussed on pages 504-506.
> I found no use what-so-ever for the nextlist construct, thus my
> solution was exactly this much simpler.

I see now why I was able to simplify the implementation removing the
nextlist construct. This construct is probably still required for a
single pass compiler.

Since I parsed all of the code into an Abstract Syntax Tree and
annotated this tree as code generation progressed the nextlist was not
needed. Also on pages 468-469 of the Red Dragon Book, the E.code
construct was not needed for this same reason.

After the code was parsed into an Abstract Syntax Tree, the code was
generated from a single function that was recursively called with the
YACC production number. The YACC production number formed the cases in
a large switch statement.

A very useful debugging function that I created was to output the
Abstract Syntax Tree to XML using a very simple function that was
recursively called. Then I could use the freeware "XML Viewer" to
examine the structure of the tree.

0 new messages