Originally posted by LightBit
View Post
what is a compiler? a compiler[very simplified] is an converter from Language X to IR[as intermediate representation][very very low level] to binary[<--simplified] which is the unique language your CPU can talk
what are a compiler stages? well your code is most likely to be really inefficient from a CPU perspective[and well you code can be very crappy too] so the compiler has many optimization passes to fix this situation and improve the quality of the resulting binary code
what is a language? since writing a software in binary is absoletely impossible for a human being in a regular lifetime, it was common sense to create a much more simplified way of communicate the CPU the task we need it to compute in a logical ordeal and after we end expressing our computing needs then use an automated translation tool to make it binary language[compiler] again so the cpu can get to work.
What is C? is just a language which unique syntax and features that were used commonly enough to be able of make that syntax and features an ISO standard
what is C++? is a syntax and features superset of C able to reach ISO standard as well that introduce a new set of tool to improve our way to write code that were developed after C was an ISO standard
what is X language? same crap
since C dont have OOP that means it don't use some parts of my cpu? no, it doesnt matter the language they all pass by a compiler in some point and get translated to binary using as many features as your CPU can handle[flags control this but keeping it simple]
what make OOP different from C? is no magic at all is just syntax that allows to express logic in a more natural real world way[we use objects[apple], properties[color, texture, smell], etc in our daily life] where C is more a serialized syntax[do this, next do that, then do this 4 times and then do that thing there and then close][again very simplified]
so the C interpreter inside the compiler is simple a parser that reads your X language code and translate it into an IR[gimple in GCC case] that much later will be writed in binary to a file[.o file (.exe or .so are made by a linker not a compiler) ] so the features or syntax of the language you use to write the parser are 100% irrelevant as long as you can properly translate to IR with it[so yes you can make a c interpreter in python or java if you want no biggie here], so using a bit more higher level to write this parser can allow you to write a smarter parser or at least a more readable parser than with a lower level language hence opening the possibility of apply further optimizations to the code that is getting parsed that would be too hackish or hard in a lower level language that is all
Comment