What language do they build other languages with?

后端 未结 8 975
青春惊慌失措
青春惊慌失措 2021-01-31 09:31

What language is used to build low level languages like c++ and java?

How could you build the first language with no language?

相关标签:
8条回答
  • 2021-01-31 10:12

    You don't build a language, but you build a compiler or an interpreter ... and for this you can choose any language even the language you want to compile ...

    The first self-hosting compiler — capable of compiling its own source code in a high-level language — was created for Lisp ... Since the 1970s it has become common practice to implement a compiler in the language it compiles, although both Pascal and C have been popular choices for implementation language. http://en.wikipedia.org/wiki/Compiler

    0 讨论(0)
  • 2021-01-31 10:17

    there are a couple options, you can implement the entire language in a language available on the target host, like C or Ocaml, whatever it may be. Once you have that implementation, you can write a compiler / interpreter in the language itself, build it, and now the language runs itself. this process is called 'bootstrapping'.

    0 讨论(0)
  • 2021-01-31 10:19

    In the context of compilers, this operation is often called bootstrapping. In particular, see the "Chicken and egg problem" section for a direct answer to your question.

    The very first compiler would have been hand-written in assembly language. If your next question is "how was the first assembler written?" then the answer would be that the first assembler was hand-written in binary machine code, possibly with front panel toggle switches. This is undoubtedly a simplification of what really happened, but the concept is the same.

    There is also an excellent article titled Reflections on Trusting Trust by Ken Thompson about the risks of using a compiler for a language to build the compiler for that language.

    0 讨论(0)
  • 2021-01-31 10:21

    Much of this kind of thing is done in C.

    The first C compiler was not written in C; it was PDP-11 assembler. Other early C compilers have been written in various assembler languages.

    But all subsequent C compilers actually are written in C, based on an early "Portable C Compiler". Yes, it's circular. But the version x compiler can be used to build the version x+1 compiler.

    0 讨论(0)
  • 2021-01-31 10:22

    I think the key insight to your question is the notion of boot-strapping. The link will describe how a language can self-host.

    It is relatively common in the Lisp community. e.g. Some university classes will use Scheme to write a language subset (this is not a compiler class activity).

    That said, many compilers are written in other languages. For example, PUGS (Perl 6) is written in Haskell. Ruby is available in C or Java (as JRuby).

    0 讨论(0)
  • 2021-01-31 10:27

    As mentioned by the other posters, you can write a language in practically any language, and often one of the first programs written in a language is a compiler for the language itself.

    However, there are some languages that were specially developed for writing computer languages - namely lex, yacc, flex, bison (updated versions of lex and yacc). These allow you to represent the lexical and grammatical specification of some languages (I believe LLR, or LALR) in a form that can be compiled into an efficient language recognizer.

    You do still have to write other parts of the language compiler/interpreter yourself, i.e. semantic analysis, code generation.

    See

    http://dinosaur.compilertools.net/

    0 讨论(0)
提交回复
热议问题