Archived

This topic is now archived and is closed to further replies.

citizen3019

create a compiler

Recommended Posts

Good day, Was wondering if someone might direct me toward a comprehensive forum, site, etc. that dealt with creating compilers. Not Visual C/C++ caliber but something simpler with which an at-home coder might have fun playing around? Thanks, c3019

Share this post


Link to post
Share on other sites
quote:
Original post by citizen3019
Thanks for the tipoff.
But is there anything else that doesn''t cost $70 used?

Thnx anyway,
-c3019


Abebooks.com has it for $30 (according to pricegrabber). This book is considered a classic intodructory text to this subject, so it would probably be worth your money.

Share this post


Link to post
Share on other sites
I might be wrong but I believe there is a compiler (compiles to MSIL not ASM) in Microsofts SSCLI (aka Rotor) package. Search their MSDN site for it, it includes source code for a sample .Net CLR, many many tools, and I believe at least 1 compiler.

Share this post


Link to post
Share on other sites
Maega wrote "Why not do a scripting language with a virtual machine? You won''t have to kill yourself learning assembly hehe "

Why would you need to know assembly to write a compiler?

Share this post


Link to post
Share on other sites
Forgot to post too, that the java SDK comes with the code for a java compiler -- same same. It just makes machine code for the java Virtual Machine...regular readable code there. Also, supposedly you could down load the gcc and check out the code... I tried, but gave up after a little while. Don''t forget you are going to need to know some stuff on Linkers and Loaders. It sort of a hidden art. If you can write your own compiler, then you can eventually write your own Virtual Machine! There is only one book that I can think of that explains how to write a virtual machine in C/C++.

Compilers are considered the most complex and advanced peices of software... and rightly so... it litterally translates a broken human language ( ie programming syntax ) into machine "binary" instructions!

Good luck man! Its worth it...everything else will seem like child''s play afterward. I''m working on something compiler-ish myself right now.

Share this post


Link to post
Share on other sites
quote:
Original post by Lucidquiet
Compilers are considered the most complex and advanced peices of software...


Only by compiler writers. Compilers are laughably trivial to implement. An optimising compiler is less trivial, but is still at the simple end of the spectrum.

The reason compilers are trivial is that the programmer has to translate rigorously defined input into rigorously defined output using a rigorously defined syntax and semantics.

Operating system kernels are far more complex than compilers and are far from the most complex software.

Kernels follow the same design principles as compilers, but unlike a compiler must also be tolerant, to some degree, of bad input.

Large bespoke projects are the most complex and advanced pieces of software. Unlike kernels and compilers, applications designed for unskilled humans to use must be highly tolerant of bad input, and must usually apply ad-hok and inconsistent transformations upon the input to produce the output.

Share this post


Link to post
Share on other sites
quote:
Original post by antareus
The Dragon Book is so highly regarded it was mentioned in Hackers .



The movie? Hardly a shining review of the book, then. Hackers was a pile of crud.

I''m excluding the leaking pool hack from that classification. Obviously that particular scene wasn''t written by whoever wrote the rest of the movie.

Share this post


Link to post
Share on other sites
Langauge Processors in Java is well suited book for noobs on intepreters/compilers.

I really didn''t like Lets Build a Compiler that much, but it does have some fine points.

If you know Standard ML I recommend Programming Language Concepts which have details on abstract syntax, dynamic and static semantics, interpreters, virtual machines, compilers, compilation, byte code, reflection, and runtime code generation.



"Yeah, I would''ve killed you, but I''m glad I didn''t - the paperwork is a bitch"

Share this post


Link to post
Share on other sites
quote:
Original post by Mayrel
quote:
Original post by Lucidquiet
Compilers are considered the most complex and advanced peices of software...


Only by compiler writers. Compilers are laughably trivial to implement. An optimising compiler is less trivial, but is still at the simple end of the spectrum.

The reason compilers are trivial is that the programmer has to translate rigorously defined input into rigorously defined output using a rigorously defined syntax and semantics.



Well, I would say that it''s often not rigorously defined input. The grammar often leaves you with some doubt.

The big problem with writing a compiler is not to make it compile good code into executables. That''s the easy part. The problem is that you have to make good decisions when the code is filled with errors. You can''t simply say, there were errors. The accuracy of the compiler messages, even in the latest compilers, aren''t that good. Errors can also make your compiler go bezerk. Especially those that slips throught the lexical part. When you write the grammar for a compiler it''s very easy to include cases that should''nt be allowed. Another problem is to avoid recursion in your grammar and ambiguous grammar. To make a compiler efficient you should also make it bottom-up which is not that trivial.

And as answer to the top question.
If you just want to play around with compilers then lex and yacc is a couple of cool tools. There are free versions of them. As said before, the dragon book is good. It''s a bit boring to read though

Share this post


Link to post
Share on other sites
And then there are the problems of platform specifics. Precompiled header option. Linking to shared objects. Performance (it might be able to compile but if it takes a day, the "implementation" is not adequate.) Advanced also means the most fully developed. The technology is more mature. And inspite of the ease of implementation even the most advanced compiler have a flock of bugs still being worked out. The type of bugs for the most part rare use cases, but still exist.

Share this post


Link to post
Share on other sites
quote:
Original post by __fold
Well, I would say that it''s often not rigorously defined input. The grammar often leaves you with some doubt.


The grammar of C++ is famously ambigious. However, the standard quite explicitly defines how to resolve those ambiguities. When using tools such as lex and yacc it can be difficult to resolve them, since they are designed for parsing sane grammars.
quote:

The problem is ... when the code is filled with errors. You can''t simply say, there were errors. The accuracy of the compiler messages, even in the latest compilers, aren''t that good.


Sure, that does make things less trivial. However, it makes all software less trivial -- detecting errors is not a feature that is unique to compilers.
quote:

When you write the grammar for a compiler it''s very easy to include cases that shouldn''t be allowed.


This very much depends upon the language. C/C++ parsers are tricky mainly because C/C++ aren''t designed to be parsed with yacc, and writing parsers by hand is tedious and therefore errorprone. A language with a more orthogonal feature set would be easier to compile since you don''t have to check for so many invalid cases.
quote:

To make a compiler efficient you should also make it bottom-up which is not that trivial.


Making any program efficient is more difficult than making an inefficient version of the program, that''s not a special feature of a compiler.
quote:

And as answer to the top question.
If you just want to play around with compilers then lex and yacc is a couple of cool tools. There are free versions of them. As said before, the dragon book is good. It''s a bit boring to read though


quote:
Original post by Lucidquiet
And then there are the problems of platform specifics. Precompiled header option. Linking to shared objects.


Naturally, adding features to a program will make it more complex. But none of these features are required features of a compiler. (Not even platform specifics, which belong in a seperate standard library. The library, although probably developed along with the compiler, would nonetheless be a seperate component.)
quote:

Advanced also means the most fully developed. The technology is more mature.


What does this mean, exactly? There are new features? Or it just supports the required features more correctly?
quote:

And in spite of the ease of implementation even the most advanced compiler have a flock of bugs still being worked out. The type of bugs for the most part rare use cases, but still exist.


Which is not a unique feature of compilers. All but the very most trivial programs have bugs, and introducing new features almost always introduces more bugs.

Share this post


Link to post
Share on other sites
Spirit, which is a library that enables you to write parsers directly in C++, looks very cool.


Yacc -->
if_stmt: "if" "(" expr ")" stmt
| "if" "(" expr ")" stmt "else" stmt

Spirit -->
if_stmt =
(str_p("if") >> '(' >> expr >> ')' >> stmt)
|| (str_p("if") >> '(' >> expr >> ')' >> stmt ("else" >> stmt));



[edited by - Mayrel on October 8, 2003 12:46:09 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by citizen3019
Good day,

Was wondering if someone might direct me toward a comprehensive forum, site, etc. that dealt with creating compilers. Not Visual C/C++ caliber but something simpler with which an at-home coder might have fun playing around?

Thanks,
c3019


You can get a free online book from here It comes with a bunch of example code.

Share this post


Link to post
Share on other sites