Commit 81415bb0 authored by Taddeus Kroes's avatar Taddeus Kroes

Added identifier possibility parser concerning syntax 'log_g(x)'.

parent d7329b8d
......@@ -398,10 +398,15 @@ class Parser(BisonParser):
if op == OP_VALUE_MAP[OP_LOG]:
return Node(OP_LOG, values[1], Leaf(DEFAULT_LOGARITHM_BASE))
m = re.match(r'^log_([0-9]+)', op)
m = re.match(r'^log_([0-9]+|[a-zA-Z])', op)
if m:
return Node(OP_LOG, values[1], Leaf(int(m.group(1))))
value = m.group(1)
if value.isdigit():
value = int(value)
return Node(OP_LOG, values[1], Leaf(value))
return Node(op, values[1])
......@@ -534,8 +539,8 @@ class Parser(BisonParser):
"[" { returntoken(LBRACKET); }
"]" { returntoken(RBRACKET); }
"'" { returntoken(APOSTROPH); }
log_[0-9]+"*(" { returntoken(FUNCTION_LPAREN); }
log_[0-9]+"*" { returntoken(FUNCTION); }
log_([0-9]+|[a-zA-Z])"*(" { returntoken(FUNCTION_LPAREN); }
log_([0-9]+|[a-zA-Z])"*" { returntoken(FUNCTION); }
""" + operators + r"""
"raise" { returntoken(RAISE); }
"graph" { returntoken(GRAPH); }
......
......@@ -84,3 +84,8 @@ class TestParser(unittest.TestCase):
self.assertEqual(tree('log(x, 10)'), log(x))
self.assertEqual(tree('log(x, 2)'), log(x, 2))
self.assertEqual(tree('log(x, g)'), log(x, g))
self.assertEqual(tree('log_2(x)'), log(x, 2))
self.assertEqual(tree('log_10(x)'), log(x))
self.assertEqual(tree('log_g(x)'), log(x, g))
self.assertEqual(tree('log_g x'), log(x, g))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment