Working on pseudocode for new stateful collapseNodes algorithm in graph_algs.txt.

This commit is contained in:
Robbie Gleichman 2016-11-07 13:41:07 -08:00
parent 78dde11454
commit 4f87457639
2 changed files with 25 additions and 0 deletions

View File

@ -38,6 +38,7 @@ data Icon = ResultIcon | BranchIcon | TextBoxIcon String | GuardIcon Int
deriving (Show, Eq)
-- TODO remove Ints from SyntaxNode data constructors.
-- TODO Add NestedApplyNode, and NestedPatternApplyNode
data SyntaxNode = ApplyNode Int-- Function application
| PatternApplyNode String Int -- Destructors as used in patterns
| NameNode String -- Identifiers or symbols

View File

@ -1,5 +1,29 @@
-- Pseudocode for collapsing a syntax graph.
-- New stateful algorithm
-- Note: Node refers to the FGL node, which is just an integer. The node label has to be looked up separately in the graph.
-- The node label has all of the information about the node such as what SyntaxNode it represents.
collapseNodes :: SyntaxGrrah -> SyntaxGraph
collapseNodes originalGraph = finalGraph where
-- findTreeRoots returns a list of nodes that will embed other nodes, but are not embedded themselves.
-- These nodes are thus each a root of a collapsed node tree.
treeRoots = findTreeRoots originalGraph
-- Now collapse each tree of nodes
finalGraph = foldl' collapseTree originalGraph treeRoots
collapseTree :: SyntaxGraph -> Node -> SyntaxGraph
collapseTree oldGraph rootNode = newGraph where
childrenToEmbed = findChildrenToEmbed rootNode oldGraph
-- TODO
findChildrenToEmbed :: Node -> SyntaxGraph -> [Node]
findChildrenToEmbed = -- TODO
-- OLD ALGORITHM
-- To make the problem simpler, collapseNodes just cares about the
collapseNodes :: SyntaxGraph -> SyntaxGraph
collapseNodes inGraph = graphFold foldFunc initialOutputGraph inGraph where