Answer the question
In order to leave comments, you need to log in
Do I understand correctly what a programming language is?
I've been learning php and its frameworks for quite some time now, as well as js and c# . But since I am a teapot by nature, it became interesting whether I understand correctly what languages are and how they work.
If we take compiled languages, then in fact it is just a text file with the necessary extension, and the compiler for them is a program written in assembler that reads this text file and receives a script in it, as it were.
example:
The compiler program has started.
Reading text file test.c
class MyClass{
void myfunc() {
int c = 1488;
}
}
...
myfunc();
Answer the question
In order to leave comments, you need to log in
No, it's wrong.
First, a language is not a text file. This is a set of rules (syntactic, semantic), tokens and other things.
Secondly, the compilation process does not look like this at all. The compiler does not create any variables. Moreover, there are still translators, linkers, validators and more.
Well, yes, compilers have not been written in assembler for a long time.
And it turns out that if this is the case, then the program written in a high-level language without a compiler is just a text file, and also that the finished compiled program will be written in assembly language based on what is written in the source file in a high-level language.
Assembler is also nothing more than a formalized text file; compilers operate with machine codes, which the processor perceives as a specific instruction for action. There are no functions or variables for the processor, only JS-TypedArray style memory and a sequence of instructions like load, store, add, sub, compare, goto to ptr if(compare is signed_less), in the same memory as binary numbers.
It is your example that any optimizing compiler will simply erase. That is, it simply writes the return statement, swearing at the unused variable along the way, or it can even erase the entire function and its calls, because this will not affect the result in any way.
Although, of course, knowing one of the assemblers of the selected processor architecture (and as you know, there are many of them), you can easily write a primitive, non-optimizing compiler that will transfer the generated assembler file to the assembler translator. Which simply translates assembler instructions into the corresponding binary, machine instructions.
In general, if you want to make your own programming language, then I advise you to look towards llvm. This will allow you not to bother with supporting countless processor architectures and optimizing machine codes for them. Habré even has an article on how to make your own llvm compiler.
php and its frameworks, also js and c#
If we take compiled languages, then in fact it is just a text file with the necessary extension, and the compiler for them is a program written in assembler that reads this text file and receives a script in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question