|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)|
|Re: Making my first compiler firstname.lastname@example.org (2006-11-27)|
|Re: Making my first compiler email@example.com (John) (2006-11-29)|
|[6 later articles]|
|Date:||18 Sep 2006 09:49:24 -0400|
|Organization:||Department of Computer Science, University of Copenhagen|
|Posted-Date:||18 Sep 2006 09:49:24 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?
You can generate code directly, most compilers pre 1990 did that. It
makes it a bit harder to optimize code, but for simple code it will
work, especially if you output textual assembler (with labels), so you
don't have to worry about back-patching branch targets.
> What's a basic structure for a syntax tree in C?
A union of structs where all the structs share a tag field as the
> 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?
Going through three-address code seems like taking a detour. Most
constructs in Pascal can be directly translated into source-level
constructs in C. The main problems would be nested function
declarations and functions as parameters, but you can handle these
with lambda lifting (discussed here recently).
So my steps would be:
1. Build syntax tree
2. Do lambda lifting
3. Emit C.
Return to the
Search the comp.compilers archives again.