roshan-d21 / rust-compiler

⚙ A basic lexical analyser and parser for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust-Compiler

Introduction

Problem Statement: Build a basic Rust compiler using Lex and Yacc

The compiler performs the following tasks:

  1. Lexical Analysis
  2. Symbol Table Generation
  3. Syntax Analysis
  4. Semantic Analysis
  5. Error Detection
  6. Intermediate Code Generation
  7. Code Optimization

Installing Dependencies

This project uses lex and yacc, and also requires gcc and python3 to be installed

sudo apt-get install -y flex byacc bison

Or use the Dockerfile instead to run the application in a container:

docker image build -t lex-yacc:latest .
docker container run --name cdproject -it lex-yacc:latest

Usage

For Phase 1 of the compiler (Lexical and Syntactical Analysis)

cd phase\ 1

Using make:

make parse

Or compile each file individually:

flex parser.l
yacc parser.y
gcc y.tab.c -lfl -w
./a.out test.rs

For Phase 2 of the compiler (ICG and Code Optimization)

cd phase\ 2

To Generate ICG:

make parse

Or compile each file individually:

flex parser-v2.l
yacc parser-v2.y
gcc y.tab.c -lfl -w
./a.out test.rs

To optimize ICG code:

make optimize

Or

python3 code_optimizer.py icg.txt

Team Members

  • Naveen K Murthy - PES2201800051
  • Siva Surya Babu - PES2201800475
  • Roshan Daivajna - PES2201800372

About

⚙ A basic lexical analyser and parser for Rust


Languages

Language:Python 35.8%Language:Yacc 35.8%Language:Lex 17.4%Language:C 8.7%Language:Rust 1.0%Language:Makefile 0.6%Language:Dockerfile 0.5%