Home > Archive > Compilers > March 2005 > Compiler Construction - New to it and getting started.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Compiler Construction - New to it and getting started.
|
|
| Nate the Capricious 2005-02-12, 3:58 am |
| Hello everyone,
I want to start doing some research on compiler construction and was
wondering what programming language you guys use or would like to use
to implement a compiler. I know a bit of C/C++ and 'a little' Pascal
but was reading and it seems Modula-2 and Objective CaML get alot of
thumbs up in this department.
Thoughts?
Nathaniel L. Walker
[Depends on what your goals are. These days I write most of my programs in
perl because they run fast enough for my purposes, and the built in data
types and all the public libraries make me a lot more productive than in
low level languages like C or C++. On the other hand, if I were writing
a compiler to ship to a thousand other sites, I'd probably write it in C
or C++. -John]
| |
| Mohd Hanafiah Abdullah 2005-02-12, 8:58 pm |
| Nate the Capricious <NatLWalker@gmail.com> wrote:
>I want to start doing some research on compiler construction and was
>wondering what programming language you guys use or would like to use
>to implement a compiler. I know a bit of C/C++ and 'a little' Pascal
>but was reading and it seems Modula-2 and Objective CaML get alot of
>thumbs up in this department.
You will not go wrong with C being a mature language and a pervasive
one, regardless of its drawbacks. Every language has its downside.
The following website shows an index on programming languages
popularity:
http://www.tiobe.com/tpci.htm
which shows C is up there.
The availability of support tools and components for C is overwhelming
be it on desktop platforms like Linux, Windows, MacOS, Solaris, etc,
or on embedded systems or game consoles. So, with due respect for the
various languages, if you are going to write a compiler C would be an
excellent choice.
Napi
--
http://www.axiomsol.com
http://www.cs.indiana.edu/hyplan/napi.html
| |
| Torben Ęgidius Mogensen 2005-02-17, 4:03 am |
| "Nate the Capricious" <NatLWalker@gmail.com> writes:
> I want to start doing some research on compiler construction and was
> wondering what programming language you guys use or would like to use
> to implement a compiler. I know a bit of C/C++ and 'a little' Pascal
> but was reading and it seems Modula-2 and Objective CaML get alot of
> thumbs up in this department.
Of the languages you mention, I would definitely go with O'CaML. The
reasons are:
- The datatypes in O'CaML are almost ideal for representing syntax
trees: You get pattern matching, simple building of trees, GC, etc.
- The fact that datastructures are by default persistent makes symbol
tables easy to handle. And you can use references to make
non-persistent data structures when you need them.
- Higher-order functions makes inherited attributes easy.
In general, you will get a much more compact and easily maintainable
compiler using O'CaML than you would with, say, C or C++. And that is
very useful if you want to experiment with variants of the compiler.
Torben
| |
| TOUATI Sid 2005-02-28, 3:59 am |
| Right,
I would suggest Ocaml as a programming language for a clean compiler.
But, if the compiler would do some backend or advanced code
optimization, I think that Ocaml wouldn't be the best choice.
As I tell to my students, compilation can be seen as a formal work
when doing simple parsing&semantic analysis&simple code generation.
Unfortunately, many code optimization techniques in the litterature
are completely ad-hoc, and no formal description/model can be easily
used. Such ad-hoc techniques require to "hack" a compiler or to use
some "C" programming inside the compiler. While this is not the best
thing for a compiler, this is actually the situation of (maybe) almost
all optimizing compilers.
S
| |
| Torben Ęgidius Mogensen 2005-03-01, 3:58 am |
| TOUATI Sid <touati@nospam-prism.uvsq.fr> writes:
> I would suggest Ocaml as a programming language for a clean compiler.
> But, if the compiler would do some backend or advanced code
> optimization, I think that Ocaml wouldn't be the best choice.
>
> As I tell to my students, compilation can be seen as a formal work
> when doing simple parsing&semantic analysis&simple code generation.
> Unfortunately, many code optimization techniques in the litterature
> are completely ad-hoc, and no formal description/model can be easily
> used. Such ad-hoc techniques require to "hack" a compiler or to use
> some "C" programming inside the compiler. While this is not the best
> thing for a compiler, this is actually the situation of (maybe) almost
> all optimizing compilers.
I don't agree. First of all, most optimization techniques are
formalized in some way (data-flow analysis, control-flow analysis,
pattern recognition, etc.) and, secondly, OCaml or SML can be used to
write ad-hoc code as well as C can. I would actually say they are even
better at this than C, as you don't have to worry so much about memory
allocation/deallocation in the compiler and you can often write fairly
advanced transformations as quick hacks by using pattern matching or
standard higher-order functions such as fold and map.
Where C may be a better option than OCaml or SML is bytecode
interpreters. Here, you may want to do bit-fiddling and stuff where
you treat the same data sometimes as pointers and sometimes as
integers. This is where C's lack of type enforcement can come in
handy.
Torben
| |
| TOUATI Sid 2005-03-01, 8:59 pm |
| > I don't agree. First of all, most optimization techniques are
> formalized in some way (data-flow analysis, control-flow analysis,
> pattern recognition, etc.) and, secondly, OCaml or SML can be used to
> write ad-hoc code as well as C can. I would actually say they are even
> better at this than C, as you don't have to worry so much about memory
> allocation/deallocation in the compiler and you can often write fairly
> advanced transformations as quick hacks by using pattern matching or
> standard higher-order functions such as fold and map.
>
> Where C may be a better option than OCaml or SML is bytecode
> interpreters. Here, you may want to do bit-fiddling and stuff where
> you treat the same data sometimes as pointers and sometimes as
> integers. This is where C's lack of type enforcement can come in
> handy.
>
> Torben
Torben,
your arguments convinced me. I agree that OCaml can be used as
imperative C language, so it may be used to implement ad hoc compiler
optimization modules.
However, there is another important point : history ! sometimes, many
previous compiler modules are already implemented in C or C++. Reusing
them efficiently may require to use one of these two languages. I think
you would say that OCaml allows to import external modules (as if they
are libraries) ! but we may feel too that reusing C modules is better
done by continuing to use C. All depends on the engineering criteria.
History isn't a weak argument in software engineering : did you try to
persuade physicists to stop using fortran 77 ?
S
|
|
|
|
|