Skip to content

Commit

Permalink
Documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayphoenix committed Sep 8, 2020
1 parent dc03e25 commit 84f498d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 53 deletions.
17 changes: 0 additions & 17 deletions .circleci/config.yml

This file was deleted.

22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

MIT License

Copyright (c) 2019 Vijay Tadikamalla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![CircleCI](https://circleci.com/gh/IITH-SBJoshi/haskell-11/tree/master.svg?style=svg&circle-token=72b4ba1854966fc5f4e58b1e3d0fc5a05cf4ad66)](https://circleci.com/gh/IITH-SBJoshi/haskell-11/tree/master)
[![Build Status](https://travis-ci.com/vijayphoenix/Compiler-written-in-Haskell.svg?token=67qmZmyfex1ST6G5tpZK&branch=master)](https://travis-ci.com/vijayphoenix/Compiler-written-in-Haskell)

# Implementing a JIT Compiled Language with Haskell

## About

The aim of the project was to implement a simple procedural language.
The project aimed to implement a simple procedural language.
We named it **HASKULL** :-)
The frontend is written in Haskell and the backend it managed LLVM-hs-pure package.
The project extensively uses Monads, State Monads, Applicative functors and Transformers.
Expand All @@ -18,7 +18,7 @@ You will need GHC 7.8 or newer as well as LLVM 4.0.
Clone the repository:

```
git clone "https://github.com/IITH-SBJoshi/haskell-11.git"
git clone https://github.com/vijayphoenix/Compiler-written-in-Haskell.git
```

Browse to the directory where all the files of this repository are located.
Expand All @@ -37,7 +37,7 @@ stack repl
```
Type "main" in the interactive console.

Write any code using following Syntax rules
Write any code using the following Syntax rules.

```
Syntax rules:
Expand All @@ -47,14 +47,13 @@ All the symbol starting with lower-case letter are terminal(lexer units).
All the operators are left associative
Command = Expr ;
Expr : DeclarationStmt | FuncCallStmt | LiteralStmt | Var | ifthenStmt | (Expr)
Expr : DeclarationStmt| FuncCallStmt | LiteralStmt | ifthenStmt | (Expr)
DeclarationStmt : ExternDecl | VarDecl
DeclarationStmt : ExternDecl
ExternDecl : extern Name([ArgList]) : Type
VarDecl : Type VList
Type : int | string
Type : int
VList: Name[, VList]
FuncCallStmt : Call
Expand All @@ -63,13 +62,12 @@ Call : Name ( [Args] )
BinOpCallStmt : BinOpCall
BinOpCall : Expr Op Expr
Op : + | - | * | / | ; | = | <
Op : + | - | * | / | ; | <
reserved keywords: int char def extern string if then else
Args : Expr[, Args]
LiteralStmt : StrLiteral | IntLiteral
LiteralStmt : IntLiteral
IntLiteral : integer
StrLiteral : string
Name : ident
ArgList : Type Name[, ArgList]
Expand All @@ -79,7 +77,8 @@ Command-list = Command [Command-list]
Command = Expr ;
```
For more insight on the language grammer, refer to Language.hs, Lexer.hs, Parser.hs files.
Some sample example functions are provided in examples.txt file.
For more insight on the language grammar, refer to Language.hs, AST.hs files.


### Documentation
Expand All @@ -100,7 +99,7 @@ stack haddock
* [**Yogesh Singh**](https://github.com/yo5sh)

#### License
* [LICENSE](https://github.com/IITH-SBJoshi/haskell-11/blob/master/LICENSE)
* [LICENSE](LICENSE)

#### Acknowledgments
* [Haskell LLVM JIT Compiler Tutorial](http://www.stephendiehl.com/llvm)
* [Haskell LLVM JIT Compiler Tutorial](http://www.stephendiehl.com/llvm)
27 changes: 27 additions & 0 deletions examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Some example functions:

def eq(int x, int y):int { if(x-y) then {0} else {1};}

extern int abs(int x):int ;

def leq(int x, int y) : int { if(x) then { if (y) then { leq(x-1, y-1) } else {1} } else {2}; } {- | x<=y | 2-> y>=x | 1-> x>y | -}
def gt(int x, int y) : int { if( eq( leq(int x, int y), 1 ) ) then {1} else {2} ;} {- | x>y ? 1 : 2 | -}

def fib(int x):int { if(x-1) then { if (x) then { fib(x-1)+fib(x-2) } else {0} } else {1}; } {- | x=0 ? 1 : x*(x-1)! | -}
def fact(int x):int { if(x) then { x*fact(x-1) } else {1}; }

def mod(int x, int y): int { x - (x/y)*y; }
def pow(int x, int y): int { if(y) then { x*pow(x, y-1) } else {1} ; }
def powmod(int x, int y, int p): int { if(y) then { mod( x * powmod(x, y-1), p) } else {1}; }
def nCr(int n, int r): int { fact(n)/fact(n-r)/fact(r);}

4 + 5*6 - 3*2 + 10/3 + 5*7;



def pred(int x) : int { x-1 ;}
def succ(int x) : int { x+1 ;}


def and(int x, int y) : int { if( eq( x+y , 2 ) ) then {1} else {0} ;}
def or (int x, int y) : int { if( eq( x+y , 0 ) ) then {0} else {1} ;}
10 changes: 5 additions & 5 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Haskull
version: 0.1.0.0
github: "https://github.com/IITH-SBJoshi/haskell-11"
license: BSD3
author: "Vijay"
github: "https://github.com/vijayphoenix/Compiler-written-in-Haskell"
license: MIT
author: "Vijay Tadikamalla"
maintainer: "cs17btech11040@iith.ac.in"
copyright: "2019 Vijay"
copyright: "2019 Vijay Tadikamalla"

extra-source-files:
- README.md
Expand All @@ -17,7 +17,7 @@ extra-source-files:
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/IITH-SBJoshi/haskell-11#readme>
description: Please see the README on GitHub at <https://github.com/vijayphoenix/Compiler-written-in-Haskell#readme>

dependencies:
- base >= 4.7 && < 5
Expand Down
13 changes: 6 additions & 7 deletions src/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ module AST (
-- All the operators are left associative

-- Command = Expr ;
-- Expr : DeclarationStmt | FuncCallStmt | LiteralStmt | (Expr)
-- Expr : DeclarationStmt | FuncCallStmt | LiteralStmt | IfthenStmt | (Expr)

-- DeclarationStmt : ExternDecl | VarDecl
-- DeclarationStmt : ExternDecl

-- ExternDecl : extern Name([ArgList]) : Type
-- VarDecl : Type VList

-- Type : int | string
-- Type : int
-- VList: Name[, VList]

-- FuncCallStmt : BinOpCall | Call
-- FuncCallStmt : Call
-- BinOpCall : Expr Op Expr
-- Call : Name ( [Args] )

-- Op : + | - | * | /
-- Op : + | - | * | / | <
-- Args : Expr[, Args]

-- LiteralStmt : StrLiteral | IntLiteral
Expand Down Expand Up @@ -71,7 +70,7 @@ data Expr
| BinOpCallStmt BinOpCall -- Done
| LiteralStmt Literal -- Done
| Var Name -- Done
| IfthenStmt Ifthen -- Left
| IfthenStmt Ifthen -- Done
deriving (Show)


Expand Down
15 changes: 5 additions & 10 deletions test/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,25 @@ main
func2 &&
func3 &&
func4 &&
func5 &&
func6 = putStrLn "\nTEST PASSING"
func5 = putStrLn "\nTEST PASSING"
| otherwise = error "TESTS NOT PASSING"

func1 = case (parse binOpCallStmtParser "File1" "5+3;") of
Right s -> (show (parse binOpCallStmtParser "File1" "5+3;")) == "Right (BinOpCallStmt (BinOpCall {op = Plus, lhs = LiteralStmt (IntLiteral 5), rhs = LiteralStmt (IntLiteral 3)}))"
Left err -> error $ show err

func2 = case (parse binOpCallStmtParser "File2" "4+5*7/10;") of
Right s -> (show (parse binOpCallStmtParser "File2" "4+5*7/10;")) == "Right (BinOpCallStmt (BinOpCall {op = Divide, lhs = BinOpCallStmt (BinOpCall {op = Plus, lhs = LiteralStmt (IntLiteral 4), rhs = BinOpCallStmt (BinOpCall {op = Mul, lhs = LiteralStmt (IntLiteral 5), rhs = LiteralStmt (IntLiteral 7)})}), rhs = LiteralStmt (IntLiteral 10)}))"
Left err -> error $ show err

func3 = case (parse binOpCallStmtParser "File2" "x+y;") of
func2 = case (parse binOpCallStmtParser "File2" "x+y;") of
Right s -> (show (parse binOpCallStmtParser "File2" "x+y;")) == "Right (BinOpCallStmt (BinOpCall {op = Plus, lhs = Var \"x\", rhs = Var \"y\"}))"
Left err -> error $ show err

func4 = case (parse literalStmtParser "File2" "\"Hello\"") of
func3 = case (parse literalStmtParser "File2" "\"Hello\"") of
Right s -> (show (parse literalStmtParser "File2" "\"Hello\"")) == "Right (LiteralStmt (StrLiteral \"Hello\"))"
Left err -> error $ show err

func5 = case (parse literalStmtParser "File2" "15000") of
func4 = case (parse literalStmtParser "File2" "15000") of
Right s -> (show (parse literalStmtParser "File2" "15000")) == "Right (LiteralStmt (IntLiteral 15000))"
Left err -> error $ show err

func6 = case (parse funcCallStmtParser "File2" "func(4,3)") of
func5 = case (parse funcCallStmtParser "File2" "func(4,3)") of
Right s -> (show (parse funcCallStmtParser "File2" "func(4,3)")) == "Right (FuncCallStmt (FuncCall {callee = \"func\", args = [LiteralStmt (IntLiteral 4),LiteralStmt (IntLiteral 3)]}))"
Left err -> error $ show err

0 comments on commit 84f498d

Please sign in to comment.