views:

932

answers:

20

Just curious. I may be wrong, but as far as I know, most languages are created using 'C' sources.

For example: perl , php , python, java(?), go ...

Is there any language that doesn't use C as a low level interpreter/compiler ? (fortran ?)

+4  A: 

What about BASIC or Pascal?

Konamiman
For obvious reasons...
Arthur Reutenauer
@Arthur - It think FreeBASIC is self-hosting at the moment, although that will change once it becomes a gcc front-end
Gautham Ganapathy
+1  A: 

PyPy is an implementation of Python written in Python.

Dave Webb
There is also an Python implementation in Java: Jython
Gregor Müllegger
However, PyPy generates C code in order to be fast enough for daily usage. ;)
All the Python implementations boil down to a C-based interpreter or virtual machine
orip
+1  A: 

From what I know of gcc, most of the compilers go from java/fortran/ada/whatever to object code, then they all use the same linker. I'd imagine the linker is in C, but the assembler probably isn't.

Dasuraga
The gcc/java/fortran gcc compiler is written in C, outputs assembler that's assembled with gas(also written in C)
nos
+3  A: 

SBCL

nos
And what language was it written in? I mean, the first version, not the bootstrapped.
avp
Spice Lisp begat CMUCL, and CMUCL begat SBCL. Spice Lisp, it seems, was written in microcode (for the Perq). From: http://www.cons.org/cmucl/doc/cmucl-history.html
Frank Shearar
+2  A: 

The Dylan compiler is written in Dylan.

Jochen
+3  A: 

Hi Pierre

Yes ..... PL/1 an old IBM mainframe program (PL/1 stands for Programgramming Language 1)

There are others: Assembler?

Regards Sigersted

Sigersted
+17  A: 

Any compiled language that predates C has (had?) compilers that weren't themselves dependent on C.

There was an old Lisp compiler that was written in Lisp (back when Lisp was the only Lisp).

Fortran, Algol, SNOBOL, Forth, Smalltalk, Simula, Pascal, APL, COBOL, MUMPS, LOGO and BCPL were also completely free of C.

outis
+1  A: 

Probably, in practice due to C being used in MANY places, it would only be Assembler or machine.

Even languages that compile themselves were written in something else before.

Usually at some level that will involve c.

Tom Hubbard
there are languages older than c that have been continually self hosting
Justin Smith
+13  A: 

If you write a language B in A, it's possible to write later a compiler for B in B.
Check out Bootstrapping

Bootstrapping is a term used in computer science to describe the techniques involved in writing a compiler (or assembler) in the target programming language which it is intended to compile. This technique is also called self-hosting.

A large proportion of programming languages are bootstrapped, including BASIC, C, Pascal, Factor, Haskell, Modula-2, Oberon, OCaml, Common Lisp, Scheme, Clojure, and more.

Edit: taking account of the comments:

  • Haskell's runtime system is still a pretty large chunk of C
  • Clojure isn't (yet) bootstrapped, but it's implemented in Java
Nick D
That doesn't really answer the question.
Robert Gamble
Haskell's runtime system is still a pretty large chunk of C
barkmadley
Clojure isn't (yet) bootstrapped, it's core is still implemented in Java, not Clojure. Also, the JVM is itself written in C(++).
bendin
@Robert Gamble, above is a list of bootstrapped languages, aka languages that don't use C.
Nick D
Not true... This only applies if B is sufficiently functional. I could write a language in C whose only commands are print and goto; this language could not be used to write an independent implementation of itself.
Dave Sherohman
@Dave Sherohman, sorry I wasn't clear. By "it's possible to write later" I meant if you design/evolve B to be sufficiently functional for that, as you mentioned.
Nick D
+5  A: 

Delphi has been written in Pascal and AFAIK Pascal has been (initially) written in Fortran but after that in Pascal itself.

Kosi2801
Delphi was written in Turbo Pascal and that was written in Assembler. The code generator upto version 3 was still in assembler. Even Borlands C++ Builder aka Turbo C was written in assembler.
Lothar
+3  A: 

FreePascal is self compiling. At some point, I'm going to get round to having a play with it. I still remember the glory days of Turbo Pascal.

In fact, I've just noticed it in the Karmic Koala Synaptic repositories so I'm downloading it and the Lazarus IDE right now.

Great, another weekend down the tubes :-)

paxdiablo
+3  A: 

See bootstrapping compilers. The first Pascal compiler was written in Fortran, which was used to compile a Pascal compiler which was written in Pascal.

C++ is a super-set of C, so a basic C++ compiler could be written in C, then enhanced using C++ specific features (and compiled using a previous version of itself).

I don't know what language MS compilers are written in, but I wouldn't be surprised it they were in C++. Apple's Clang is in C++, and targets the LLVM, which is also written in C++.

Also, many Lisp languages can compile themselves.

Some compilers will use C as a portable version of assembly, but that's just for convenience.

wisty
MSVC's compiler is effectively `C1.DLL`, which links against both the C++ CRT and .Net.
MSalters
+1  A: 

JRuby is an implementation of Ruby which uses the Java Virtual machine. Its possible to say that the Java Virtual Machine is written in C, C++ or some other low level language, but ultimately anything that talks to the hardware directly is written in C, C++, Assembler, or some other low level language.

Zubair
+3  A: 

More a rule of thumb than a law of nature: Compilers for compiled languages are usually written in the language itself. (Examples include Pascal, OCaml, Haskell, ...) This is sometimes obscured by the fact that some languages use a C compiler as a back-end. This is quite common for new languages: e.g. the Glasgow Haskell compiler is written in Haskell, but it creates intermediate C code that is than compiled to native code, thus saving the programmers the tedious task of generating native code for multiple platforms. BTW: Java and C# fall in this category, too. The javac compiler is written in Java, the C# compiler in C#. parts of the runtime/VM are written in C, but not the compiler.

Interpreters for interpreted languages on the other hand are often (though not always) written in another language. Examples include the languages you mentioned. Counterexamples include Lisp or PyPy. I guess the main reason to implement the interpreter in a different language is to get a faster interpreter, which would also explain why C is common choice here (since C has the reputation of leading to fast code).

nikie
ghc only generates c if you specifically ask for it (-fvia-C) . Most of the time it just generates object code directly.
Kyle Butt
+7  A: 

If you are looking for non-C implementations of some popular/great languages, then consider these:

  • Sun's Java VM is implemented in C++ (as per http://www2.research.att.com/~bs/applications.html. You can also checkout the OpenJDK source code)
  • Clojure, Scala and Groovy - all implemented in Java and runs on the JVM.
  • Squeak - a modern Smalltalk with the VM itself implemented in Smalltalk!
  • Arc - A Lisp dialect implemented in Scheme.
  • CLOS - A language (yes it is!) for Object Oriented programming in Common Lisp, implemented, well, in Common Lisp!
  • Factor - A popular concatenative language implemented in C++.
Vijay Mathew
"Clojure, Scala and Groovy" - and of course JRuby and Jython are non-C implementations of Ruby and Python. They just aren't how those two languages were first created.
Steve Jessop
@Steve 'onebyone' Jessop Well, true. I listed languages whose first implementations themselves were not in C.
Vijay Mathew
+3  A: 

The process of getting a language up and running is very interesting. FORTH is particularly interesting in that the core of the language can be implemented in a decidedly small amount of space, then everything else can come along for the ride. From my own memory, you can get away with implementing @, !, +, and - in assembly - maybe one or two stack juggling operators and you're done. See here for more information.

What's particularly interesting is when things start to go wrong in the bootstrapping process. Many years ago I read about a Pascal compiler that was created at a university as a research project. It was written in Pascal, using the existing Pascal compiler and eventually supplanted it. The problem was that there was a bug in the code generation in a particular case and the fix in the compiler source induced bug in the existing compiler, making it impossible to apply using conventional means. Back ups to a non-bugged version were out-of-date. Eventually, the author ended up to very careful binary surgery on the existing compiler.

While C is a dominant systems language, it is certainly not the base-level language for creating other languages. The early Macintosh machines were created with Pascal in mind and most of the first tools and languages were Pascal (or assembly) based.

plinth
Another example is bootstrapping deliberately gone wrong. See: http://cm.bell-labs.com/who/ken/trust.html
rjmunro
+1  A: 

There have been multiple projects started to implement Perl 6, distinguished primarily by their choice of implementation language. Initially, the primary contender (whose name escapes me) was written in Perl 5. The major current focus for Perl 6 is on Rakudo, which is being implemented on top of Parrot using, as I understand it, a language called PIR. (I assume Parrot is written in C and don't know whether Rakudo is using C along with PIR or not; anyone involved in Perl 6 development is invited to edit my answer and fill in these details.)

In principle, any Turing-complete language is capable of being used to write its own compiler. Although this hasn't been done in all cases, it seems to have been done for most, if only "because we can".

Dave Sherohman
http://search.cpan.org/perldoc?v6 Perl 6 on Perl 5 never made it past the prototype stage, as far as I can tell. For a while, the best implementation was Pugs: written in Haskell, mainly an interpreter but also able to compile to Perl 5, JavaScript, and Parrot; now efforts are concentrated on Parrot and Rakudo.
ephemient
+1  A: 

There is even a present-day C compiler not originally written in C

I believe the Green Hills Software C compiler was first written in the early 1980's in Pascal. The company is now a large supplier of aerospace- and mil-qualified embedded stuff and it's possible that the compiler is still in Pascal. But then, I think they also have a Pascal-to-C translator so I guess they could have migrated.

DigitalRoss
+2  A: 

C is the language that most modern operating systems are written in, and thus pretty much every other language that wants to run on modern operating systems and modern hardware has to have the ability to interface to C if it wants to interact with the rest of the world at all. Also, because of this, C compilers are ubiquitous, so you can pretty much always rely on a C compiler being available for any platform you're interested in. For these two reason, many languages are either implemented in C (at least in part), or are written to compile to C (so the version compiled to C can be used to bootstrap).

That said, there are still some languages that have very little contact with C. Clozure Common Lisp (formerly OpenMCL, before that Macintosh Common Lisp, before that Coral Common Lisp) is written entirely in Common Lisp. You need to download binaries of it for some platform in order to be able to compile it. It's very common for Lisps to be written in Lisp (sometimes another dialect, sometimes the same one), as Lisp is much older than C. There were even Lisp Machines in the 1970's and 80's that were designed to run Lisp, and the entire operating system and development environment was written in it.

There are many languages that have a compiler and some libraries written in that language, while some libraries and bits of the runtime are written in C. For instance, CMUCL (and its derivative SBCL) are primarily written in Common Lisp, but they have a small C runtime. The same is true of GHC, the Glasgow Haskell Compiler; it's written in Haskell, so you need an existing Haskell implementation to build it (usually Hugs, as that's written in C and thus makes bootstrapping easier), but it has some C code in its runtime.

Scheme 48 is a Scheme that is is written in PreScheme, a limited dialect of Scheme that can be compiled to C, which is itself written in Scheme. The fact that it compiles to C makes bootstrapping easier; the Scheme 48 distribution comes with the code compiled to C already, so you just need to compile that with your system C compiler to get yourself up and running.

There are plenty of other languages written in languages other than C as well. There's Free Pascal, a version of Pascal written in Pascal. There are plenty of languages written in Java, though the JVM itself is mostly written in C. Erlang was originally written in Prolog (which strongly influenced its syntax), but is not written in a combination of C and Erlang.

All programming languages have to be written in something, if you want them to run on an actual computer. In the beginning, the only choice was writing machine code directly. Soon after, people wrote assemblers (originally in machine code, and later themselves in assembler) to make writing machine code easier. That was then followed by high level languages; FORTRAN, Lisp, COBOL, ALGOL, and later still Simula, Smalltalk, C, Pascal, ML, Prolog. Each of these had to be written in something; the earliest were written in assembler, then later some were written in themselves, and others written in another high level language. By the 80's, C was pretty much the dominant systems programming language, and thus it became the default choice for writing a new language in; and that continues to today. But look back to languages from before then, and you'll find plenty implemented in other languages, or even themselves.

Brian Campbell
A: 

You need to define what you mean by "low-level". Almost all of the languages are going to use C indirectly because most operating systems are written in C or C++. To make any System calls (opening files, network sockets) you are going to have to interface with C.

That being said there have been attempts in writing operating systems in other languages most notably being OCaml and Lisp.

For sure this has been done in Lisp (google Lisp machines).

So Lisp would be most notable (non-dead) language that has succeeded with out C.

Adam Gent