Re: Making my first compiler

Tommy Thorn <tommy.thorn@gmail.com>
18 Sep 2006 09:45:18 -0400

          From comp.compilers

Related articles
Making my first compiler szigetir@gmail.com (2006-09-16)
Re: Making my first compiler pjb@informatimago.com (Pascal Bourguignon) (2006-09-18)
Re: Making my first compiler tommy.thorn@gmail.com (Tommy Thorn) (2006-09-18)
Re: Making my first compiler idknow@gmail.com (idknow@gmail.com) (2006-09-18)
Re: Making my first compiler torbenm@app-1.diku.dk (2006-09-18)
Re: Making my first compiler jeffrey.kenton@comcast.net (Jeff Kenton) (2006-09-25)
Re: Making my first compiler firefly@diku.dk (Peter \Firefly\Lund) (2006-09-25)
Re: Making my first compiler monnier@iro.umontreal.ca (Stefan Monnier) (2006-11-23)
Re: Making my first compiler ValdoFerrari@libero.it (Valdo Ferrari) (2006-11-24)
[8 later articles]
| List of all articles for this month |
From: Tommy Thorn <tommy.thorn@gmail.com>
Newsgroups: comp.compilers
Date: 18 Sep 2006 09:45:18 -0400
Organization: Compilers Central
References: 06-09-087
Keywords: design
Posted-Date: 18 Sep 2006 09:45:18 EDT

szigetir@gmail.com wrote:
> 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?


Hi Roland,


many moons ago, I was facing the same question while working on
Alvilda
(http://not.meko.dk/Hacks/Alvilda/The%20Alvilda%20Optimizing%20Compiler.html)
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".


Tommy


Post a followup to this message

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