Alright, I'm trying to write a simple parser given the following:
d = {
'a': [1,2,3,4],
'b': [2,3,4,5],
'c': [2,4,6,7]
}
And the following two function:
def _and(l1, l2):
return [i for i in l1 if i in l2]
def _or(l1, l2):
return list(set(l1+l2))
I am trying to take in a string (e.g. "a||(b&c)"
) and parse it into the following:
_or(d['a'],_and(d['b'],d['c']))
I've never written a parser before, so I'm a little lost. The parser should support OR
, AND
and parentheses. Could someone point me in the right direction? A similar example in Python would be great if anyone knows of any.