-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I have broken something and I need to get an overview.
- Loading branch information
1 parent
9f16faa
commit 863b78c
Showing
9 changed files
with
168 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
module Alpacc.Lexer.DFAParallelLexer | ||
(dfaParallelLexer | ||
,intDfaParallelLexer) | ||
where | ||
|
||
import Alpacc.Lexer.FSA | ||
import Alpacc.Lexer.DFA | ||
import Alpacc.Lexer.Encode | ||
import Alpacc.Lexer.ParallelLexing | ||
import Data.Map.Strict (Map) | ||
import Data.Map.Strict qualified as Map hiding (Map) | ||
import Data.Set qualified as Set hiding (Set) | ||
import Data.Maybe | ||
import Data.Array.Base (IArray (..)) | ||
import Data.Array.Unboxed (UArray) | ||
import Data.Array.Unboxed qualified as UArray hiding (UArray) | ||
|
||
errorMessage :: String | ||
errorMessage = "Error: Happend during Parallel Lexing genration, contact a maintainer." | ||
|
||
data Endomorphism = | ||
Endomorphism | ||
{-# UNPACK #-} !(UArray S S) | ||
{-# UNPACK #-} !(UArray S Bool) deriving (Eq, Ord, Show) | ||
|
||
type S = Int | ||
|
||
deadState :: S | ||
deadState = 0 | ||
|
||
initState :: S | ||
initState = 1 | ||
|
||
endomorphismTable :: | ||
(Enum t, Bounded t, Ord t, Ord k) => | ||
ParallelDFALexer t S k -> | ||
Map t Endomorphism | ||
endomorphismTable lexer = | ||
Map.fromList | ||
$ map statesFromChar | ||
$ Set.toList _alphabet | ||
where | ||
dfa = fsa $ parDFALexer lexer | ||
produces_set = producesToken lexer | ||
_transitions = transitions' dfa | ||
_states = states dfa | ||
_alphabet = alphabet dfa | ||
first_index = deadState | ||
last_index = maximum _states | ||
tableLookUp key = | ||
fromMaybe deadState | ||
$ Map.lookup key _transitions | ||
statesFromChar t = (t, Endomorphism ss bs) | ||
where | ||
ss = | ||
UArray.array (first_index, last_index) | ||
$ zip [first_index..last_index] | ||
$ map (tableLookUp . (, t)) | ||
$ Set.toAscList _states | ||
bs = | ||
UArray.array (first_index, last_index) | ||
$ zip [first_index..last_index] | ||
$ map ((`Set.member` produces_set) . (, t)) | ||
$ Set.toAscList _states | ||
|
||
instance Semigroup Endomorphism where | ||
(Endomorphism a a') <> (Endomorphism b b') = Endomorphism c c' | ||
where | ||
c = UArray.array (0, numElements a - 1) | ||
$ map auxiliary [0..(numElements a - 1)] | ||
c' = UArray.array (0, numElements a' - 1) | ||
$ map auxiliary' [0..(numElements a' - 1)] | ||
auxiliary i = (i, b UArray.! (a UArray.! i)) | ||
auxiliary' i = (i, b' UArray.! (a UArray.! i)) | ||
|
||
instance Sim Endomorphism S where | ||
toState s endo = | ||
if a <= s && s <= b then | ||
(producing UArray.! s, endo' UArray.! s) | ||
else | ||
error errorMessage | ||
where | ||
(Endomorphism endo' producing) = endo | ||
(a, b) = bounds endo' | ||
|
||
dfaParallelLexer :: | ||
(Ord t, Ord s, Enum t, Bounded t, Ord k) => | ||
ParallelDFALexer t s k -> | ||
ParallelLexer t (EndoData k) | ||
dfaParallelLexer lexer' = parallelLexer lexer endo_table | ||
where | ||
lexer = enumerateParLexer initState lexer' | ||
endo_table = endomorphismTable lexer | ||
|
||
intDfaParallelLexer :: | ||
(Ord t, Ord s, Enum t, Bounded t, Ord k) => | ||
Map (Maybe k) Int -> | ||
ParallelDFALexer t s k -> | ||
Either String (IntParallelLexer t) | ||
intDfaParallelLexer m = intParallelLexer m . dfaParallelLexer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.