Re: Making my first compiler

Tommy Thorn <>
18 Sep 2006 09:45:18 -0400

          From comp.compilers

Related articles
Making my first compiler (2006-09-16)
Re: Making my first compiler (Pascal Bourguignon) (2006-09-18)
Re: Making my first compiler (Tommy Thorn) (2006-09-18)
Re: Making my first compiler ( (2006-09-18)
Re: Making my first compiler (2006-09-18)
Re: Making my first compiler (Jeff Kenton) (2006-09-25)
Re: Making my first compiler (Peter \Firefly\Lund) (2006-09-25)
Re: Making my first compiler (Stefan Monnier) (2006-11-23)
Re: Making my first compiler (Valdo Ferrari) (2006-11-24)
[8 later articles]
| List of all articles for this month |

From: Tommy Thorn <>
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 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
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".


Post a followup to this message

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