Preprocessor now converts '4 4' into '4 * 4'.

parent 7aee3e1c
...@@ -90,12 +90,13 @@ class Parser(BisonParser): ...@@ -90,12 +90,13 @@ class Parser(BisonParser):
# - "4a" with "4*a". # - "4a" with "4*a".
# - "a4" with "a^4". # - "a4" with "a^4".
pattern = ('(?:(\))\s*(\()' # match: )( pattern = ('(?:(\))\s*(\()' # match: )( result: ) * (
+ '|([a-z0-9])\s*(\()' # match: a( + '|([a-z0-9])\s*(\()' # match: a( result: a * (
+ '|(\))\s*([a-z0-9])' # match: )a + '|(\))\s*([a-z0-9])' # match: )a result: ) * a
+ '|([a-z])\s*([a-z]+)' # match: ab + '|([a-z])\s*([a-z]+)' # match: ab result: a * b
+ '|([0-9])\s*([a-z])' # match: 4a + '|([0-9])\s*([a-z])' # match: 4a result: 4 * a
+ '|([a-z])\s*([0-9]))') # match: a4 + '|([a-z])\s*([0-9])' # match: a4 result: a ^ 4
+ '|([0-9])\s+([0-9]))') # match: 4 4 result: 4 * 4
def preprocess_data(match): def preprocess_data(match):
left, right = filter(None, match.groups()) left, right = filter(None, match.groups())
...@@ -107,7 +108,7 @@ class Parser(BisonParser): ...@@ -107,7 +108,7 @@ class Parser(BisonParser):
# If all characters on the right are numbers. e.g. "a4", the # If all characters on the right are numbers. e.g. "a4", the
# expression implies exponentiation. Make sure ")4" is not # expression implies exponentiation. Make sure ")4" is not
# converted into an exponentiation, because that's multiplication. # converted into an exponentiation, because that's multiplication.
if left != ')' \ if left != ')' and not 48 <= ord(left) < 58 \
and all(map(lambda x: 48 <= ord(x) < 58, list(right))): and all(map(lambda x: 48 <= ord(x) < 58, list(right))):
return '%s^%s' % (left, right) return '%s^%s' % (left, right)
......
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