DEV Community

James
James

Posted on • Originally published at miiizen.github.io

15 4

Compiler Series Part 1: Introduction

Programming was my first foray into computer science, and recently I wanted to dig into this topic in more detail. The posts which follow will be a collection of my notes, made while writing my own compiler in C++.

Compilers are an essential part of computing, allowing higher level languages to be translated to machine code that the computer can understand. This provides an important level of abstraction to the programmer, meaning they don’t have to worry about the complexity and quirks of assembly languages.

I will break down the compiler into a collection of separate, easier to understand modules. Compilers lend themselves to this modular approach quite nicely. From front to back:

  1. The lexer - This performs lexical analysis, breaking the input up into tokens
  2. The parser - This puts the tokens we get from the lexer into the context of our language via an intermediate representation
  3. Transformation - Once we have the intermediate representation, this can be tidied and optimised
  4. Code generation - The intermediate representation is used to generate the required assembly for each language construct

In the next section, we'll get a bird's eye view of gcc the GNU Compiler Collection.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay