Compiler theory deals with the concept of a compiler for programming languages. The topic has heavy ties to linguistics because of the nature of compilers. A compiler is what translates the high-level code of the programmer into the machines particular object code. Compilers are very difficult to write and develop, but the best ones will not only translate, but also optimize the resulting object code. The compilers will generate object code based off the syntax, semantics and grammar of the programming language, which is where the tie to linguistics comes in.
The compiler works in two phases. First, it does a lexical analysis of the source code, and organizes the code into groupings called Lexemes. These groupings are organized by their token class, such as Integer, or String, or Loop. Once the lexemes are created, the compiler will then analyze the syntax and grammar to determine the functional aspect of the code. When this step is done, the program is converted into Object Code, and can be run on the architecture it was compiled for. When optimizing, the compiler will generally do the optimization directly after the syntax analysis.
Steps in compiling sourcecode to final code [ Image credit: Pau Gay ]
Most modern compilers will also handle the linking and loading of files. When a compiler detects that a program requires external libraries to run, it will automatically prepend a compiled version of whatever is being used to the compiled product, as long as it exists on the system, and it does so fully recursively.
© BrainMass Inc. brainmass.com January 18, 2021, 11:34 am ad1c9bdddf