Giter Club home page Giter Club logo

cminus's Introduction

C-Minus Compiler

Introduction

A simple compiler written in Rust for the C-minus language; a very limited subset of C. Tested with rustc version 1.56.1.

How to use

The compiler consists of four stages, each with their own crate. Every compiler stage crate is both a library and a binary. The binary can be conveniently run by the provided run.sh script at the root of every crate. To run a full compilation, use the machine_code crate.

The log level for each binary can be set through an environment variable RUST_LOG. Options are: error, warning, info, debug, trace.

Overview

  • lexical includes only the lexical parsing aspect of the compiler.
  • syntax transforms a parse tree into an abstract syntax tree.
    • Use -s to obtain partial output. The (incomplete) syntax tree and symbol table will be printed even in case of an error.
  • intermediate_code produces 3-address code for a given AST. Also performs live time analysis and can make a control flow graph.
    • Use -a to annotate the produced three-address code with the original variable names rather than the symbol ids, for easier reading.
    • Use -g <filename>.png to save the control flow graph as a PNG image. This requires Graphviz (dot) on your system.
  • machine_code - produces x86 assembly for the given 3-address code.
    • Use -o to set the name of the output file.
    • WARNING: Machine code is WIP and will barely compile anything yet.

There are two additional crates:

  • general includes components used across multiple other crates, such as logging.
  • tests includes tests for all crates (WIP) Use the tests.sh script to run one or more test suites. Provide all the tests you want to run, e.g.
./tests.sh lexical syntax intermediate

Available test suites are lexical, syntax, intermediate. Tests for machine_code is WIP.

cminus's People

Contributors

dependabot[bot] avatar sholtrop avatar

Stargazers

 avatar

Watchers

 avatar

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.