Simple Compiler for C

Simple Compiler for C

A screenshot of the main code for the compiler.

Introduction

The project is developed for Mapua University - Makati in fulfillment of CSS125L, Principles of Programming Languages. This project builds upon the use of Flex, Bison, Clang, LLVM, and GCC. The project was done in groups and the tasks were distributed equally to the members. It is composed of the following:

  • Lexical Analysis
    • This component handles the tokenization of keywords, operators, as well as identifiers. It was created with the help of Flex.
  • Syntax Analysis
    • This compliments the Lexical Analysis component, it uses Bison and handles the construction of an Abstract Syntax Tree.
  • Semantic Analysis
    • Checks the keywords for any mismatch.
  • Intermediate Code Generation
    • This component translates the Abstract Syntax Tree (AST) into an intermediate representation via LLVM. The output of this component is then used as reference to code generation.
  • Code Generation
    • After the generation of Intermediate Representation (IR) code, LLVM translates the code to assembly code is ready for execution.

Issues

The project can’t handle temporary variables. Thus, the project can’t output strings and is only restricted to numericals.

Prerequisites

  • Linux – Any Linux operating system will be compatible. For the development of the project, Oracle VirtualBox was used alongside Ubuntu.
  • Flex – A lexical analyzer generator used to tokenize the input source code. It scans the code and identifies meaningful sequences of characters (tokens) for further processing.
  • Bison – A parser generator that works in conjunction with Flex. It processes the tokens produced by Flex and builds a syntax tree based on the defined grammar rules.
  • GCC – The GNU Compiler Collection is used to compile the C/C++ source code. It ensures compatibility and efficient performance across different systems. The project mainly used GCC as a way to compile the program.
  • Clang – An alternative to GCC, Clang is a compiler based on LLVM that offers faster compilation times and more detailed error diagnostics, helpful during development and debugging. Although, it was used only for the LLVM aspect of the program.

Access

Since this is an academic project, publicly releasing the source code may lead to issues. Therefore, the project’s source will be made available upon request.


© 2025. All rights reserved.