sine-patre/fol/pretty.py

24 lines
681 B
Python
Raw Normal View History

2024-04-25 16:47:45 +00:00
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}')