diff --git a/OCaml/hw1/python_hint.py b/OCaml/hw1/python_hint.py index e47d593..f019a67 100644 --- a/OCaml/hw1/python_hint.py +++ b/OCaml/hw1/python_hint.py @@ -127,12 +127,17 @@ def __eq__(self, other): (symbol('N', 'Num'), [symbol('T', "9")])] sample_grammar = (symbol('N', 'Expr'), sample_rules[2:]) +sample_grammar2 = (symbol('N', 'Lvalue'), sample_rules[2:]) def equal_second_elem_sets(a, b): return equal_sets(a[1], b[1]) def get_reachable_symbols(params): + # use a helper function so that we can call compute_fixed_point with the full grammar each time + return get_reachable_symbols_helper(params) + +def get_reachable_symbols_helper(params): rules, reachable_symbols = params if len(rules) == 0: return (rules, reachable_symbols) @@ -167,4 +172,5 @@ def filter_reachable(g): if __name__ == '__main__': - print(filter_reachable(sample_grammar)) + print("Test 1", filter_reachable(sample_grammar)) + print("Test 2", filter_reachable(sample_grammar2))