Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion OCaml/hw1/python_hint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))