DarkGeekMS / simple-c-compiler

A simple C/C++ compiler implemented in LEX (Flex) and YACC (Bison)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple C/C++ Compiler

A simple C/C++ compiler implemented in LEX (Flex) and YACC (Bison).

Prerequisites

  • gcc
  • g++
  • flex
  • bison
  • Python (PyQT5)

Usage (Ubuntu)

  • Add the required code to .c or .cpp file.

  • Compile and run the lexer and parser on the code :

    bison --yacc parser.y -d # process parser using bison
    flex lexer.l # process lexer using flex
    g++ -c symbolTable.cpp # compile symbol table file and object file
    gcc -c lex.yy.c y.tab.c compiling.c # compile c files and get object files
    g++ -o cpp.out symbolTable.o compiling.o lex.yy.o y.tab.o # link output object files
    ./cpp.out /path/to/input/file /path/to/output/directory # run output file providing required code file
  • Alternatively, use run.bash to compile and run the compiler :

    ./run.bash /path/to/input/file /path/to/output/directory
  • Use GUI :

    • First, compile the code and get cpp.out.
    • Second, copy cpp.out to gui folder.
    • Third, run GUI :
      cd gui/
      python gui.py
    • Finally, choose the input file and the output directory, then press compile button.

About

A simple C/C++ compiler implemented in LEX (Flex) and YACC (Bison)


Languages

Language:C 56.1%Language:Yacc 19.3%Language:C++ 12.3%Language:Python 7.0%Language:Lex 4.7%Language:Shell 0.5%