24 lines
681 B
Python
24 lines
681 B
Python
|
def get(f):
|
||
|
if f.name == 'EXISTS':
|
||
|
return f'\\exist {get(f.children[0])}({get(f.children[1])})'
|
||
|
|
||
|
if f.name == 'NOT':
|
||
|
return '~' + get(f.children[0])
|
||
|
|
||
|
if f.name == 'AND':
|
||
|
return '(' + " & ".join([get(c) for c in f.children]) + ')'
|
||
|
|
||
|
if f.name == 'OR':
|
||
|
return '(' + " | ".join([get(c) for c in f.children]) + ')'
|
||
|
|
||
|
if f.name in ['PRED', 'FUN']:
|
||
|
return f.value + "(" + ", ".join([get(c) for c in f.children]) + ")"
|
||
|
|
||
|
if f.name in ['VAR', 'CONST']:
|
||
|
return f.value
|
||
|
|
||
|
if f.name == 'IMP':
|
||
|
return '(' + get(f.children[0]) + ' -> ' + get(f.children[1]) + ')'
|
||
|
|
||
|
raise Exception(f'cannot print f = {f.name}')
|