----------------------------------------------------------------------
-- Visualize the sunting-yard algorithm steps
----------------------------------------------------------------------

-- | Similar to the 'shunt' function but print the steps
-- performed by the modified shunting yard algorithm.
-- This function is useful to understand (and debug) the
-- modified shunting-yard algorithm.
steps :: Token a => Table a -> [SExpr a] -> IO ()
steps table ts = do
  putStrLn "               Input               Stack              Output   Rule"
  let sh = iterate (step table) $ initial ts
      l = length $ takeWhile (not . isDone) sh
  mapM_ (putStrLn . showShunt) (take (l + 1) sh)

----------------------------------------------------------------------
-- Convenience functions used in step and apply
----------------------------------------------------------------------

-- Convert a SExpr to a Tree
steps :: Token a => Table a -> [SExpr a] -> IO ()
steps table ts = do
  putStrLn "               Input               Stack              Output   Rule"
  let sh = iterate (step table) $ initial ts
      l = length $ takeWhile (not . isDone) sh
  mapM_ (putStrLn . showShunt) (take (l + 1) sh)

----------------------------------------------------------------------
-- Convenience functions used in step and apply
----------------------------------------------------------------------

-- Convert a SExpr to a Tree
steps table ts = do
  putStrLn "               Input               Stack              Output   Rule"
  let sh = iterate (step table) $ initial ts
      l = length $ takeWhile (not . isDone) sh
  mapM_ (putStrLn . showShunt) (take (l + 1) sh)

----------------------------------------------------------------------
-- Convenience functions used in step and apply
----------------------------------------------------------------------

-- Convert a SExpr to a Tree