diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-05-14 04:48:46 +1000 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-05-14 04:48:46 +1000 |
commit | 8824d5725b40a2b1eb57b81110fe7c5ec9a4916d (patch) | |
tree | a84379910ac4f116cba829244a427606d3f3fcf4 | |
parent | 1cd61e1840794500166d3f8c18d9010ad5564f37 (diff) |
Function to calculate reachable nodes complete
-rw-r--r-- | src/Grasp/Interpreter.hs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Grasp/Interpreter.hs b/src/Grasp/Interpreter.hs index e556414..03816f6 100644 --- a/src/Grasp/Interpreter.hs +++ b/src/Grasp/Interpreter.hs @@ -5,7 +5,7 @@ module Grasp.Interpreter ( import Data.Graph.Inductive.Graph( Node, LNode, LEdge, (&) ) import qualified Data.Graph.Inductive.Graph as Graph -import qualified Data.Set as Set +import Data.List import Grasp.Types import Grasp.Parser @@ -24,7 +24,19 @@ grasp g = reachable :: GraspProgram -> [IP] -> [Node] -reachable g ips = Graph.nodes g +reachable g ips = + let startNodes = nub . (map fst) $ (namedNodes g) ++ (concat ips) + in reach g startNodes [] + + + +reach :: GraspProgram -> [Node] -> [Node] -> [Node] +reach _ [] f = f +reach g s@(x:xs) f = + let f' = nub (x:f) + s' = nub (xs ++ (Graph.suc g x)) + g' = Graph.delNode x g + in reach g' s' f' |