What is Compiler Design?

Before you design your next compiler, read this.

is the structure and set of principles that guide the translation, analysis, and optimization process of a compiler.

is computer software that transforms program source code which is written in a high-level language into low-level machine code. It essentially translates the code written in one programming language to another language without changing the logic of the code.

also makes the code output efficient and optimized for execution time and memory space. The compiling process has basic translation mechanisms and error detection, it can’t compile code if there is an error. The compiler process runs through syntax, lexical, and semantic analysis in the front end and generates optimized code in the back end.

all the language statements one after the other syntactically and then, if it’s successful, builds the output code, making sure that statements that refer to other statements are referred to appropriately, Traditionally, the output code is called .

Types of Compiler

  1. Cross Compiler: This enables the creation of code for a platform other than the one on which the compiler is running. For instance, it runs on a machine ‘A’ and produces code for another machine ‘B’.
  2. Source-to-source Compiler: This can be referred to as a transcompiler or transpiler and it is a compiler that translates source code written in one programming language into source code of another programming language.
  3. Single Pass Compiler: This directly transforms source code into machine code. For instance, Pascal programming language.
  4. Two-Pass Compiler: This goes through the code to be translated twice; on the first pass it checks the syntax of statements and constructs a table of symbols, while on the second pass it actually translates program statements into machine language.
  5. Multi-Pass Compiler: This is a type of compiler that processes the source code or abstract syntax tree of a program multiple times before translating it to machine language.

Language Processing Systems Steps

  1. High-Level Language: These are programs that contain #define or #include directives such as #include or #define. They are closer to humans language but far from machines. The (#) tags are referred to as preprocessor directives. They tell the pre-processor about what to do.
  2. Pre-Processor: This produces input for the compiler and also deals with file inclusion, augmentation, macro-processing, language extension, etc. It removes all the #include directives by including the files called file inclusion and all the #define directives using macro expansion.
  3. Assembler: This translates assembly language code into machine understandable language. Each platform (OS + Hardware) has its own assembler. The output of an assembler is known as an object file which is a combination of machine instruction along with the data required to store these instructions in memory.
  4. Interpreter: An interpreter converts high-level language into low-level machine language almost similar to what Compiler does. The major difference between both is that the interpreter reads and transforms code line by line while Compiler reads the entire code at once and outputs the machine code directly. Another difference is, Interpreted programs are usually slower with respect to compiled ones.
  5. Relocatable Machine Code: This can be loaded at any point in time and can be run. This enables the movement of a program using its unique address identifier.
  6. Linker: It links and merges a variety of object files into a single file to make it executable. The linker searches for defined modules in a program and finds out the memory location where all modules are stored.
  7. Loader: It loads the output from the Linker in memory and executes it. It basically loads executable files into memory and runs them

Features Of A Compiler

A major feature of a compiler is its correctness, and accuracy to compile the given code input into its exact logic in the output object code due to its being developed using rigorous testing techniques (often called compiler validation) on an existing compiler.

Compilers are designed in such a way that they can identify which part of the program formed from one or more lexical tokens using the appropriate rules of the language is syntactically allowable and which is not.

A compiler is designed to know how to parse the error encountered from lack be it a syntactical error, insufficient memory errors, or logic errors are meticulously handled and displayed to the user.

Compilers make sure that the target code is fast because in huge size code its a serious limitation if the code is slow, some compilers do so by translating the bytecode into target code to run in the specific processor using classical compiling methods.

A compiler makes sure that the code logic is preserved to the tiniest detail because a single loss in the code logic can change the whole code logic and output the wrong result, so during the design process, the compiler goes through a whole lot of testing to make sure that no code logic is lost during the compiling process.

Compilers make help the debugging process easier by pointing out the error line to the programmer and telling them the type of error that is encountered so they would know how to start fixing it.

Benefits Of Using A Compiler:

Using a compiler increases your program performance, by making the program optimized, portable, and easily run on the specific hardware.

Compilers make your program run faster than interpreted programs because it compiles the program only once, hence reducing system load and response time when next you run the program.

Compilers protect your program source by discouraging other users from making unauthorized changes to your programs, you as the author can distribute your programs in object code.

Compiled programs are always portable meaning that you can transfer it from one machine to another without worrying about dependencies as it is all compiled together.

SIITGo

Tech Courses and Reviews

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store