Skip to content

Commit 35b231c

Browse files
author
MaxVortman
committed
HUnit installed and a first test passed.
1 parent 7fe0f58 commit 35b231c

13 files changed

+332
-44
lines changed

ChangeLog.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog for LangToGroup
2+
3+
## Unreleased changes

LangToGroup.cabal

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
-- This file has been generated from package.yaml by hpack version 0.28.2.
2+
--
3+
-- see: https://github.com/sol/hpack
4+
--
5+
-- hash: e5bd5a115e6c958840612b41dc6ceef41bd84bb315db8601a999ae2433b24be4
6+
7+
name: LangToGroup
8+
version: 0.1.0.0
9+
description: Please see the README on GitHub at <https://github.com/githubuser/LangToGroup#readme>
10+
homepage: https://github.com/githubuser/LangToGroup#readme
11+
bug-reports: https://github.com/githubuser/LangToGroup/issues
12+
author: Author name here
13+
maintainer: [email protected]
14+
copyright: 2018 Author name here
15+
license: BSD3
16+
license-file: LICENSE
17+
build-type: Simple
18+
cabal-version: >= 1.10
19+
extra-source-files:
20+
ChangeLog.md
21+
README.md
22+
23+
source-repository head
24+
type: git
25+
location: https://github.com/githubuser/LangToGroup
26+
27+
library
28+
exposed-modules:
29+
CfgToTm1Mapper
30+
GrammarType
31+
Lib
32+
PdaType
33+
Tm1Type
34+
other-modules:
35+
Paths_LangToGroup
36+
hs-source-dirs:
37+
src
38+
build-depends:
39+
base >=4.7 && <5
40+
, containers
41+
default-language: Haskell2010
42+
43+
executable LangToGroup-exe
44+
main-is: Main.hs
45+
other-modules:
46+
Paths_LangToGroup
47+
hs-source-dirs:
48+
app
49+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
50+
build-depends:
51+
LangToGroup
52+
, base >=4.7 && <5
53+
, containers
54+
default-language: Haskell2010
55+
56+
test-suite LangToGroup-test
57+
type: exitcode-stdio-1.0
58+
main-is: Spec.hs
59+
other-modules:
60+
Paths_LangToGroup
61+
hs-source-dirs:
62+
test
63+
ghc-options: -threaded -rtsopts -with-rtsopts=-N
64+
build-depends:
65+
HUnit
66+
, LangToGroup
67+
, base >=4.7 && <5
68+
, containers
69+
, test-framework
70+
, test-framework-hunit
71+
default-language: Haskell2010

PdaType.hs

-31
This file was deleted.

Setup.hs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

app/Main.hs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import Lib
4+
5+
main :: IO ()
6+
main = someFunc

package.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: LangToGroup
2+
version: 0.1.0.0
3+
github: "githubuser/LangToGroup"
4+
license: BSD3
5+
author: "Author name here"
6+
maintainer: "[email protected]"
7+
copyright: "2018 Author name here"
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/githubuser/LangToGroup#readme>
21+
22+
dependencies:
23+
- base >= 4.7 && < 5
24+
- containers
25+
26+
library:
27+
source-dirs: src
28+
29+
executables:
30+
LangToGroup-exe:
31+
main: Main.hs
32+
source-dirs: app
33+
ghc-options:
34+
- -threaded
35+
- -rtsopts
36+
- -with-rtsopts=-N
37+
dependencies:
38+
- LangToGroup
39+
40+
tests:
41+
LangToGroup-test:
42+
main: Spec.hs
43+
source-dirs: test
44+
ghc-options:
45+
- -threaded
46+
- -rtsopts
47+
- -with-rtsopts=-N
48+
dependencies:
49+
- LangToGroup
50+
- HUnit
51+
- test-framework
52+
- test-framework-hunit

CfgToTm1Mapper.hs src/CfgToTm1Mapper.hs

+27-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module CfgToTm1Mapper where
22

33
import qualified PdaType
44
import qualified GrammarType
5+
import qualified Tm1Type
56
import Data.Set (Set)
67
import qualified Data.Set as Set
78

@@ -21,17 +22,19 @@ mapCfgToPda
2122
let startState = PdaType.State 's'
2223
let finalState = PdaType.State 'f'
2324
let states = PdaType.States (Set.fromList [startState, finalState])
24-
let mappedRelations = do
25-
let mapSymbolToLetter (GrammarType.T (GrammarType.Terminal x)) = PdaType.Letter x
26-
let mapSymbolToLetter (GrammarType.N (GrammarType.Nonterminal x)) = PdaType.Letter x
27-
let mapListOfSymbolsToListOfLetters = map mapSymbolToLetter
28-
Set.map (\(GrammarType.Relation (GrammarType.Nonterminal nonterminalSymbol, symbols)) ->
29-
PdaType.TransitionRelation (
30-
(finalState, PdaType.emptySymbol, PdaType.Letter nonterminalSymbol),
31-
(finalState, mapListOfSymbolsToListOfLetters symbols)
32-
))
25+
let mapSymbolToLetter x =
26+
case x of
27+
GrammarType.T (GrammarType.Terminal c) -> PdaType.Letter c
28+
GrammarType.N (GrammarType.Nonterminal c) -> PdaType.Letter c
29+
let mapListOfSymbolsToListOfLetters = map mapSymbolToLetter
30+
let mappedRelations =
31+
Set.map (\(GrammarType.Relation (GrammarType.Nonterminal nonterminalSymbol, symbols)) ->
32+
PdaType.TransitionRelation (
33+
(finalState, PdaType.emptySymbol, PdaType.Letter nonterminalSymbol),
34+
(finalState, mapListOfSymbolsToListOfLetters symbols)
35+
))
3336
setOfRelations
34-
let transinstFromTerminals = Set.map
37+
let transitionsFromTerminals = Set.map
3538
(\letter ->
3639
PdaType.TransitionRelation (
3740
(finalState, letter, letter),
@@ -43,7 +46,7 @@ mapCfgToPda
4346
(startState, PdaType.emptySymbol, PdaType.emptySymbol),
4447
(finalState, [PdaType.Letter startSymbol])
4548
))
46-
(Set.union mappedRelations transinstFromTerminals)
49+
(Set.union mappedRelations transitionsFromTerminals)
4750
PdaType.Pda (
4851
states,
4952
pdaInputAlphabet,
@@ -52,4 +55,16 @@ mapCfgToPda
5255
startState,
5356
PdaType.InitialStackSymbols [],
5457
PdaType.AcceptingStates (PdaType.States (Set.fromList [finalState]))
55-
)
58+
)
59+
60+
-- mapPdaToTm1 :: PdaType.Pda -> Tm1Type.TM1
61+
-- mapPdaToTm1
62+
-- (PdaType.Pda
63+
-- (PdaType.States setOfStates,
64+
-- PdaType.InputAlphabet setOfInputLetters,
65+
-- PdaType.StackAlphabet setOfStackLetters,
66+
-- PdaType.TransitionRelations setOfTransitions,
67+
-- startState,
68+
-- PdaType.InitialStackSymbols listOfInitialStackLetters,
69+
-- PdaType.AcceptingStates)
70+
-- ) = do

GrammarType.hs src/GrammarType.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ newtype Nonterminal = Nonterminal Char
99
deriving (Eq, Ord)
1010
-- union of terminal and nonterminal
1111
data Symbol = T Terminal | N Nonterminal
12+
deriving (Eq, Ord)
1213
-- start symbol must be a nonterminal synonym
1314
type StartSymbol = Nonterminal
1415
-- grammar relation
1516
newtype Relation = Relation (Nonterminal, [Symbol])
17+
deriving (Eq, Ord)
1618
newtype Relations = Relations (Set Relation)
19+
deriving (Eq, Ord)
1720
newtype Nonterminals = Nonterminals (Set Nonterminal)
21+
deriving (Eq, Ord)
1822
newtype Terminals = Terminals (Set Terminal)
23+
deriving (Eq, Ord)
1924
-- grammar type
20-
newtype Grammar = Grammar (Nonterminals, Terminals, Relations, StartSymbol)
25+
newtype Grammar = Grammar (Nonterminals, Terminals, Relations, StartSymbol)
26+
deriving (Eq, Ord)

src/Lib.hs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Lib
2+
( someFunc
3+
) where
4+
5+
someFunc :: IO ()
6+
someFunc = putStrLn "someFunc"

src/PdaType.hs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module PdaType where
2+
3+
import Data.Set (Set)
4+
import qualified Data.Set as Set
5+
6+
newtype State = State Char
7+
deriving (Eq, Ord, Show)
8+
9+
newtype States = States (Set State)
10+
deriving (Eq, Ord, Show)
11+
12+
-- letter
13+
newtype Letter = Letter Char
14+
deriving (Eq, Ord, Show)
15+
-- input, stack alphabets
16+
newtype InputAlphabet = InputAlphabet (Set Letter)
17+
deriving (Eq, Ord, Show)
18+
newtype StackAlphabet = StackAlphabet (Set Letter)
19+
deriving (Eq, Ord, Show)
20+
type StartState = State
21+
22+
newtype InitialStackSymbols = InitialStackSymbols [Letter]
23+
deriving (Eq, Ord, Show)
24+
25+
newtype AcceptingStates = AcceptingStates States
26+
deriving (Eq, Ord, Show)
27+
28+
newtype TransitionRelation = TransitionRelation ((State, Letter, Letter), (State, [Letter]))
29+
deriving (Eq, Ord, Show)
30+
31+
newtype TransitionRelations = TransitionRelations (Set TransitionRelation)
32+
deriving (Eq, Ord, Show)
33+
emptySymbol = Letter 'ε'
34+
35+
newtype Pda = Pda (States, InputAlphabet, StackAlphabet, TransitionRelations, StartState, InitialStackSymbols, AcceptingStates)
36+
deriving (Eq, Ord)
37+
38+
instance Show Pda where
39+
show (Pda (states, inputAlphabet, stackAlphabet, transitionRelations, startState, initialStackSymbols, acceptingStates)) =
40+
"\tStates: " ++ show states ++
41+
"\n\tInputAlphabet: " ++ show inputAlphabet ++
42+
"\n\tStackAlphabet: " ++ show stackAlphabet ++
43+
"\n\tTransitionRelations: " ++ show transitionRelations ++
44+
"\n\tStartState: " ++ show startState ++
45+
"\n\tInitialStackSymbols: " ++ show initialStackSymbols ++
46+
"\n\tAcceptingStates: " ++ show acceptingStates

Tm1Type.hs src/Tm1Type.hs

File renamed without changes.

stack.yaml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
# resolver: ghcjs-0.1.0_ghc-7.10.2
15+
#
16+
# The location of a snapshot can be provided as a file or url. Stack assumes
17+
# a snapshot provided as a file might change, whereas a url resource does not.
18+
#
19+
# resolver: ./custom-snapshot.yaml
20+
# resolver: https://example.com/snapshots/2018-01-01.yaml
21+
resolver: lts-12.13
22+
23+
# User packages to be built.
24+
# Various formats can be used as shown in the example below.
25+
#
26+
# packages:
27+
# - some-directory
28+
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
29+
# - location:
30+
# git: https://github.com/commercialhaskell/stack.git
31+
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
32+
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
33+
# subdirs:
34+
# - auto-update
35+
# - wai
36+
packages:
37+
- .
38+
# Dependency packages to be pulled from upstream that are not in the resolver
39+
# using the same syntax as the packages field.
40+
# (e.g., acme-missiles-0.3)
41+
# extra-deps: []
42+
43+
# Override default flag values for local packages and extra-deps
44+
# flags: {}
45+
46+
# Extra package databases containing global packages
47+
# extra-package-dbs: []
48+
49+
# Control whether we use the GHC we find on the path
50+
# system-ghc: true
51+
#
52+
# Require a specific version of stack, using version ranges
53+
# require-stack-version: -any # Default
54+
# require-stack-version: ">=1.7"
55+
#
56+
# Override the architecture used by stack, especially useful on Windows
57+
# arch: i386
58+
# arch: x86_64
59+
#
60+
# Extra directories used by stack for building
61+
# extra-include-dirs: [/path/to/dir]
62+
# extra-lib-dirs: [/path/to/dir]
63+
#
64+
# Allow a newer minor version of GHC than the snapshot specifies
65+
# compiler-check: newer-minor

0 commit comments

Comments
 (0)