¿Cómo se crean los compiladores?

When a compiler is created for a particular language, do the people who develop the compiler define the language and it's commands right from the beginning as if the language never existed (This seems unreal)? or is there a way to use previous compilers? or how else do they do it?

preguntado el 08 de noviembre de 11 a las 11:11

4 Respuestas

Either they define a [domain specific] language or implement some already existing language.

A language is typically written in a certain form called BNF

One method to create a compiler (or at least lexer and parser) is to use a tool, there are several tools like yacc/lex, ANTLR etc which can be used to generate the raw plumbing for the compiler, tokenizing the file and parsing the tokens. Check out antlr.org for some examples of a pretty easy to use tool that generates C#, Java or C code parser/lexers.

respondido 08 nov., 11:15

I'm guessing you are assuming that the compiler is written in the same language it compiles. This is not the case. The process is called bootstrapping. The first C# compiler was written in C++. The first C++ compiler was written in C. The first C compiler was written in B. The first B compiler was written in BCPL. Beyond which it gets fuzzy, ancient history and all that. This does ultimately go back to somebody entering a program into a machine with toggle switches.

Addressing the first part of your question: yes. Nobody sets out writing a compiler without a very strong definition of the grammar of the language. This can be worked out on paper.

respondido 08 nov., 11:16

I'm not assuming that, and I'm not talking about creating the first compiler for a new language, I'm talking about creating a compiler for an already existing language. - Sameh Hany

Then I don't know what you are asking. Particularly the "this seems unreal" comment is confusing. - Hans Passant

@Sameh, so you're talking about an "already existing language" y at the same time "define the language..as if the language never existed": seems like a contradiction that makes the question hard to do justice to. - ángel

I'm saying that it's unreal that the compiler developers will have to redefine a language every time they create a compiler for the language. - Sameh Hany

@SamehHany: If they redefined the language, they wouldn't create a compiler for that existing language but one for a slightly different (and thus distinct) language. A language is not defined by any compiler. - user395760

It all depends on the language. If the language doesn't exist (and remember that none did in the beginning) then of course it must be designed before the compiler. But if you just want to make changes to an existing language it might be easier to take an existing compiler and make the changes you want.

I have personally made a few compilers for little languages that I thought up my self, and created the compilers from scratch. Sometimes using tools such as lex y Yacc, sometimes by hand-coding it all.

respondido 08 nov., 11:15

The evaluation of Language have started since the born of computer, and the first optimzation compiler came up in around 1960s.

The simplest answer to your question is that language design comes up first, and then compiler developer develop the compiler follow the standard. And then the language designer get feed back from the user community,and make changes to the language standard, and the compiler developer work on this new standard again.

compiler support for C++0x standard

Usually, compiler developer develop new language feature support only use the already supported feature of the compiler.

respondido 08 nov., 11:15

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.