/CppCompiler

C++ like simple compiler

Primary LanguageC++GNU General Public License v3.0GPL-3.0

C++ Compiler

Simple C++ like compiler using Bison/Flex

We use C++ 17, Bison >= 3.0 because we use it to generate C++ files and use C++ variants instead of %union

Features

  • C++ like syntax
  • Used modern C++ features
  • Support functions, if conditions, loops, etc.
  • Support multiple operators as +, -, *, /, ++, --, ** (exp), and, or, not, &&, ||, !, ==, !=, <, >, <=, >=, <<, >>
  • Expressive Warnings, and Errors
  • Warning on not used variables, functions, etc.
  • Warning on not initialized variables.
  • Simple GUI Text Editor

IDE GUI

Download

You can find precompiled binaries (CLI, GUI) for Linux and Windows in the releases

How To Build

Dependencies

  • Cmake >= 3.0
  • C++ compiler
  • Bison >= 3.0
  • Flex

Install Dependencies

  • Ubuntu:

        sudo apt-get update
        sudo apt-get install build-essential bison flex cmake gcc g++
  • Windows:

Build

  • Ubuntu:
          mkdir build
          cd build
          cmake .. -DCMAKE_BUILD_TYPE=Release
          cmake --build . --config Release --clean-first

You will find executable called CppCompiler inside build directory

Generated C++ grammar files inside build/src/grammar/ directory


  • Windows:
    • Using Visual Studio:

          mkdir build
          cd build
          cmake .. -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 17 2022" -A x64
          cmake --build . --config Release --clean-first

      Visual Studio it is the default generator for windows, (i.e you can remove -G "Visual Studio 17 2022" and cmake will choose the installed version) but you can select a specific version:

      • "Visual Studio 11 2012"
      • "Visual Studio 14 2015"
      • "Visual Studio 15 2017"
      • "Visual Studio 16 2019"
      • "Visual Studio 17 2022"

      You will find executable called CppCompiler.exe inside build/Release/ directory

      Generated C++ grammar files inside build/src/grammar/ directory

    • Using Mingw-w64:

          mkdir build
          cd build
          cmake .. -DCMAKE_BUILD_TYPE=Release -G "Mingw-w64 GCC 8"
          cmake --build . --config Release --clean-first

      You will find executable called CppCompiler.exe inside build directory

      Generated C++ grammar files inside build/src/grammar/ directory

Usage

The program takes one argument of the file to compile

If no arguments are given, the program reads from standard input, saves output to out.txt and saves symbol table to symbols.txt

Example:

  • Ubuntu
      CppCompiler test.txt out.txt symbols.txt
  • Windows
      CppCompiler.exe test.txt out.txt symbols.txt