Journey of Programming languages from human to CPU

hi.

Is there any standard and general ways for ALL or atlas MOST programming languages for

1) Translation phases:
a- From source code to next form
b- from previous form to next form
c- so on until CPU executes it as a program

If not then do most programming languages follow C steps in their translations?

Thanks
You should do a quick search in Google for
compiled vs interpreted

hope it helped you a bit ..
thanks,

I know there are lot of mats out there but they are mixed with many shortcomings and extensions that it is difficult for a beginner like me to fully understand what is going on. I mean not all impart the same content in the same manner.

I hope someone with a vast expertise in this could give me a clear picture of translation science.
I hope someone with a vast expertise in this could give me a clear picture of translation science


What is actually your intention ? Do you want to create a compiler or something ?
Or what you can do is buying yourself a book that contains hundred of pages to answer that question. I am not being mean by saying that , but this is not a related question to c++ but more a general computer science. Maybe I did not get your question clearly , you will have to be more specific . Thanks
Hi,

Yes there is, otherwise we cannot have programming languages. These are called application levels (as far as I understand it) Each higher level, starting from the source code, must be able to be translated into a lower level. There must be an unbroken path, from the high level to the very lowest level, otherwise everything becomes useless.

For example, a C program is converted to assembly, then there is microcode, which does each instruction in assembly, which then becomes machine code.

Some other language might be converted to C, and so on.

IIRC from what I have read (Stroustrup), the very first versions of C++ were converted to C first, then assembly etc. Apparently it wasn't long before C++ was compiled to assembly directly.

If not then do most programming languages follow C steps in their translations?


AFAIK, the translation to a lower level doesn't necessarily have to go through the C language, (I guess there are lots that do though), there could be some other step - just as long as it makes it to the lowest level.

Hope all is well :+)
Last edited on
For example, a C program is converted to assembly, then there is microcode, which does each instruction in assembly, which then becomes machine code.

No, microcode, if it exists, is an implementation detail of the CPU. The CPU executes instructions in an "instruction set" and the instruction set has a 1-to-1 correspondence with assembly language. In other words, an assembler translates assembly directly into instructions that the CPU can execute, and all (published) instructions that the CPU executes can be written in assembly.

I believe the steps for compiling a program are like this. Note that interpretted languages are different.

1. The compiler reads the program and, through a lot of work, converts it to an intermediate representation.
2. It the applies optimizations to the intermediate representation.
3. The intermediate rep is converted to CPU instructions. CPU-specific optimizations get applied here. The result is written out as an object file.
4. After all the source code is compiled, the linker combines the object files, along with any libraries that are included. Mostly what the linker does is resolve external references. In other words, if file1.o refers to int a that was defined in file2.o, then the linker figures out where int a is located and fixes the references in file1.o so they refer to the right location. The result is the executable program.
5. When you ask to run the program, there may be additional fixing that's needed. For example, initialized data may be decompressed. Memory references in the program may need to be adjusted to reflect the actual location in memory where the program runs, dynamic link libraries may be need to be loaded and calls to them may need to be bound.
Topic archived. No new replies allowed.