How do we define the implementation language?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    How do we define the implementation language?

    For example, we want to produce a new language called NewLang. When we
    implement
    the compiler of NewLang, we should use languages other than NewLang.
    Correct?

    But I heard Java is implemented in C/C++. More specifically, does it
    mean
    the Java compiler is written in C/C++? But the Java API is written in
    Java itself.
    This is the confusing part.

    How about C++? I always heard people saying C++ is written in C++
    itself. I think it
    means C++ libaries are written in C++. But C++ compiler is written in
    pure C.
    Is that correct?

    My conclusion is that a language's compiler should be written in
    another language.
    But a language's libraries can be written in its own language. Then it
    makes the
    implementation language definition little bit tricky.

    Please advise and discuss. thanks!!
  • Phlip

    #2
    Re: How do we define the implementation language?

    Matt wrote:
    [color=blue]
    > For example, we want to produce a new language called NewLang. When we
    > implement
    > the compiler of NewLang, we should use languages other than NewLang.
    > Correct?[/color]

    You ask how to bootstrap a language into existence.

    For example, Pascal was notoriously implemented by writing the source for a
    Pascal compiler (probably on a typewriter;), and then reading the source and
    pretending to apply it to itself. The output then goes into a real Assembler
    program to produce the ultimate machine opcodes.

    A compiled language, such as a C-style language, typically bootstraps from a
    previous language. Then it's used to compile itself, and this vets its
    capacities. Small-C can bootstrap like that.
    [color=blue]
    > But I heard Java is implemented in C/C++. More specifically, does it
    > mean
    > the Java compiler is written in C/C++? But the Java API is written in
    > Java itself.
    > This is the confusing part.[/color]

    Most languages are implemented in K&R C, to maximize portability. That means
    they are implemented in a sufficiently narrow subset of ISO-C that one can
    compile them with very old (obsolete) K&R C compilers.

    Ruby and Python are both brilliant examples of interpreted OO scripting
    languages that port to a wide range of platforms. One can write Ruby
    expressions directly in C, using a VALUE type and a handful of support
    functions.

    (Perl, by contrast, _requires_ brilliance to use...;)

    All these languages come with complete libraries (up to things like HTTP
    protocol, built-in databases, etc.), mostly written in their own language.
    [color=blue]
    > How about C++? I always heard people saying C++ is written in C++
    > itself. I think it
    > means C++ libaries are written in C++. But C++ compiler is written in
    > pure C.
    > Is that correct?[/color]

    Depends on the vendor. I suspect GNU C++ is written in K&R C.
    [color=blue]
    > My conclusion is that a language's compiler should be written in
    > another language.
    > But a language's libraries can be written in its own language.[/color]

    Well, the exception might be Visual Basic ;-)

    Its libraries are overwhelmingly _not_ written in VB. That should tell us
    something about the language's quality.

    --
    Phlip



    Comment

    • Nils O. Selåsdal

      #3
      Re: How do we define the implementation language?

      Matt wrote:[color=blue]
      > For example, we want to produce a new language called NewLang. When we
      > implement
      > the compiler of NewLang, we should use languages other than NewLang.
      > Correct?[/color]
      In the very first implementation, you have to do that, for obvious reasons.
      [color=blue]
      > But I heard Java is implemented in C/C++. More specifically, does it
      > mean
      > the Java compiler is written in C/C++? But the Java API is written in
      > Java itself.
      > This is the confusing part.[/color]
      There are atleast 2 types of languages, those that are compiled to
      machine/hardware language, and those that are not. C++ is typically
      compiled to "native" hardware language, while java run within a
      virtual machine. Now a virtual machine needs to be written in something
      that will run on actual hardware, C/C++ are suitable for that.
      (And yes, you can very well run C++ within a virtual machine/interpreter
      and you can make hardware that executes java bytecode directly, the
      reverse is what the respective languages were designed for though.)
      [color=blue]
      > How about C++? I always heard people saying C++ is written in C++
      > itself. I think it
      > means C++ libaries are written in C++. But C++ compiler is written in
      > pure C.
      > Is that correct?[/color]
      Yes and no. C++ compilers are usually written in C or C++. The standard
      library is written in C++ usually, it makes more sense...[color=blue]
      > My conclusion is that a language's compiler should be written in
      > another language.[/color]
      Why's that ? It will usually be dictated by wether your language is
      meant/designed to run on actual existing hardware I'd say.[color=blue]
      > But a language's libraries can be written in its own language. Then it
      > makes the
      > implementation language definition little bit tricky.[/color]
      Writing libraries in its own language is often favorable, since other
      languages might have trouble interacting with the new one. Note that
      many languages (e.g. perl,python, and even java) have parts of their
      libraries written in C or C++, often for sake of speed.

      Comment

      Working...