Giter VIP home page Giter VIP logo

pld-comp's Introduction

C compiler with Antlr4/C++ (H4244)

This is a long term project in 4th year in computer science at INSA Lyon.
The goal is to create a compiler for a subset of the C programming language.

https://github.com/jeromehue/PLD-COMP

grammar/ contains the Antlr4 grammar for a subset of C (.g4 files)
src/ contains the source code (.cpp and .h files)
tests/ contains everything related to tests

Prerequisites

Make sure to create a Makefile.local file containing your local Antlr4 paths, e.g.:

ANTLR4_BINDIR=/usr/bin
ANTLR4_INCDIR=/shares/public/tp/ANTLR4-CPP/antlr4-runtime
ANTLR4_LIBDIR=/shares/public/tp/ANTLR4-CPP/lib
ANTLR4_RUNTIME=libantlr4-runtime.a # or libantlr4-runtime.so

The above example should work with computers of IF rooms 208 and 219.

Usage

Compile the project by running make.
Execute our compiler on example.c by running ./bin/ifcc example.c.
The assembly output will go into output.s.

You can use -v for a verbose output.

Tests

Run tests with make test.
Detailed test results will go into tests/out/.

As the time of writing, the codeblocks and unary-operators tests fail, because they cover unimplemented features.

You can run a 'graphical' test to visualize the derivation tree produced by antlr.

  • Download antlr complete java tool from https://www.antlr.org/download.html, place it under tests/gui.
  • Edit launch.sh to specify the CLASSPATH, for instance with antlr-4-9-complete.jar:
    export CLASSPATH=".:./antlr-4.9-complete.jar:$CLASSPATH" 
    alias antlr4="java -jar ./antlr-4.9-complete.jar"
  • Run launch.sh

You can also modify the grammar and .c file used. By default, it uses main.c as source code and ifcc.g4 as grammar, but the 'official' C grammar is also available in tests/gui.

antlr_parse

pld-comp's People

Contributors

jeromehue avatar charleprr avatar quentin-rgd avatar sdejoannis avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

aziz4785

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.