Creating programming languages and compiler designing. Are they related?
Alright, I guess this question has been开发者_JAVA技巧 asked a lot of times here.
I want to create a programming language, not necessarily starting today, but over a span of 2-3 yrs. I'm not a very good programmer, but I'm improving. What I wanted to ask is how closely creating a language and writing a compiler related?
Since, a compiler translates a language from one form into another, I guess it's all about writing a compiler for a particular piece of text. SO if I learn compiler design, will I be able to write my own programming language?
You can design a programming language without knowing anything about implementing compilers, and vice versa. The language designer can write a specification for the language, and a compiler implementor can then take that and create the compiler.
However, if this is a personal project, then you will probably have to learn how to do both. A programming language for which there is no compiler is purely theoretical, and it is difficult to figure out how good a programming language is without writing and executing real programs with it. Even if you do find someone willing to implement the compiler for you, you might not want to have to wait for that person every time you have a new idea to try, so you will want to know how to do it yourself.
Implementing a compiler is a pretty advanced programming project, so if you are just getting started as a programmer, you have a steep learning curve ahead of you. You might want to start by looking at the tutorials and examples for LLVM, although that might not actually be a suitable compiler infrastructure for your language.
Naruto, it depends on what kind of "Language" you want to create. If it is a simple, just-for-learning language, and you choose the grammar, etc, etc, you won't need to know a lot about programming. BUT, if you are going to deal with a serious one, you will have to study at least one computer programming language deep not only to use it, but to try to reach several of its concepts, for example, like OO, generics, lambda expressions, etc, etc.
Believe me, this is not a task of months, but a serious journey. Anyway, I wish you luck ;)
Intimately related. You really don't have a language unless you have a way to interpret/compile it into an executable form.
It depends on what you mean by "compiler". Compilers/interpreters usually consist of two big parts: a parser part, which reads a text in your language and builds an internal structure (AST) out of it, and a code generation/interpretation part, which reads the AST and translates it to machine or byte codes. While you definitely will need to know how to write a parser for your language, code generation is less important, at least, at the early stages. You can start by simply translating your language to C and see where you go from there.
精彩评论