Usually compiling is a term which is frequently heard by every person that is related to programming, even if remotely. A compiler converts or translates code from one language to another. A compiler is a program which transforms a high level language program/code into binary instructions (machine language) that our computer system can analyze, understand and take the ideal steps to execute the very same. The generated machine code can be later on carried out lot of times against various data each time. The process of transferring high level language source program into object code is a prolonged and complicated process as compared to assembling. Compliers have diagnostic abilities and trigger the programmer with suitable error message while compiling a high level language program.
The lexer will divide the code into tokens and send them to the parser. The parser identifies patterns, that represent the grammar of the language and transform the code into an AST (abstract syntax tree). Lastly the generator converts the AST to the syntax of the target language. Lexer uses basic regular expressions to slice up the source code and convert it right into tokens, these tokens are then sent out to the parser where groups of tokens that stand for expressions and statements are transformed into the abstract syntax tree. Finally the AST is utilized to create the target code.
The work of a complier consists of the following:
- To translate high level language source program to machine codes.
- To map variables in the program
- To include link for subroutines.
- To assign memory for storage space of program and variables.
- To generate error messages, if there are errors in the program.
Types of Compiler
Cross Compiler that operates on a machine ‘A’ and generates a code for one more machine ‘B’. It is capable of developing code for a platform besides the one on which the compiler is running.
Source-to-source Compiler or transcompiler or transpiler is a compiler that converts source code written in one programming language into source code of another programming language.