177

Sometimes while programming in different languages (C/C++, C#), this thought comes to my mind:

  • Is each and every language written in the C programming language?
  • Is the C language the mother/father of all languages?
  • Is each concept (OOP, etc.) all implemented in C?

Am I in right direction?

  • 58
    @X.L.Ant: many (maybe even most) C compilers are written in C. – Jörg W Mittag Dec 22 '14 at 11:07
  • 32
    @Neil: C++ doesn't compile to anything. C++ is a language. Languages don't compile, compilers do. – Jörg W Mittag Dec 22 '14 at 11:07
  • 12
    @X.L.Ant: I don't think so. But the first Oberon compiler, for example, was written in Oberon and then hand-translated (which is a form of compilation, I guess) to Fortran. This compiler was then compiled with a Fortran compiler, the resulting Oberon compiler was used to compile the Oberon compiler and from that point on, the previous version of the compiler was used to compile the next one. – Jörg W Mittag Dec 22 '14 at 11:10
  • 18
    @Neil It's not really that pedantic. It's accurate: a language is a spec. It may be implemented as a compiler, as an interpreter, a hybrid, etc. You can write a compiler for a language, but the compiler is not the language. I guess the issue gets confusing because there are languages for which there is no spec written anywhere except for its reference implementation. But even in those cases, I'd argue the language (i.e. the ideal the author had in his/her mind) is different from the implementation/compiler/interpreter/etc. – Andres F. Dec 22 '14 at 12:54
  • 21
    Downvoters: this is a pretty reasonable question with a clear answer. That the answer is "no" is no reason to downvote. Instead, consider answering and explaining. – Andres F. Dec 22 '14 at 12:57
206

No.

OCaml, Haskell, Lisp dialects like Scheme, and several other languages are often used in the development of hobby languages.

Many languages are implemented in C because it's a ubiquitous language, and compiler-writing tools like lexer-parser generators (such as yacc and bison) are well-understood and almost as ubiquitous.

But C itself couldn't originally be developed in C when it was first created. It was, in fact, originally developed using the B language. Earlier languages (like Fortran) were usually bootstrapped using a native assembly language or even machine code long before C ever existed.

Unrelatedly, language paradigms like OOP are generally language-agnostic. The functional paradigm, for example, was developed mathematically (by Alonzo Church) as a branch of set theory long before any programming language ever existed. The procedural and structured programming paradigms came out of the mathematical work of theorists like John von Neumann. Object-orientation was developed by several different and unrelated efforts, some out of the lambda calculus (the functional paradigm) and some out of dynamic programming systems like SmallTalk at Xerox PARC by Alan Kay.

C is merely a tiny part of the story, decades after these ideas came into being.

  • 40
    While it's true that the first C compilers obviously couldn't be written in C, it's certainly possible now. – reirab Dec 22 '14 at 15:14
  • 17
    @reirab Posible AND true. GCC is written in C and usally compiled using GCC. – Darkhogg Dec 22 '14 at 23:30
  • 8
    Of course, GCC is now being rewritten in C++, but that's not as important as the fact that the first C compiler couldn't be written in C. – greyfade Dec 23 '14 at 1:35
  • 10
    @greyfade gcc hasn't been C for some time. It is not "now being rewritten" it is "has been written in C++ for over two years" (its even older than that though, thats when the merge happened that moved it to C++). – user40980 Dec 23 '14 at 4:26
  • 13
    @greyfade isn't "C but with C++ features" sort-of the definition of C++? – KutuluMike Dec 23 '14 at 12:52
91

Is each and every language written in C language?

A language is a set of abstract mathematical rules and restrictions ("if I write this, that happens"). It isn't written in anything, really.

It is specified, usually in a mixture of a formalized subset of English, mathematical notation, and maybe some specialized specification language. The syntax is often specified in a variant of EBNF or ABNF.

For example, here is the specification of the for expression from the ISO Ruby Language Specification:

§11.5.2.3.4 The for expression

Syntax

  • for-expression for for-variable [no line-terminator here] in expression do-clause end
  • for-variable left-hand-side | multiple-left-hand-side

Semantics

A for-expression is evaluated as follows:

  1. Evaluate the expression. If the evaluation of the expression is terminated by a break-expression, next-expression, or redo-expression, the behavior is unspecified. Otherwise, let O be the resulting value.
  2. Let E be the primary-method-invocation of the form primary-expression [no line-terminator here].each do | block-parameter-list | block-body end, where the value of the primary-expression is O, the block-parameter-list is the for-variable, the block-body is the compound-statement of the do-clause.

    Evaluate E; however, if a block whose block-body is the compound-statement of the do-clause of the for-expression is called during this evaluation, the steps in §11.3.3 except the Step c) and the Step e) 4) shall be taken for the evaluation of this call.

  3. The value of the for-expression is the resulting value of the invocation.

Here's a different example from the type conformance rules of Scala:

The polymorphic type [a1 >: L1 <: U1 , … , an >: Ln <: Un]T conforms to the polymorphic type [a1 >: L′1 <: U′1 , … , an >: L′n <: U′n]T′ if, assuming L′1 <: a1 <: U′1 , … , L′n <: an <: U′n one has T <: T′ and Li <: L′i and U′i <: Ui for i ∈ { 1 , … , n }.


Is C language mother/father of all languages?

No, it is not. C is pretty young. There are a lot of old languages. Since time travel is physically impossible, it is simply impossible for C to have had any influence whatsoever on those old languages.

  • Plankalkül (1943)
  • Speedcoding (1953)
  • Fortran (1954)
  • IPL (1956)
  • Lisp (1958)
  • Algol (1958)
  • COBOL (1959)
  • JOVIAL (1960)
  • APL (1962)
  • SIMULA (1962)
  • SNOBOL (1962)
  • CPL (1963)
  • BASIC (1964)
  • PL/I (1964)
  • RPG (1964)
  • BCPL (1966)
  • ISWIM (1966)
  • MUMPS (1967)
  • Forth (1968)
  • LOGO (1968)
  • REFAL (1968)
  • B (1969)
  • BLISS (1970)
  • Pascal (1971)
  • KRL (1971)
  • Smalltalk (1972)

All of those existed before C was even invented. And many others have no influence of C in them, even after it existed. The PASCAL-family of languages (ALGOL-58, ALGOL-60, ALGOL-X, ALGOL-W, PASCAL, Modula-2, Oberon, Oberon-2, Active Oberon, Component Pascal) is a completely separate lineage. The whole Lisp family (LISP, Franz Lisp, InterLisp, MacLisp, Scheme, Flavors, LOOPS, CommonLoops, Dylan, CommonLisp, Arc, Clojure, Racket, etc.) is unrelated as well. Functional languages (ISWIM, KRL, Miranda, ML, SML, CAML, OCaml, F#, Haskell, Gofer, Clean) and the whole dependently-typed family (Agda, Coq, GURU, Idris) are about as far from C as possible. The same is true for the Smalltalk family (Smalltalk, Self, Newspeak, Us, Korz), the logic programming family (PLANNER, Prolog, Mercury), SQL, and many others.

Each concept (OOP etc) is all implemented in C language?

The first languages with OO concepts were Simula (1960) and Smalltalk (1972), but object-oriented systems had been built as far back as 1953 (without calling them that). Again, that's long before C existed, so OO cannot possibly have any relation to C.

50

Most of the core of many important languages is written in C, but things are changing:

  • the reference implementation of Python (CPython) is written in C (but there are other implementations written in other languages, e.g. Jython / Java, PyPy / Python, IronPython / C#...)
  • PHP Zend Engine is written in C
  • very first Java compiler developed by Sun Microsystems was written in C, but now the class libraries are always written in Java (since they are intended to be run using the Java VM itself). Certain libraries using JNI (Java Native Interface) may be partially written in a variety of other languages, as they are intended to be used OUTSIDE the JVM.

    The Sun/Oracle VM is written in C++. The BEA/Weblogic/Oracle VM is written in C. But there are JVM written in Java, Lisp, SmallTalk (IBM)...

  • Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C (but Pugs, a compiler and interpreter for the Perl 6 programming language, is written in Haskell)
  • the official Ruby interpreter, often referred to as the Matz's Ruby Interpreter or MRI, is written in C and uses its own Ruby-specific virtual machine (but there is JRuby, a Java implementation that runs on the Java virtual machine; Rubinius, a C++ bytecode virtual machine that uses LLVM to compile to machine code at runtime...)
  • about 50% of R is written in C
  • and, of course, C is (was) written in C! (but the first C compiler, targeted to the PDP-11, was a mix of B and assembler).

There are many reasons why C was often chosen: performance, portability, experience.

The last probably being the most important: Python was started in 1991, PHP in 1994/1995, Perl in 1988, Ruby in 1995. In those years Java was just released and C++ not yet well standardized.


Somewhat related:

  • 5
    From the perspective of compilers/interpreters implementation, C has been/is a reference point. In addition it has directly or indirectly influenced many later languages (at least syntactically). – manlio Dec 22 '14 at 10:41
  • 2
    pretty soon, you'll be able to say that C# was written in C#! (kind of) – DLeh Dec 22 '14 at 18:44
  • 1
    Most of Mono (which includes a C# compiler and many/most of the .NET base class library) is written in C#. – Charlie Kilian Dec 23 '14 at 6:31
  • 3
    The answer to the question "is C the mother/father of all languages?" is "no", so I don't think it's helpful to provide lots of examples which are written in C. Counter-examples would help, but your choices are still descended from C. For example, even if Java, Python, etc. are now self-hosting, they were still bootstrapped from C, so they're like "grandchildren" of C. Languages like LISP, FORTRAN, ML and (of course) machine code are true counter-examples, since C was never involved in their creation. – Warbo Dec 23 '14 at 18:39
  • 2
    The aspiration for many languages is, of course, to be implemented as far as possible in itself. However, it seems like most languages depend on C because most languages need to be able to call C to be useful; the majority of modern operating system APIs and useful libraries tend to have C bindings. You also have to be careful about what you mean by "written in". A language implementation typically has multiple parts: at least a compiler and a runtime system. Runtime systems are often written in C to better interface with the OS. – Pseudonym Dec 24 '14 at 0:21
10

No, some languages pre-date C. And many are implemented independently of C, e.g. see http://en.wikipedia.org/wiki/Lisp_%28programming_language%29

  • 2
    There are many implementations of Java, most are written in Java. The GNU implementation of Objective-C is written in C (or C++, they changed recently, I believe), the LLVM implementation is written in C++, and there used to be an interpreter written in C#. There are many implementations of Python, one is written in RPython, one in Java, one in C#, and one in C. PHP has six main implementations, two in Java, two in C#, one in C and one in C++. – Jörg W Mittag Dec 22 '14 at 9:28
  • 1
    No. Language designers are certainly influenced by other languages, but they can choose to ignore those influences if they so wish. – Jörg W Mittag Dec 22 '14 at 11:08
  • 2
    @FaizanRabbani languages, in essence, are concepts and choices of paradigms, patterns and compromises - very often a "language is created/adapted from other language(s)" but that's completely unrelated to the implementation language of its compiler; language X can be derived from language Y but implemented in C or something completely else - and that often is the case. And in this case, the 'conceptual ancestor' is important but the compiler language is just a barely relevant technical nuance that can change over time. – Peteris Dec 22 '14 at 16:44
  • 3
    That last link if of dubious value - too many mistakes in it to really take it seriously. – Unknown Coder Dec 22 '14 at 16:50
  • 4
    @SebastianGodelet: HotSpot is not an implementation of the Java language. It's an implementation of the JVM bytecode language. Those are two completely different languages. The most widely used implementations of the Java language are javac from the Oracle JDK / OpenJDK written by Martin Odersky (of Scala fame) in 100% Java, the Eclipse Compiler, written in 100% Java (derived from IBM's Jikes compiler), the compiler from IBM's J9, also derived from Jikes and 100% Java. AFAIK, the only Java compiler in somewhat widespread use that is not written in Java is GCJ – Jörg W Mittag Dec 23 '14 at 15:54
4

I would make this a comment if I could, but I can't so here goes:

One of the reasons C seems so ubiquitous is because it is one of the earliest languages developed, and an enormous amount of modern languages are based off of its structure (Java, Go, PHP, Perl, etc.) - making it seem like it's more places than it is.

Another oft-forgotten reason is that in 1973 Unix was rewritten in C and many of Unix's system calls are also available as C programs/functions, making the two highly interlinked. Since Unix was a powerful part of the development of modern programming as a whole, C was dragged along into infamy with it.

Having said all that, the answer to your question is "No". C is based off of a language called ALGOL, and there were many competitors both with ALGOL (FORTRAN, Lisp, COBOL) and C (none come to mind). Object-oriented programming, arguably the biggest paradigm-shift in programming design, did not originate with C - despite C++ being a very popular OOP language (it showed up first in Lisp or Simula 67, depending on who you ask). By the time OOP came about, C was such a popular language that it didn't need to be first - it was so popular that the C++ "expansion", so to speak, became one of the primary OOP languages too. It remains in modern use mainly because of its powerful memory control features (you can directly allocate and deallocate the memory your structures create), allowing it to create programs on tight memory budgets (think video games) and its highly optimized compiler (obviously depending on the compiler). Admittedly, even these features are losing ground as Java JIT compilation and in-language memory managers become more advanced.

3

Obviously not. How could the first C compiler be written in C if C wasn't exist before? This isn't the chicken and the egg problem.

There are many ways to write the first compiler of a language which are called bootstrapping

Moreover most compilers try to achieve self-hosting, or compile itself it its language, mainly to promote the language and the compiler itself

  • 12
    The first Oberon compiler was written in Oberon. That's perfectly fine, provided you are a professor and have lots of students that will hand-translate the compiler for you (which Prof. Wirth had). – Jörg W Mittag Dec 22 '14 at 21:38
  • @Jorg that was mentioned in the bootstrapping article linked above so I don't bother writing that because this question is about C and no C compiler was written that way – phuclv Dec 23 '14 at 2:39
  • 14
    @JörgWMittag - the first automated Oberon compiler was written in Oberon. The actual first Oberon compiler was a bunch of students. – nnnnnn Dec 23 '14 at 22:33
  • 4
    @nnnnnn: I would consider this "bunch of students" an interpreter, not a compiler. – Paŭlo Ebermann Dec 25 '14 at 18:23
  • 4
    @Paŭlo Ebermann To add another human element: "computer" was originally a job title. – chux Jan 3 '15 at 6:59
2

Here is a list of some programming languages that are not written in C, alongside the languages they are implemented in:

  • Haskell - Haskell
  • Idris - Haskell
  • Adga - Haskell
  • Clash - Haskell
  • PureScript - Haskell
  • Elm - Haskell
  • Mercury - Mercury
  • Rust - Rust (initially OCaml)
  • Go - Go
  • Crystal - Crystal
  • OCaml - OCaml
  • Frege - Frege + Java
  • Haxe - OCaml + Haxe
  • Scala - Scala
  • Futhark - Haskell
  • ATS - ATS

The best languages for implementing a compiler are probably going to be pretty far away from C. Functional languages give you things like recursion schemes and monadic parser combinators (provided you have typeclasses), which makes them especially suited for compiler work.

Second, to address your question as to whether C is the "mother/father of all programming languages" - not really. C was a well-designed language at the time it appeared, and it no doubt has influenced language designers who then went on to do very different things. But at the end of the day, Haskell departs from C in essentially every way possible. C is 45 years old and it is not surprising that we have learned to do better in the meantime.

Finally, to answer your third question, it is simply not the case that C implements "all the concepts". In particular, trying to implement some of the advanced concepts from functional programming (such as metamorphisms, or, god forbid, synchromorphisms) in C would be monstrously difficult. I am not particularly familiar with object-oriented programming, but I do know for a fact that some object-oriented languages have sum types.

  • C was never "an incredibly well-designed language." The warts that we see on it today were known to be warts from the very beginning. But, it was good enough to be the native language of the developer-friendly Unix operating system, and after Bell Labs pushed Unix out into the universities, C/Unix became a favorite language/OS for a generation of computer professionals. – Solomon Slow Sep 22 '17 at 21:06
  • PS., There weren't a lot of original ideas in C. If You're looking for the mother/father of all block-structured, procedural programming languages you might want to have a look at ALGOL. – Solomon Slow Sep 22 '17 at 21:09
1

Programming languages are specifications (not software!) usually written in some English document (with some formalization, e.g. EBNF for most of the syntax; sometimes their semantics is also partly formalized).

For example, C11 is defined by n1570 (which you should read). Some dialect of Scheme is defined by R5RS (which you should also read, it is very well written).

Programming languages may be implemented by some software. Sometimes that software is a compiler written in the programming language itself. Read about bootstrapping compilers.

One can write a compiler in the compiled programming language itself. If that language XX is brand new, you need to go thru a temporary step which involves writing a minimal interpreter or compiler of a subset of that language in some other implementation language (perhaps C), and later your can throw away that temporary compiler or interpreter (which don't need to be "good", just to be enough to compile the other compiler). Once you compiled your XX compiler written in XX you can throw away your temporary compiler.

Often (but not always) the runtime system is partly written in C (in particular the garbage collector).

Notice that bones is a Scheme compiler and runtime entirely written in itself (and you can find many other examples of fully bootstrapped implementations).

BTW it is convenient to use C as the target language of compilers.

Today, a lot of programming languages implementations is free software or open source. Feel free to study (and perhaps contribute to) their source code!

protected by World Engineer Dec 22 '14 at 19:29

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.