From 79ac9fe785348f52f46a7c7df1aad2a9f33bafa9 Mon Sep 17 00:00:00 2001 From: Kia <kia@special-circumstanc.es> Date: Thu, 6 Aug 2020 14:01:49 -0600 Subject: [PATCH] got the language-item-building working --- cfg_utils.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/cfg_utils.py b/cfg_utils.py index 8f1081e..39a4e25 100644 --- a/cfg_utils.py +++ b/cfg_utils.py @@ -96,9 +96,12 @@ def apply_rule(tree, leafcache, cache_index, ruleset, rule_number): location = leafcache[cache_index] - for depth_index in location: - opsite = opsite.subnodes[depth_index] - print("TMP index ", depth_index, " gives ",opsite) + if (location != []): + for depth_index in location: + opsite = opsite.subnodes[depth_index] + print("TMP index ", depth_index, " gives ",opsite) + else: + opsite = tree print(opsite) walk_the_tree(opsite) @@ -144,20 +147,22 @@ def apply_rule(tree, leafcache, cache_index, ruleset, rule_number): -test_tree = TreeNode(symbols.EXPRESSION, [ - TreeNode(symbols.ADDOP,[]), - TreeNode(symbols.MULTOP,[ - TreeNode(symbols.EXPRESSION,[]), TreeNode(symbols.TERM,[]),TreeNode(symbols.FACTOR,[]) - ]) - ]) +test_tree = TreeNode(symbols.EXPRESSION, []) walk_the_tree(test_tree) #def next_stage(derivation_tree_with_cached, language_definition): -leafcache = [[1,1]] -apply_rule(test_tree,leafcache,0,rules,2) +leafcache = [[]] +apply_rule(test_tree,leafcache,0,rules,0) +print("and the tree looks like") +walk_the_tree(test_tree) + +print("updated leafcache") +print(leafcache) + +apply_rule(test_tree,leafcache,2,rules,2) print("and the tree looks like") walk_the_tree(test_tree) -- GitLab