@@ -17,8 +17,7 @@ Path settings auto-generated by Cabal:
17
17
> import PrettyGrammar
18
18
> import Parser
19
19
20
- > import First
21
- > import LALR
20
+ > import Tabular
22
21
> import ProduceCode (produceParser )
23
22
> import ProduceGLRCode
24
23
> import Info (genInfoFile )
@@ -29,8 +28,7 @@ Path settings auto-generated by Cabal:
29
28
> import System.Exit (exitWith , ExitCode (.. ))
30
29
> import Data.Char
31
30
> import System.IO
32
- > import Data.Array ( assocs , elems , (!) )
33
- > import Data.List ( nub , isSuffixOf )
31
+ > import Data.List ( isSuffixOf )
34
32
> import Data.Version ( showVersion )
35
33
36
34
> main :: IO ()
@@ -84,30 +82,28 @@ Mangle the syntax into something useful.
84
82
85
83
> optPrint cli DumpMangle $ putStr $ show g
86
84
87
- > let first = {-# SCC "First" #-} (mkFirst g)
88
- > closures = {-# SCC "Closures" #-} (precalcClosure0 g)
89
- > sets = {-# SCC "LR0_Sets" #-} (genLR0items g closures)
90
- > _lainfo@ (spont,prop) = {-# SCC "Prop" #-} (propLookaheads g sets first)
91
- > la = {-# SCC "Calc" #-} (calcLookaheads (length sets) spont prop)
92
- > items2 = {-# SCC "Merge" #-} (mergeLookaheadInfo la sets)
93
- > goto = {-# SCC "Goto" #-} (genGotoTable g sets)
94
- > action = {-# SCC "Action" #-} (genActionTable g first items2)
95
- > (conflictArray,(sr,rr)) = {-# SCC "Conflict" #-} (countConflicts action)
85
+ > let select_reductions | OptGLR `elem` cli = select_all_reductions
86
+ > | otherwise = select_first_reduction
87
+
88
+ > let tables = genTables select_reductions g
89
+ > sets = lr0items tables
90
+ > lainfo = (la_prop tables, la_spont tables)
91
+ > la = lookaheads tables
92
+ > goto = gotoTable tables
93
+ > action = actionTable tables
94
+ > (conflictArray,(sr,rr)) = conflicts tables
96
95
97
96
Debug output
98
97
99
98
> optPrint cli DumpLR0 $ putStr $ show sets
100
99
> optPrint cli DumpAction $ putStr $ show action
101
100
> optPrint cli DumpGoto $ putStr $ show goto
102
- > optPrint cli DumpLA $ putStr $ show _lainfo
101
+ > optPrint cli DumpLA $ putStr $ show lainfo
103
102
> optPrint cli DumpLA $ putStr $ show la
104
103
105
104
Report any unused rules and terminals
106
105
107
- > let reduction_filter | OptGLR `elem` cli = any_reduction
108
- > | otherwise = first_reduction
109
- > (unused_rules, unused_terminals)
110
- > = find_redundancies reduction_filter g action
106
+ > let (unused_rules, unused_terminals) = redundancies tables
111
107
> when (not (null unused_rules))
112
108
> (hPutStrLn stderr (" unused rules: " ++ show (length unused_rules)))
113
109
> when (not (null unused_terminals))
@@ -298,49 +294,6 @@ Successfully Finished.
298
294
> constArgs :: [String ]
299
295
> constArgs = []
300
296
301
- -----------------------------------------------------------------------------
302
- Find unused rules and tokens
303
-
304
- > find_redundancies
305
- > :: (LRAction -> [Int ]) -> Grammar -> ActionTable -> ([Int ], [String ])
306
- > find_redundancies extract_reductions g action_table =
307
- > (unused_rules, map (env ! ) unused_terminals)
308
- > where
309
- > Grammar { terminals = terms,
310
- > token_names = env,
311
- > eof_term = eof,
312
- > starts = starts',
313
- > productions = productions'
314
- > } = g
315
-
316
- > actions = concat (map assocs (elems action_table))
317
- > start_rules = [ 0 .. (length starts' - 1 ) ]
318
- > used_rules = start_rules ++
319
- > nub [ r | (_,a) <- actions, r <- extract_reductions a ]
320
- > used_tokens = errorTok : eof :
321
- > nub [ t | (t,a) <- actions, is_shift a ]
322
- > n_prods = length productions'
323
- > unused_terminals = filter (`notElem` used_tokens) terms
324
- > unused_rules = filter (`notElem` used_rules ) [0 .. n_prods- 1 ]
325
-
326
- > is_shift :: LRAction -> Bool
327
- > is_shift (LR'Shift _ _) = True
328
- > is_shift (LR'Multiple _ LR'Shift {}) = True
329
- > is_shift _ = False
330
-
331
- ---
332
- selects what counts as a reduction when calculating used/unused
333
-
334
- > any_reduction :: LRAction -> [Int ]
335
- > any_reduction (LR'Reduce r _) = [r]
336
- > any_reduction (LR'Multiple as a) = concatMap any_reduction (a : as)
337
- > any_reduction _ = []
338
-
339
- > first_reduction :: LRAction -> [Int ]
340
- > first_reduction (LR'Reduce r _) = [r]
341
- > first_reduction (LR'Multiple _ a) = first_reduction a -- eg R/R conflict
342
- > first_reduction _ = []
343
-
344
297
------------------------------------------------------------------------------
345
298
346
299
> possDelit :: String -> String -> IO (String ,String )
0 commit comments