arrow_back How to write a programming language?

2 votes
Is it possible to write a programming language in Flat Assembler to create applications with a compiler, simple syntax.
On the expanses of the Internet flies "one water", and I would like a detailed answer to this question with links to useful articles on the subject

1 comment

you can start here. There's enough to study for a couple of years.

3 Answers

Best answer
0 votes
An extended answer would take many books, so briefly...
There are two types of languages: compiled and interpreted.

The complexity of creating the former is translating high-level abstraction into low-level code (+memory management and other complicated stuff). The easiest approach is to come up with your own syntax, which translates into some C++ or C

But I recommend that you make an interpreted language (with the Script postfix). In that case you can just process commands likeif cmd='add' then return a+b

And if you don't want to deal with all that, it is better to use a parser-compiler generator. Then write your own language compiler (bootstrapping) to get an independent compiler.

P. S.
Your question about assembler is not clear. Do you want to write a parser and a compiler in assembler or do you want to translate your language into assembler? Or an assembler interpreter? The lower the level, the more options you have.
4 votes


Ivan Balashov , the detailed answer to the question "how to write a programming language" is precisely in these books.
Naturally, it will take you a long time to read and UNDERSTAND them - but how else would you like it? They haven't learned how to put a cord in the back of your head yet.
GavriKos , the answer to the question should be like a summary of the book
And how many years do I have to look up literature on this list and read

I expected to see a detailed answer to the question, not a list of books on the book
Denioo What do you know about me
GavriKos , look up
Ivan Balashov I don't think it's possible to create a language with this approach!
Ivan Balashov , the first impression is enough)
Ivan Balashov ,
And how many years do I have to look up literature on this list and read

No one will retype a whole book + a bunch of related material just because you are too lazy to read the original, written by people who obviously know a thing or two about writing compilers. If it were a simple subject, they wouldn't write a book thousands of pages long on it. If you're very itchy, start with the compiler for an esoteric language (it's really interesting and useful). It will come out sloppy, but you will understand why so many books were written on the subject. And yes, the same Sharp compiler is freely available on githab. You can read the source code to get at least a rough understanding of the complexity of this endeavor.
3 votes
You can, but you can't.
Even creating a compiler for an existing language takes years for teams of professionals, with excellent specialists in a variety of fields.

I understand you want to make a translator from your language to Assembler? Even for a simple language, the task would be extremely difficult, unless of course the language is Turing-complete.


pqgg7nwkd4 , the author wants to write a complete programming language in FASM, which will be compiled into the same FASM and from there into machine code or PE file.
Ternick Exactly
Ivan Balashov It's not wrong to want.
What is the "extreme difficulty"?
Once I had a task to optimize the interpreter for formulas (expressions) in an already completed project. The optimization went as far as JIT compilation, which is essentially compilation to machine codes. Add loops, library imports, etc. to it. - not such a big problem.
And the author, as I understand it, wants to translate into assembler and build with it - is also not difficult. And if you translate into C, then you can build for anything.

It seems to me that the complexity is not in the compiler itself, but in the bundling: debugger, development environment, documentation. That's where you can drown.