Skip to content

Commit c5abc64

Browse files
committed
Added Lexer for the Language
0 parents  commit c5abc64

File tree

10 files changed

+264
-0
lines changed

10 files changed

+264
-0
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog for Haskull
2+
3+
## Unreleased changes

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright Author name here (c) 2019
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Author name here nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Implementing a JIT Compiled Language with Haskell
2+
3+
## About
4+
5+
### Built With
6+
7+
### Installing
8+
9+
On Linux
10+
11+
### Documentation
12+
13+
This project is documented under [DOXYGEN](http://www.doxygen.nl/) Documentation
14+
15+
### Authors
16+
17+
* [**Vijay Tadikamalla**](https://github.com/vijayphoenix)
18+
* [**Anjani Kumar**](https://github.com/anjani-1)
19+
* [**Anupam Saini**](https://github.com/anupamsaini98)
20+
* [**Yogesh Singh**](https://github.com/yo5sh)
21+
22+
#### License
23+
24+
#### Acknowledgments
25+
* [Haskell LLVM JIT Compiler Tutorial](http://www.stephendiehl.com/llvm)

Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

app/Main.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Main where
2+
3+
import Lexer
4+
5+
main :: IO ()
6+
main = do
7+
str <- getLine
8+
putStrLn ("Input:" ++ str)
9+
print $ parse ident "File1" str
10+
main
11+
-- print $ parse ident "File1" str

package.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Haskull
2+
version: 0.1.0.0
3+
github: "https://github.com/IITH-SBJoshi/haskell-11"
4+
license: BSD3
5+
author: "Anjani Kumar"
6+
maintainer: "cs17btech11002@iith.ac.in"
7+
copyright: "2019 Anjani Kumar"
8+
9+
extra-source-files:
10+
- README.md
11+
- ChangeLog.md
12+
13+
# Metadata used when publishing your package
14+
# synopsis: Short description of your package
15+
# category: Web
16+
17+
# To avoid duplicated efforts in documentation and dealing with the
18+
# complications of embedding Haddock markup inside cabal files, it is
19+
# 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>
21+
22+
dependencies:
23+
- base >= 4.7 && < 5
24+
- haskeline >= 0.7.1.2
25+
- llvm-hs >= 4.0.0.0
26+
- llvm-hs-pure >= 4.0.0.0
27+
- parsec >= 3.1
28+
- bytestring >= 0.10
29+
- mtl >= 2.1.3
30+
- transformers >= 0.3.0.0 && < 0.6
31+
- containers >= 0.4
32+
33+
library:
34+
source-dirs: src
35+
36+
executables:
37+
Haskull-exe:
38+
main: Main.hs
39+
source-dirs: app
40+
ghc-options:
41+
- -threaded
42+
- -rtsopts
43+
- -with-rtsopts=-N
44+
dependencies:
45+
- Haskull
46+
47+
tests:
48+
Haskull-test:
49+
main: Spec.hs
50+
source-dirs: test
51+
ghc-options:
52+
- -threaded
53+
- -rtsopts
54+
- -with-rtsopts=-N
55+
dependencies:
56+
- Haskull

src/Language.hs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Language (
2+
haskullstyle,
3+
haskulldef
4+
) where
5+
6+
import Text.Parsec
7+
import Text.Parsec.Token
8+
import Text.Parsec.Language
9+
10+
11+
-- | This is a minimal token definition for Haskull style languages. It
12+
-- defines the style of comments, valid identifiers and case
13+
-- sensitivity. It does not define any reserved words or operators.
14+
15+
haskullstyle :: LanguageDef st
16+
haskullstyle = emptyDef {
17+
commentStart = "{-"
18+
, commentEnd = "-}"
19+
, commentLine = "//"
20+
, nestedComments = False
21+
, reservedNames = []
22+
, reservedOpNames = []
23+
, caseSensitive = True
24+
, identStart = letter <|> char '_'
25+
, identLetter = alphaNum <|> oneOf "_'"
26+
}
27+
28+
29+
-- | The language definition for the Haskull language.
30+
haskulldef = haskullstyle {
31+
reservedOpNames = ["+", "/", "-", "*", ";"],
32+
reservedNames = ["int", "char", "def", "extern"]
33+
}
34+

src/Lexer.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module Lexer (
2+
lexer,
3+
ident,
4+
reserved,
5+
reservedOp,
6+
charLiteral,
7+
Parser(..),
8+
parse
9+
) where
10+
11+
import Language
12+
import Text.Parsec
13+
import qualified Text.Parsec.Token as Tok
14+
import Text.Parsec.String (Parser)
15+
16+
lexer :: Tok.TokenParser st
17+
lexer = Tok.makeTokenParser haskulldef
18+
19+
ident :: Parser String
20+
ident = Tok.identifier lexer
21+
22+
reserved :: String -> Parser ()
23+
reserved = Tok.reserved lexer
24+
25+
reservedOp :: String -> Parser ()
26+
reservedOp = Tok.reservedOp lexer
27+
28+
charLiteral :: Parser Char
29+
charLiteral = Tok.charLiteral lexer

stack.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This file was automatically generated by 'stack init'
2+
#
3+
# Some commonly used options have been documented as comments in this file.
4+
# For advanced use and comprehensive documentation of the format, please see:
5+
# https://docs.haskellstack.org/en/stable/yaml_configuration/
6+
7+
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8+
# A snapshot resolver dictates the compiler version and the set of packages
9+
# to be used for project dependencies. For example:
10+
#
11+
# resolver: lts-3.5
12+
# resolver: nightly-2015-09-21
13+
# resolver: ghc-7.10.2
14+
#
15+
# The location of a snapshot can be provided as a file or url. Stack assumes
16+
# a snapshot provided as a file might change, whereas a url resource does not.
17+
#
18+
# resolver: ./custom-snapshot.yaml
19+
# resolver: https://example.com/snapshots/2018-01-01.yaml
20+
resolver: lts-8.13
21+
22+
# User packages to be built.
23+
# Various formats can be used as shown in the example below.
24+
#
25+
# packages:
26+
# - some-directory
27+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
28+
# - location:
29+
# git: https://github.com/commercialhaskell/stack.git
30+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
31+
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
32+
# subdirs:
33+
# - auto-update
34+
# - wai
35+
packages:
36+
- .
37+
38+
extra-deps:
39+
- llvm-hs-4.0.1.0
40+
- llvm-hs-pure-4.0.0.0
41+
# Dependency packages to be pulled from upstream that are not in the resolver
42+
# using the same syntax as the packages field.
43+
# (e.g., acme-missiles-0.3)
44+
# extra-deps: []
45+
46+
# Override default flag values for local packages and extra-deps
47+
# flags: {}
48+
49+
# Extra package databases containing global packages
50+
# extra-package-dbs: []
51+
52+
# Control whether we use the GHC we find on the path
53+
# system-ghc: true
54+
#
55+
# Require a specific version of stack, using version ranges
56+
# require-stack-version: -any # Default
57+
# require-stack-version: ">=1.9"
58+
#
59+
# Override the architecture used by stack, especially useful on Windows
60+
# arch: i386
61+
# arch: x86_64
62+
#
63+
# Extra directories used by stack for building
64+
# extra-include-dirs: [/path/to/dir]
65+
# extra-lib-dirs: [/path/to/dir]
66+
#
67+
# Allow a newer minor version of GHC than the snapshot specifies
68+
# compiler-check: newer-minor

test/Spec.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Lib
2+
3+
main :: IO ()
4+
main
5+
| "Check" == "Check" = putStrLn "Test Passing"
6+
| otherwise = putStrLn "Test Failed"

0 commit comments

Comments
 (0)