How is it possible that written a programming language like CoffeeScript in itself like CoffeeScript? Firstly CoffeeScript doesn't exist that read CoffeeScript scripts and interpret them?


2 Answers 2

  • First you design a language A on paper and white board.
  • Then you write an implementation of a language A (compiler, vm, interpreter, runtime depending on a scope of language) in language B.
  • Once you have stable environment for language A, you can start writing version of environment for language A in language A.

I would say, that unless language is slow or not turing complete, it's tools should always be implemented in it. That makes it's much easier for developers to work with it.

  • 2
    I have to disagree with your last statement, or specifically with its absoluteness ("always"). Some languages are good for writing compilers in, some aren't. You have to weigh the benefits of writing a compiler in the language it compiles and thus increasing the amount of people able to work with it (because they only need to understand one language, not two) against the increase in complexity caused by using a language that might not be up to the task. I personally would much rather maintain a SQL compiler written in Scala than one written in SQL. Jun 19, 2013 at 8:53
  • 2
    Wrong. Language traits that are required for writing compilers (pattern matching, ADTs, compile-time metaprogramming, etc.) are not necessarily the traits you want in your target language. And, by the way, you don't need a Turing-complete language to write a compiler.
    – SK-logic
    Jun 19, 2013 at 9:39
  • @JörgWMittag I'm sorry, I meant turing complete languages, I've edited my post. Jun 19, 2013 at 9:49
  • @SK-logic last paragraph is my opinion. And I didn't say that you need turing complete languages to write compiler, you don't need languages with fast environments to write compiler either. That is my preference and my opinion. In the end, if I'm a full time LanguageA programmer, I will understand LanguageA better than other languages, even if we suppose that there is LanguageB that's the best language to write compilers. Jun 19, 2013 at 9:52

Think of a subset of language to build another language. Don't watch it as building A with A but instead building A with B where B is a small language.

Think of it in this way: You build a simple interpreter with JavaScript and name it CoffeeScript, later on as your project goes bigger and bigger you start writing parts of your code with your new functions/construcs or in short - your own language like CoffeeScript.

  • 1
    The first compiler was written in Ruby, not JavaScript, but yeah, that's basically how it works. Jun 19, 2013 at 8:50

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