tags:

views:

41

answers:

1

I was getting acquainted with ANTLR, so had this question. If i am supposed to create a robust programming language like java or C#, would i use compiler tools to create it or write handwritten code for the compiler. Are there any practical examples of widely used languages created using compiler tools? Also are there performance issues with tool generated code versus handwritten compiler.

+1  A: 

I believe the Java compiler was/is written in C. Sun was a hardware company with a long investment in Unix, C, and Solaris, so that's what they knew best.

They might have used a C-based lex/parser like yacc and their grammar for Java. But it certainly wasn't ANTLR.

UPDATE: I was thinking that this was true for the first javac.exe, but I wasn't certain. A comment below said the current incarnations of the Java compiler are indeed written in Java.

You could use ANTLR as the basis for a language like Java or C# or another of your own devising. (I believe you can find Java grammars for ANTLR.)

You'd start with a grammar, lex and parse that into an abstract syntax tree (AST), and then emit your byte code or anything else from that.

Terrance Parr's latest book might interest you.

duffymo
The standard Java bytecode compiler 'javac' is actually implemented in Java. The default runtime platform (VM + default libraries) is implemented in C/C++.
Kknd
I didn't know that. I guess I was thinking that the both the runtime and the compiler were written in C. I would be surprised to learn that the first javac was written in Java.
duffymo
Many compilers are written with some kind of manual or semi-automatic translation into something for which an actual compiler exists -- i.e. compiler bootstrapping. So the process is basically: Write compiler for language L to target M in language L. Translate compiler to M manually (or write a minimal compiler for L in M). Compile the compiler written in L using this bootstrap compiler. Finally, recompile the compiler using the version just generated. It's an excellent way to make sure that your compiler and language are production-ready!
Gian