Giter Site home page Giter Site logo

jobhdez / pine Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 176 KB

compiles while loops, if expressions, print statements, addition, assignment, tuples to x86

License: GNU General Public License v2.0

Haskell 74.22% Yacc 3.45% C 22.32% Makefile 0.02%
anf compiler haskell x86

pine's Introduction

a compiler with an x86-64 back-end and C backend!

I have plans to change the syntax.

Running the program

you will need to install the happy parser generator:

* cabal install happy

After you install happy you need to clone the repo:

* git clone [email protected]:Jobhdez/pyhs.git

and then navigate to the src/ directory and load the files. You can load the ToSelect module to run the examples below.

* cd pyhs/src
* ghci ToSelect.hs

Examples

Before running the examples, you need to build it:

* cabal build

and when you have the generated assembly, use gcc:

* cd pyhs
* gcc -c -g -std=c99 src/runtime/runtime.c
* gcc -g runtime.o <assembly file>

So far it can compile the following expressions:

let x = 0;; while x < 4;: if x < 5; then print(x);; let x = x + 1;; else print(3);;

You can generate the assembly file for the above program by:

* cd pyhs
* cabal run whileifeg

You can also compile an expression such as

if True then print(2); else print(3);;

To run this example:

* cabal run ifexpeg

And I have also tested this program

let x = 0;; while x < 5;: print(x);; let x = x + 1;;

To generate the assembly for this program:

* cabal run whileeg

Tuples

So far I can only compile the expression:

let x = (4;5;6);; print(x[1]);

If you want to generate the file yourself:

* cabal run tup

Thanks

This compiler was based on Dr. Siek's compilation book https://github.com/IUCompilerCourse/Essentials-of-Compilation. The runtime (runtime.c) was written by Dr. Siek but the compiler is my work.

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.