Code Monkey home page Code Monkey logo

decaf's Introduction

The New Decaf Compiler

Decaf is a Java-like, but much smaller programming language mainly for educational purpose. We now have at least three different implementations of the compiler in Java, Scala and Rust. Since the standard language has quite a limited set of language features, students are welcome to add their own new features.

Getting Started

This project requires

  • JDK 14
  • Gradle 6.5.1

Other dependencies will be automatically downloaded from the maven central repository by the build script.

After git clone, you need to setup submodules by

git submodule update --recursive --init

Build

Type the standard Gradle build command in your CLI:

gradle build

The built jar will be located at build/libs/decaf.jar.

Or, import the project in a Java IDE (like IDEA or Eclipse, or your favorite VS Code) and use gradle plugin, if available.

Run

In your CLI, type

java -jar build/libs/decaf.jar -h

to display the usage help.

Possible targets/tasks are:

  • PA1: parse source code and output the pretty printed tree, or error messages
  • PA1-LL: like PA1, but use hand-coded LL parsing algorithm, with the help of a LL table generator ll1pg
  • PA2: type check and output the pretty printed scopes, or error messages
  • PA3: generate TAC (three-address code), dump it to a .tac file, and then output the execution result using our built-in simulator
  • PA4: currently same with PA3, will be reserved for students to do a bunch of optimizations on TAC
  • PA5: (default target) allocate registers and emit assembly code, currently we are using a very brute-force algorithm and only generates MIPS assembly code (with pseudo-ops, and no delayed branches)

To run the MIPS assembly code, you may need spim, a MIPS32 simulator. For Mac OS users, simply install spim with brew install spim and run with spim -file your_file.s.

Releases

See https://github.com/decaf-lang/decaf/releases for releases, including separate frameworks for PA1 -- PA3.

Materials

We have a couple of Chinese documents on the language specification and implementation outlines:

Development & Contribution

In future, we will develop on (possibly variates of) development branches, and only merge release versions into the master branch.

Issues and pull requests for fixing bugs are welcome. However, adding new language features will not be considered, because that's students' work!

decaf's People

Contributors

equation314 avatar hoblovski avatar paulzfm avatar strongerxi avatar xumingkuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

decaf's Issues

gradle build fails with duplicate META-INF/LICENSE reference

I'm on Linux Manjaro and I was trying to build decaf from the src and when I would run: gradle build
it would fail for the jar task stating something about a duplicate META-INF/LICENSE file. The fix for me was this:

The original snippet of the build.gradle file:
`tasks.compileJava.dependsOn tasks.ll1pg

jar {
manifest {
attributes 'Main-Class': 'decaf.Main'
}

// Create a fat JAR with all the dependencies.
from {
    configurations.runtimeClasspath.collect {
        it.isDirectory() ? it : zipTree(it)
    }
}

}`

I changed it to:
`tasks.compileJava.dependsOn tasks.ll1pg

jar {
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE);
manifest {
attributes 'Main-Class': 'decaf.Main'
}

// Create a fat JAR with all the dependencies.
from {
    configurations.runtimeClasspath.collect {
        it.isDirectory() ? it : zipTree(it)
    }
}

}`

and now, despite giving an error about JavaExecHandlerBuilder.setMain(String) method being deprecated, it compiles. I also changed the commons-cli version from 1.5 to 1.5.0 though I'm not sure if that matters.

No gradle jar

Some students say they cannot build the project with gradlew. @Harry-Chen suspects the gradle jar is missing (ignored by .gitignore) and maybe it's true. However, I believe *.jar files should be ignored because we hope students NOT submit their built jars to their repositories.

How to fix?

Currently, please install the lastest gradle yourself and use gradle build instead.

This bug is considered in the next release.

Bad error position in BadNewArrayLength and SubNotIntError

Input:

class Main {
    static void main() {
        int[][] test;
        int[] a = new int[test[10]];
        int[] b = new int[main()];
        main()[10] = 1;
    }
}

Output:

*** Error at (4,31): new array length must be an integer
*** Error at (5,31): new array length must be an integer
*** Error at (6,13): [] can only be applied to arrays

Should be:

*** Error at (4,27): new array length must be an integer
*** Error at (5,27): new array length must be an integer
*** Error at (6,15): [] can only be applied to arrays

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.