views:

273

answers:

8

Hi,

maybe this is just a little misunderstanding but how can a programming language be implemented?

I'm not talking about how to implement my own programming language but about the word "implemented"? I mean, you can implement a compiler or an interpreter, but a programming language?

What does it mean if I read "C++ is implemented in C" or "Python was implemented in C"?

I think a language is more sth. like a protocol of how someone thinks about things should be implemented. For example, if he wants do display a messagebox he can say the command for this is ShowMessageBox(string) and implement a compiler who will translate this into something that works on a computer (aside from the selected programming paradigms he imagines).

I think this question leads to the question "what is a programming language in reality"? A compiler, an interpreter or just a documented language standard about how things should be implemented in a language?

[EDIT]

Answer: Languages are never implemented, only compilers/interpreters etc. It's this simple.

+7  A: 

"C++ is implemented in C". I understand this as "C++ compiler is written in C language". Quite simple, without too much philosophy.

Generally, C++ compiler can be written in any language, including C++ itself (except of the first compiler version).

Alex Farber
At least in theory even the first compiler version could be: but (not being compiled) it would have to be interpreted by a human, instead of executed by the machine.
ChrisW
Well, in this case this human can be interpreted as first compiler version :)
Alex Farber
I think the point of the question was that the statement "The C++ compiler is written in C" is ill-defined because "The C++ compiler" does not exist. And the alternative interpretation "Every C++ compiler is written in C" is simply false.
sepp2k
+3  A: 

A programming language is a standard. Its interpreter or compiler is an implementation of this standard.

kbok
+1  A: 

To build a new language, you don't necessarily needs to do in in low level machine code (assembly for instance). So, using another language to accomplish your goal (creating a new language here) is perfectly normal. So, when we say: Python was implemented in C, it just means that C was used to create that language. For instance, C can be complied on many different architecture, so the programmers doesn't have to take care of the different type of computers (portable).

A language is just a way to express yourself to the computer. Today, it can be done in various ways. But when you use the same syntax as the language and create your own framework, it's called a library or framework. A programming language is just a notation for writing program. If the notation change, you have a different language. Like French or Spanish comes from Latin. (French is implemented in Latin ;)

Why is there so many different languages? Because the goal of a language is to solve complex problems. So, depending on what you want to try yo accomplish, choosing the appropriate language can be an important decision.

AngeDeLaMort
That whole "French or Spanish comes from Latin. (French is implemented in Latin " is wrong. That's more influenced by. C# was influenced by C, Python was influenced by Perl etc. But C# is not an implementation of C.
Dominic Bou-Samra
It's not totally wrong, but I see your point. But I still think that's an interesting comparison. From the wiki: "French is a descendant of the Latin language of the Roman Empire..."
AngeDeLaMort
@AngeDeLaMort: But modern French had influence from numerous other sources, most notably Gaulish (Gallic), a Celtic language with similarities to modern Irish Gaelic (Gaeilge), Scottish Gaelic (Gàidhlig), and Welsh (Cymraeg).
Jon Purdy
@Jon yes, as english as well. But my point is that a programming language is pretty much like a real language. Evolution and influence is part of it. Maybe my comparison is not the best, but I think my goal there was to make a simple metaphor in order to understand the problem more clearly.
AngeDeLaMort
@AngeDeLaMort: That's fair. This reminds me: when learning a second language, it's important to learn the language as though it's your first, that is, your "implementation" of the language should "compile" directly to understanding, rather than be translated into your native language for subsequent comprehension. I think perhaps there's a more apt metaphor in there somewhere.
Jon Purdy
A: 

The direct answer: Implementation in the context you are talking about just means written and language actually means compiler. The original C++ compiler was as I understand it written in C. There is nothing (apart from knowledge and time) to stop you from writing a C++ compiler in another language.

Implementation is the code that makes software work. Often we talk about the implementation of a function as in: "the function has not been implemented yet." eg void foo()
{
//function has not been implemented yet
throw();
}

This often happens during the design phase of a program because the call needs to be there in order to write/debug/concept test the calling code but we haven't got round to implementing (writing the code to go insde the function)

developer
+2  A: 

"Python was implemented in C" means that at least one Python compiler (in this case the most commonly used one) is written using C. The developers of that implementation of Python made a deliberate decision not to use C++. As a statement it is incomplete as Python has also been implemented in Java, in C# and in Python.

The main relevance is that it gives you some idea of the systems you might be able to port the language onto: anything targeted by a C compiler should (at least in theory) be capable of running the C implementation of Python, but if they'd chosen to use C++ there would be a smaller set of systems that could run it.

C++ usually isn't implemented in C these days: I believe it is usually implemented in C++. It is quite common for languages to be implemented in the same language (or a subset of the language) as it means you are no longer dependent on some other unrelated language being available for the target. To bootstrap onto a new system you cross compile from some other system.

If you compile gcc for a new platform the build process involves compiling the source code once with whatever compiler is already available (perhaps an older gcc), then compiling it a second time with the newly compiled compiler, then compiling it a third time with the output from the second compilation. If the second and third versions aren't identical you get a build error. If they are identical then you've got a pretty good indication that it compiled correctly.

Duncan
+7  A: 

Here's a very academic answer (from a longtime academic). First I'll reframe the question:

What does it mean for a programming language to be implemented?

I'll start with "what is a programming language":

  1. A programming language is a formal language (a set of utterances we can characterize precisely through algorithmic rules) such that a sentence in the language has a computational meaning. There are a variety of ways to give computation meaning; two of the most popular are that a computation stands for a function (from values to values, or from machine states to machine states) and that a computation stands for a machine that makes "state transitions" and interacts with the outside world.

  2. A language is implemented when a means is provided to read in an utterance and perform the computation, that is, calculate the function or perform the behavior. The means is the implementation.

Typical implementations include

  • Direct interpretation of the language syntax. This model is rare but FORTH probably comes closest to it.

  • Translation of the syntax into virtual-machine code, also called bytecode, which is itself another language and which is interpreted. It is popular to write bytecode interpreters in C. Lua, Perl, Python, and Ruby are implemented more or less this way.

  • Translation of the syntax into hardware machine instructions, which is itself another language, and which is interpreted by your CPU. C and C++ are typically (but not always) implemented this way.

  • Direct interpretation of the language in hardware. IA-32 machine code and AMD64 machine code are implemented this way.

When a person says "Language X is implemented in Y", they are usually saying that a translator for X or an interpreter for X's bytecode is written in language Y. One of the great secrets of compiler writers is the ability to write the compiler for language X in language X itself. If this interests you, get Andrew Appel's paper Axiomatic Bootstrapping: A Guide for Compiler Hackers.

Sometimes the answer to this question is not obvious. Squeak Smalltalk writes both a translator and a bytecode interpreter in Smalltalk, then translates the interpreter to C, which is translated to machine code. What is Squeak implemented in? Smalltalk.


Poke a professor; get a lecture.

Norman Ramsey
If I could accept 2 answers, this would be my second choice. Nice explanation. +1 for you...
Inno
+4  A: 

You are right, those statements don't make any sense. It's pretty obvious that whoever made those statements doesn't understand the difference between a programming language and a compiler (or interpreter).

This is a surprisingly common problem. For example, sometimes people talk about interpreted languages or compiled languages. That's the same thing: languages aren't interpreted or compiled, they just are. Interpretation and compilation are traits of the implementation not the language.

Another goodie: Python has a GIL. No, it doesn't: one implementation of Python has a GIL, all the other implementations don't, and the Python Language itself certainly doesn't. Or: Ruby has green threads. Again, not true: Ruby has threads. Period. Whether any particular language implementation chooses to implement them as green threads, native threads, platform threads or whatever, is a trait of that particular implementation, not of Ruby. And of course my favorite: Ruby 1.9 is faster than Ruby 1.8. This doesn't even make sense: Ruby 1.9 and Ruby 1.8 are programming languages, i.e. a bunch of abstract mathematical rules. You cannot run a programming language, therefore a programming language can never be "faster" or "slower" than another one.

The most blatant confusion about the difference between programming languages and implementations is the Computer Language Benchmark Game, which claims to benchmark languages against each other but in fact benchmarks implementations.

All of these are just different expressions of the fact that apparently some people seem to be fundamentally incapable of grasping the concept of abstraction. Or at least the concept of having an abstract language and a concrete implementation of that language.

If we go back to the statement that "Python is implemented in C", it should now be obvious that that statement is not just wrong. If the statement were wrong that would imply that the statement even makes sense, i.e. that there is some possible world out there, in which it could at least theoretically be right. But that's not the case. The statement is neither wrong nor right, it simply doesn't make sense. If English were a typed language, it would be a type error.

Python is a programming language. Programming languages aren't implemented in anything. They are just implemented. Compilers and interpreters are implemented in languages. But even if you interpret the statement this way, it isn't true: Jython is implemented in Java, IronPython is implemented in C#, PyPy is implemented in RPython and Python, Pynie is implemented in PGE, NQP and PIR. (Oh, and all of those implementations have compilers, so there goes your "Python is an interpreted language".) Similar with Ruby: Rubinius is implemented in Ruby and C++, JRuby and XRuby are implemented in Java, IronRuby, IronRuby and Ruby.NET are implemented in C#, HotRuby is implemented in ECMAScript, Red Sun is implemented in ActionScript, RubyGoLightly is implemented in Go, Cardinal is implemented in PGE, NQP and PIR, SmallRuby is implemented in Smalltalk/X, MagLev is implemented in GemStone Smalltalk and Ruby, YARI is implemented in Io. And for C++: Clang (which is the C, C++ and Objective-C frontend for LLVM) is implemented in C++ (all three frontends are implemented in C++).

Jörg W Mittag
"If English were a typed language, it would be a type error." - loved it
Nivas
A: 

The statement "Language X is implemented in Language Y" makes sense and is true if and only if there exists a canonical implementation of Language X and that implementation is written in Language Y. In common usage, either the first or the most popular implementation is often assumed to be canonical.

For example, Perl is one of the few languages with a definitive canon. "Python is implemented in C" makes sense if CPython is taken to be the canonical implementation of Python, and "C++ is implemented in C" is true for CFront, the original implementation of "C with classes" by Bjarne Stroustrup.

Jon Purdy