Skip to content

Commit 2bd3f24

Browse files
author
Due
committed
Set bracket not in parser.
1 parent 60744f1 commit 2bd3f24

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

src/Alpacc/Encode.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ hash =
320320

321321
data LLPTable
322322
= LLPTable
323-
{ llpStacks :: [Bracket Integer],
323+
{ llpStacks :: [Integer],
324324
llpProductions :: [Int],
325325
llpOATable :: OpenAddressing [Integer] ((Int, Int), (Int, Int))
326326
}
@@ -337,10 +337,15 @@ llpHashTable ::
337337
llpHashTable q k empty_terminal grammar encoder = do
338338
table <- llpParserTableWithStartsHomomorphisms q k $ getGrammar grammar
339339

340+
num_bits <- fromInteger . numBits <$> bracketIntType encoder
340341
let int_table =
341342
Map.mapKeys (uncurry (<>)) $
342343
padLLPTableKeys empty_terminal q k $
343344
toIntLLPTable encoder table
344-
(stacks, prods, flat_int_table) = flattenTuple int_table
345+
(stacks', prods, flat_int_table) = flattenTuple int_table
346+
stacks = map (bracketEncode num_bits) stacks'
345347
oa = openAdressing hash flat_int_table
346348
pure $ LLPTable stacks prods oa
349+
where
350+
bracketEncode nbs (LBracket a) = a `setBit` (nbs - 1)
351+
bracketEncode _ (RBracket a) = a

src/Alpacc/Generator/Futhark/Parser.hs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import Alpacc.Encode
77
import Alpacc.Generator.Analyzer
88
import Alpacc.Generator.Futhark.Futharkify
99
import Alpacc.HashTable
10-
import Alpacc.LLP
11-
( Bracket (..),
12-
)
1310
import Alpacc.Types
1411
import Data.FileEmbed
1512
import Data.String.Interpolate (i)
@@ -19,10 +16,6 @@ import Data.Text qualified as Text
1916
futharkParser :: Text
2017
futharkParser = $(embedStringFile "futhark/parser.fut")
2118

22-
futharkifyBracket :: (Futharkify a) => Bracket a -> RawString
23-
futharkifyBracket (LBracket a) = RawString . ("left " <>) $ futharkify a
24-
futharkifyBracket (RBracket a) = RawString . ("right " <>) $ futharkify a
25-
2619
-- | Creates Futhark source code which contains a parallel parser that can
2720
-- create the productions list for a input which is indexes of terminals.
2821
generateParser :: UInt -> Parser -> Text
@@ -40,12 +33,6 @@ type terminal = terminal_module.t
4033
type production = production_module.t
4134
type bracket = bracket_module.t
4235

43-
def left (s : bracket) : bracket =
44-
bracket_module.set_bit (bracket_module.num_bits - 1) s 1
45-
46-
def right (s : bracket) : bracket =
47-
bracket_module.set_bit (bracket_module.num_bits - 1) s 0
48-
4936
def number_of_productions: i64 = #{number_of_productions}
5037
def q: i64 = #{q}
5138
def k: i64 = #{k}
@@ -81,7 +68,7 @@ def productions: [productions_size]production =
8168
empty_terminal = emptyTerminal parser
8269
hash_table = llpTable parser
8370
number_of_productions = numberOfProductions parser
84-
stacks = futharkifyBracket <$> llpStacks hash_table
71+
stacks = llpStacks hash_table
8572
productions = llpProductions hash_table
8673
stacks_size = length $ llpStacks hash_table
8774
productions_size = length $ llpProductions hash_table

0 commit comments

Comments
 (0)