F
F
fsgdoterr2021-11-24 21:06:12
Programming
fsgdoterr, 2021-11-24 21:06:12

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();

I see a class called MyClass and a function called myfunc which owns a local variable c.
I register a value in a hip named Myclass;
I register a frame on the stack with the name myfunc and put a variable inside it with a value of 1488. I
clear the memory.
I create a program in assembler based on what I read.
.
(if it is not entirely clear what I meant, then asm reads the file and sees the written number 1 and, using the codes embedded in the program, understands that in the finished program you need to put the "example" command instead of 1)
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.

And also, in order to write your own PL, you need to know the assembler, and just write a compiler program in assembler that substitutes embedded values ​​instead of some values.

I'm not eloquent, so I'm not sure that I correctly described it as I understand it, but I think I made the point clear. Is it correct? if not, what is wrong?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
GavriKos, 2021-11-24
@fsgdoterr

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.

Well, this is correct in some approximation, though not necessarily in assembly language.

N
none7, 2021-11-25
@none7

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.

A
Adamos, 2021-11-25
@Adamos

php and its frameworks, also js and c#

Those who answered above forgot to note that there is nothing in common between the indicated languages ​​​​and assembler - they are not compiled into machine code in principle.

S
Saboteur, 2021-11-25
@saboteur_kiev

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.

The extension has nothing to do with it, this is already for specific assemblers, IDs and operating systems in order to know which program to open and how to highlight the syntax.
And so, a program in a compiled language is a text that, with the help of several utilities (translator, compiler, linker, etc.), ultimately converts the text into an executable file.
But this is all rather arbitrary, since now virtualization has reached platforms, and if 30 years ago a platform meant a processor, now even a browser (for webassembly, css and js) and so on can be a platform.
PS And yes, assembler is text. And the end result, for example for C ++, is an executable file with machine code and the structure of the executable file, which contains how and what to load into memory and where to transfer control.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question