Re: Language features for compiler writing was: Java compiler courses

torbenm@app-5.diku.dk (Torben =?iso-8859-1?Q?=C6gidius?= Mogensen)
4 May 2007 13:18:46 -0400

          From comp.compilers

Related articles
[5 earlier articles]
Re: Language features for compiler writing was: Java compiler courses DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-04-27)
Re: Language features for compiler writing was: Java compiler courses la@iki.fi (Lauri Alanko) (2007-04-28)
Re: Language features for compiler writing was: Java compiler courses jon@ffconsultancy.com (Jon Harrop) (2007-04-28)
Re: Language features for compiler writing was: Java compiler courses DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-04-28)
Re: Language features for compiler writing was: Java compiler courses danwang74@gmail.com (Daniel C. Wang) (2007-04-28)
Re: Language features for compiler writing was: Java compiler courses s.r.clarkstone@durham.ac.uk (Simon Richard Clarkstone) (2007-04-29)
Re: Language features for compiler writing was: Java compiler courses torbenm@app-5.diku.dk (2007-05-04)
Re: Language features for compiler writing was: Java compiler courses dot@dotat.at (Tony Finch) (2007-05-04)
| List of all articles for this month |

From: torbenm@app-5.diku.dk (Torben =?iso-8859-1?Q?=C6gidius?= Mogensen)
Newsgroups: comp.compilers,comp.lang.functional
Date: 4 May 2007 13:18:46 -0400
Organization: Department of Computer Science, University of Copenhagen
References: 07-04-074 07-04-084 07-04-109 07-04-125 07-04-135
Keywords: courses
Posted-Date: 04 May 2007 13:18:46 EDT

Hans-Peter Diettrich <DrDiettrich1@aol.com> writes:


> Chris F Clark wrote:
>
>> You can get polymorphism, by using C++ as your C...
>> That leaves GC...
>
> I don't know whether polymorphism is a requirement for writing
> compilers, some opinions deny just the requirement of OOP.


I find polymorphism useful for, e.g., symbol tables: You will often
have several symbol tables that bind names to different data (variable
names to locations, constant names to values, type names to type
descriptions, function names to addresses, etc.). With polymorphism,
you can design a single symbol table library that you can use for all
symbol tables.


You can do that with OO also, but (without generics/polymorphism) you
need downcasts whenever you look up in a symbol table, wich is
tedious, slow and error-prone.


I also find that I want to decorate syntax trees with different
information at different times. For example, the parser might
decorate nodes with their position in the source file (for error
reporting), but later on I might want to add type information to the
nodes. I can do that with a single syntax tree type which is
polymorphic over the decoration info. Without, I need several similar
syntax tree types or something ugly like casts or union types for the
decoration info, with the attendant loss of type safety in the
compiler.


So, polymorphism is not a _requirement_ for writing compilers, but it
is pretty nice to have.


Torben



Post a followup to this message

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