Skip to content

Commit 84f498d

Browse files
committed
Documentation update
1 parent dc03e25 commit 84f498d

File tree

7 files changed

+78
-53
lines changed

7 files changed

+78
-53
lines changed

.circleci/config.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
MIT License
3+
4+
Copyright (c) 2019 Vijay Tadikamalla
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
[![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)
1+
[![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)
22

33
# Implementing a JIT Compiled Language with Haskell
44

55
## About
66

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

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

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

40-
Write any code using following Syntax rules
40+
Write any code using the following Syntax rules.
4141

4242
```
4343
Syntax rules:
@@ -47,14 +47,13 @@ All the symbol starting with lower-case letter are terminal(lexer units).
4747
All the operators are left associative
4848
4949
Command = Expr ;
50-
Expr : DeclarationStmt | FuncCallStmt | LiteralStmt | Var | ifthenStmt | (Expr)
50+
Expr : DeclarationStmt| FuncCallStmt | LiteralStmt | ifthenStmt | (Expr)
5151
52-
DeclarationStmt : ExternDecl | VarDecl
52+
DeclarationStmt : ExternDecl
5353
5454
ExternDecl : extern Name([ArgList]) : Type
55-
VarDecl : Type VList
5655
57-
Type : int | string
56+
Type : int
5857
VList: Name[, VList]
5958
6059
FuncCallStmt : Call
@@ -63,13 +62,12 @@ Call : Name ( [Args] )
6362
BinOpCallStmt : BinOpCall
6463
BinOpCall : Expr Op Expr
6564
66-
Op : + | - | * | / | ; | = | <
65+
Op : + | - | * | / | ; | <
6766
reserved keywords: int char def extern string if then else
6867
Args : Expr[, Args]
6968
70-
LiteralStmt : StrLiteral | IntLiteral
69+
LiteralStmt : IntLiteral
7170
IntLiteral : integer
72-
StrLiteral : string
7371
7472
Name : ident
7573
ArgList : Type Name[, ArgList]
@@ -79,7 +77,8 @@ Command-list = Command [Command-list]
7977
8078
Command = Expr ;
8179
```
82-
For more insight on the language grammer, refer to Language.hs, Lexer.hs, Parser.hs files.
80+
Some sample example functions are provided in examples.txt file.
81+
For more insight on the language grammar, refer to Language.hs, AST.hs files.
8382

8483

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

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

105104
#### Acknowledgments
106-
* [Haskell LLVM JIT Compiler Tutorial](http://www.stephendiehl.com/llvm)
105+
* [Haskell LLVM JIT Compiler Tutorial](http://www.stephendiehl.com/llvm)

examples.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Some example functions:
2+
3+
def eq(int x, int y):int { if(x-y) then {0} else {1};}
4+
5+
extern int abs(int x):int ;
6+
7+
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 | -}
8+
def gt(int x, int y) : int { if( eq( leq(int x, int y), 1 ) ) then {1} else {2} ;} {- | x>y ? 1 : 2 | -}
9+
10+
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)! | -}
11+
def fact(int x):int { if(x) then { x*fact(x-1) } else {1}; }
12+
13+
def mod(int x, int y): int { x - (x/y)*y; }
14+
def pow(int x, int y): int { if(y) then { x*pow(x, y-1) } else {1} ; }
15+
def powmod(int x, int y, int p): int { if(y) then { mod( x * powmod(x, y-1), p) } else {1}; }
16+
def nCr(int n, int r): int { fact(n)/fact(n-r)/fact(r);}
17+
18+
4 + 5*6 - 3*2 + 10/3 + 5*7;
19+
20+
21+
22+
def pred(int x) : int { x-1 ;}
23+
def succ(int x) : int { x+1 ;}
24+
25+
26+
def and(int x, int y) : int { if( eq( x+y , 2 ) ) then {1} else {0} ;}
27+
def or (int x, int y) : int { if( eq( x+y , 0 ) ) then {0} else {1} ;}

package.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name: Haskull
22
version: 0.1.0.0
3-
github: "https://github.com/IITH-SBJoshi/haskell-11"
4-
license: BSD3
5-
author: "Vijay"
3+
github: "https://github.com/vijayphoenix/Compiler-written-in-Haskell"
4+
license: MIT
5+
author: "Vijay Tadikamalla"
66
maintainer: "cs17btech11040@iith.ac.in"
7-
copyright: "2019 Vijay"
7+
copyright: "2019 Vijay Tadikamalla"
88

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

2222
dependencies:
2323
- base >= 4.7 && < 5

src/AST.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,20 @@ module AST (
2222
-- All the operators are left associative
2323

2424
-- Command = Expr ;
25-
-- Expr : DeclarationStmt | FuncCallStmt | LiteralStmt | (Expr)
25+
-- Expr : DeclarationStmt | FuncCallStmt | LiteralStmt | IfthenStmt | (Expr)
2626

27-
-- DeclarationStmt : ExternDecl | VarDecl
27+
-- DeclarationStmt : ExternDecl
2828

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

32-
-- Type : int | string
31+
-- Type : int
3332
-- VList: Name[, VList]
3433

35-
-- FuncCallStmt : BinOpCall | Call
34+
-- FuncCallStmt : Call
3635
-- BinOpCall : Expr Op Expr
3736
-- Call : Name ( [Args] )
3837

39-
-- Op : + | - | * | /
38+
-- Op : + | - | * | / | <
4039
-- Args : Expr[, Args]
4140

4241
-- LiteralStmt : StrLiteral | IntLiteral
@@ -71,7 +70,7 @@ data Expr
7170
| BinOpCallStmt BinOpCall -- Done
7271
| LiteralStmt Literal -- Done
7372
| Var Name -- Done
74-
| IfthenStmt Ifthen -- Left
73+
| IfthenStmt Ifthen -- Done
7574
deriving (Show)
7675

7776

test/Spec.hs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,25 @@ main
1616
func2 &&
1717
func3 &&
1818
func4 &&
19-
func5 &&
20-
func6 = putStrLn "\nTEST PASSING"
19+
func5 = putStrLn "\nTEST PASSING"
2120
| otherwise = error "TESTS NOT PASSING"
2221

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

27-
func2 = case (parse binOpCallStmtParser "File2" "4+5*7/10;") of
28-
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)}))"
29-
Left err -> error $ show err
30-
31-
func3 = case (parse binOpCallStmtParser "File2" "x+y;") of
26+
func2 = case (parse binOpCallStmtParser "File2" "x+y;") of
3227
Right s -> (show (parse binOpCallStmtParser "File2" "x+y;")) == "Right (BinOpCallStmt (BinOpCall {op = Plus, lhs = Var \"x\", rhs = Var \"y\"}))"
3328
Left err -> error $ show err
3429

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

39-
func5 = case (parse literalStmtParser "File2" "15000") of
34+
func4 = case (parse literalStmtParser "File2" "15000") of
4035
Right s -> (show (parse literalStmtParser "File2" "15000")) == "Right (LiteralStmt (IntLiteral 15000))"
4136
Left err -> error $ show err
4237

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

0 commit comments

Comments
 (0)