Skip to content

Commit

Permalink
make it strict
Browse files Browse the repository at this point in the history
  • Loading branch information
kwanghoon committed Mar 18, 2022
1 parent 536b02b commit 6a609a9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies:
- hspec
- transformers
- mtl
- deepseq >= 1.4.4.0

# --------------------------------------------------
# -- Main library: YAPB (Yet Another Parser Builder)
Expand Down
16 changes: 11 additions & 5 deletions src/parserlib/algo/SynCompAlgoBUTreeNested.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Config

import Data.Typeable
import Data.List (nub)
import Control.DeepSeq

--
compCandidates
Expand Down Expand Up @@ -160,7 +161,7 @@ extendedNestedCandidates ccOption initStateStkCandsList =
let nextFailContListList = map snd nextSuccFailContListList

return ( concat succContListList ++ concat nextSuccContListList
, concat nextFailContListList)
, concat nextFailContListList )

else
return ([], [])
Expand Down Expand Up @@ -267,6 +268,7 @@ simulReduce ccOption symbols prnum len i state stk =
rhsLength = length rhs

len_leafs_symbols = length (leafs symbols)
len_symbols = length symbols
in
-- debug flag $ prlevel level ++ "[simulReduce] " ++ show (cc_searchState ccOption)

Expand All @@ -281,8 +283,11 @@ simulReduce ccOption symbols prnum len i state stk =
if isFinalReduce searchState
then
-- Todo: Sometime (>) is correct sometimes (>=) is correct!

-- if rhsLength >= length (leafs symbols) && {- length symbols > 0 && -} length (leafs symbols) > 0

if rhsLength >= len_leafs_symbols && len_leafs_symbols > 0
-- if rhsLength >= len_symbols && len_symbols > 0
then
do let stk1 = drop (rhsLength*2) stk
let topState = currentState stk1
Expand Down Expand Up @@ -504,7 +509,7 @@ repGotoOrShift ccOption symbols state stk =

if null listOfList1 -- || isInitReduces (cc_searchState ccOption)
then
if gs_level (cc_searchState ccOption) - 1 > 0 then
if gs_level (cc_searchState ccOption) - 1 > 0 then -- Todo: -1 ???
let ccOption' = ccOption{cc_searchState=
SS_GotoOrShift
(r_level (cc_searchState ccOption))
Expand All @@ -521,7 +526,7 @@ repGotoOrShift ccOption symbols state stk =

-- else

let isInnerMostLevel = r_level (cc_searchState ccOption) == cc_r_level ccOption
let isInnerMostLevel = True -- r_level (cc_searchState ccOption) == cc_r_level ccOption
simulFirst = if isInnerMostLevel then simulShift else simulGoto
simulSecond = if isInnerMostLevel then simulGoto else simulShift
in
Expand All @@ -532,10 +537,11 @@ repGotoOrShift ccOption symbols state stk =
then

do (listOfList3, failCont3) <- simulSecond ccOption' symbols state stk
return $ (listOfList1 ++ listOfList2 ++ listOfList3, failCont3)
return $ ( listOfList1 ++ listOfList2 ++ listOfList3
, failCont1 ++ failCont2 ++ failCont3 )

else
return $ (listOfList1 ++ listOfList2, failCont2)
return $ (listOfList1 ++ listOfList2, failCont1 ++ failCont2)

else
return (listOfList1, failCont1) -- Q: symbols or []
Expand Down
30 changes: 15 additions & 15 deletions src/parserlib/algo/SynCompAlgoUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Debug.Trace (trace)

-- | Candidates
data Candidate = -- data Candidate vs. data EmacsDataItem = ... | Candidate String
TerminalSymbol String
| NonterminalSymbol String
TerminalSymbol !String
| NonterminalSymbol !String
deriving Eq

-- | Candidate tree
Expand All @@ -22,8 +22,8 @@ data Candidate = -- data Candidate vs. data EmacsDataItem = ... | Candidate Stri
-}

data CandidateTree =
Leaf Candidate
| Node Candidate [CandidateTree]
Leaf !Candidate
| Node !Candidate ![CandidateTree]
deriving (Eq,Show)

type CandidateForest = [CandidateTree]
Expand Down Expand Up @@ -62,16 +62,16 @@ data Automaton token ast =

-- | Computing candidates
data CompCandidates token ast = CompCandidates {
cc_debugFlag :: Bool,
cc_printLevel :: Int,
cc_maxLevel :: Int,
cc_debugFlag :: !Bool,
cc_printLevel :: !Int,
cc_maxLevel :: !Int,

cc_r_level :: Int, -- for new algorithm
cc_gs_level :: Int, --
cc_r_level :: !Int, -- for new algorithm
cc_gs_level :: !Int, --

cc_simpleOrNested :: Bool,
cc_automaton :: Automaton token ast,
cc_searchState :: SearchState
cc_simpleOrNested :: !Bool,
cc_automaton :: !(Automaton token ast),
cc_searchState :: !SearchState
}


Expand All @@ -81,9 +81,9 @@ type R_Level = Int
type GS_Level = Int

data SearchState =
SS_InitReduces R_Level GS_Level -- Reduce^*
| SS_GotoOrShift R_Level GS_Level -- (Goto | Shift)
| SS_FinalReduce R_Level GS_Level -- Reduce
SS_InitReduces !R_Level !GS_Level -- Reduce^*
| SS_GotoOrShift !R_Level !GS_Level -- (Goto | Shift)
| SS_FinalReduce !R_Level !GS_Level -- Reduce

instance Show SearchState where
showsPrec p (SS_InitReduces r gs) = (++) $ "I:" ++ show r ++ ":" ++ show gs
Expand Down
10 changes: 9 additions & 1 deletion yapb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 1d5fb6cd20b2a1521c4c26ab92651dbd5abaffad85de4ecbb28d491eac58e6e6
-- hash: 127089f7fac770f1c3d2f9516b70bacbdc45ba60fd37e79b55c0767f8b15c4e1

name: yapb
version: 0.1.4
Expand Down Expand Up @@ -65,6 +65,7 @@ library
build-depends:
base >=4.7 && <5
, bytestring >=0.10.8 && <0.11
, deepseq >=1.4.4.0
, directory >=1.3.3 && <1.4
, hashable >=1.3.0 && <1.4
, hspec
Expand All @@ -91,6 +92,7 @@ executable ambiguous-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, regex-tdfa
Expand All @@ -107,6 +109,7 @@ executable conv-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, transformers
Expand All @@ -129,6 +132,7 @@ executable error-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, regex-tdfa
Expand All @@ -152,6 +156,7 @@ executable parser-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, regex-tdfa
Expand All @@ -175,6 +180,7 @@ executable syncomp-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, regex-tdfa
Expand All @@ -191,6 +197,7 @@ executable yapb-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, transformers
Expand All @@ -207,6 +214,7 @@ test-suite yapb-test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, deepseq >=1.4.4.0
, hspec
, mtl
, process
Expand Down

0 comments on commit 6a609a9

Please sign in to comment.