Code Monkey home page Code Monkey logo

xpl's Introduction

xpl

This is a toy programming language and compiler that emits JVM code. About the most sophisticated program that can currently be compiled is this example (square root via Newton's method example from SICP):

fn average(real a, real b) -> real
  (a + b) / 2
end

fn square(real x) -> real
  x * x
end

fn abs(real x) -> real
  if(x >= 0) x else -x end
end

fn sqrt(real x) -> real
  fn improve(real guess, real x) -> real
    average(guess, x / guess)
  end

  fn goodenough(real guess, real x) -> int
    abs(square(guess) - x) < 0.0001
  end

  fn sqrtiter(real guess, real x) -> real
    if(goodenough(guess, x))
      guess
    else
      sqrtiter(improve(guess, x), x)
    end
  end

  sqrtiter(1.0, x)
end

print(sqrt(3.0))

The compiler has a suite of quite a few integration tests, so some other example programs can be found in tests/integration/positive, in files with .xpl extension, with corresponding .output-desired files containing the output expected from the program. tests/integration/negative are programs that are expected to not be compiled by the compiler, and the corresponding .compilation-desired file contains the desired compiler output in such case.

To compile and run this, one needs ant, ant-junit, antlr-3.x, and junit 4.x in the classpath. Then you can just use ./build to compile.

xpl's People

Contributors

jaroslawr avatar

Stargazers

weily avatar Roman avatar CHENG KUN avatar  avatar 曹文忠 avatar Jeorge Matthew avatar Angus H. avatar  avatar tyoc213 avatar Flávio Juvenal avatar brownman avatar Michal Kwiatkowski avatar Karol Kozub avatar tyoc avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  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.