|Making my first compiler email@example.com (2006-09-16)|
|Re: Making my first compiler firstname.lastname@example.org (Pascal Bourguignon) (2006-09-18)|
|Re: Making my first compiler email@example.com (Tommy Thorn) (2006-09-18)|
|Re: Making my first compiler firstname.lastname@example.org (email@example.com) (2006-09-18)|
|Re: Making my first compiler firstname.lastname@example.org (2006-09-18)|
|Re: Making my first compiler email@example.com (Jeff Kenton) (2006-09-25)|
|Re: Making my first compiler firstname.lastname@example.org (Peter \Firefly\Lund) (2006-09-25)|
|Re: Making my first compiler email@example.com (Stefan Monnier) (2006-11-23)|
|Re: Making my first compiler ValdoFerrari@libero.it (Valdo Ferrari) (2006-11-24)|
|[8 later articles]|
|From:||Tommy Thorn <firstname.lastname@example.org>|
|Date:||18 Sep 2006 09:45:18 -0400|
|Posted-Date:||18 Sep 2006 09:45:18 EDT|
> I'm trying to create a pascal subset interpreter/compiler.
> Do I HAVE to create a syntax tree? Or can I go straight to creating
> Intermediate Code (Quadruples) in Yacc's reduce actions?
many moons ago, I was facing the same question while working on
and I convinced my fellow group members that we didn't need an
abstract syntax tree (AST) but could go straight to intermediate code.
That was the single biggest mistake we made.
As we proved, we could write a successful optimizing compiler for a
Pascal-like language without an AST, but it was very cumbersome and
inelegant. IMO, you don't _have_ to generate an AST, but you'd be very
happy you did.
> What's a basic structure for a syntax tree in C?
Did you see the other thread called "Generating a simple hand-coded like
recursive descent parser"? It's a pretty simple example of just that.
> Say I want my compiler to convert Pascal code to C code, which steps
> are absolutely necessary to do this correctly?
> Im thinking:
> Build Syntax Tree -> Convert it to Three Address Code (Quadruples) ->
> then into C
> Was this correct?
There isn't a "correct" way, but in fact, if your target machine is C,
you don't need quadruples at all, rather that would be a mistake IMO.
An AST will be plenty sufficient.
This is somewhat related to another recent thread on "nested functions".
Return to the
Search the comp.compilers archives again.