Re: Making my first compiler

"Peter \"Firefly\" Lund" <firefly@diku.dk>
25 Sep 2006 01:15:21 -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)
Re: Making my first compiler torbenm@app-0.diku.dk (2006-11-27)
Re: Making my first compiler z2345678998765432y@sbcglobal.net (John) (2006-11-29)
Re: Making my first compiler torbenm@app-3.diku.dk (2006-11-29)
Re: Making my first compiler blume@tti-c.org (Matthias Blume) (2006-11-29)
[4 later articles]
| List of all articles for this month |
From: "Peter \"Firefly\" Lund" <firefly@diku.dk>
Newsgroups: comp.compilers
Date: 25 Sep 2006 01:15:21 -0400
Organization: Department of Computer Science, University of Copenhagen
References: 06-09-087 06-09-100
Keywords: design
Posted-Date: 25 Sep 2006 01:15:21 EDT

On Mon, 18 Sep 2006, [iso-8859-1] Torben Ęgidius Mogensen wrote:


> 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.


I can really recommend direct code generation. It is very easy to get
the compiler off the ground that way.


Don't worry about register allocation, either. Just treat the machine
as a stack machine where the top-most element is (usually) in a
register.


With some extra work one can end up with code that is quite good --
that's what Borland's Pascal/Delphi compilers used to do.


> 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).


Or you can use the gcc extension for nested functions. Yes, you can even
take the address of such functions and pass them as parameters. And they
will still be able to access the correct local variables/parameters in
their enclosing scopes.


http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/Nested-
Functions.html


Gcc has supported them since 1988 or thereabouts.


> > So my steps would be:
>
> 1. Build syntax tree
> 2. Do lambda lifting
> 3. Emit C.


And mine would be:


    1. a loop that reads pascal code and emits C code.


-Peter



Post a followup to this message

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