Skip to content

Commit b86e3f9

Browse files
committed
Pycalc release v1.0.8.
1 parent 436071c commit b86e3f9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

final_task/pycalc/pycalc.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self):
6767

6868
"space": full_info(None, None, None, r'[ \n\t]+', None),
6969
"int_n": full_info(None, None, None, r'[0-9]+', self.tag_number),
70-
"int_f": full_info(None, None, None, r'[0-9]+\.[0-9]', self.tag_number),
70+
"int_f": full_info(None, None, None, r'[0-9]+\.[0-9]+', self.tag_number),
7171
"int_f2": full_info(None, None, None, r'\.[0-9]', self.tag_number),
7272

7373

@@ -183,7 +183,7 @@ def rpn_from_stacked_string(self, stack):
183183
elif item == ",":
184184
while temporary_stack[-1] != "(":
185185
rpn_stack.append(temporary_stack.pop())
186-
elif self.operators[temporary_stack[-1]].priority <= self.operators[item].priority:
186+
elif self.operators[temporary_stack[-1]].priority < self.operators[item].priority:
187187
temporary_stack.append(item)
188188
else:
189189
temp_priority = self.operators[item].priority
@@ -254,6 +254,9 @@ def calculate(self, input_string):
254254
except RuntimeError as rerror:
255255
print(rerror.args[0])
256256
exit(1)
257+
except ValueError as verror:
258+
print(verror.args[0])
259+
exit(1)
257260
return result
258261

259262
@staticmethod
@@ -283,6 +286,8 @@ def get_math_operators(math_priority, tag_operators, tag_constants, tuple_templa
283286
math_constants.update({item: tuple_template(math.__dict__.get(item), None, None, item,
284287
tag_constants)})
285288

289+
math_operators.update({'log': tuple_template(math.log, math_priority, 1, 'log', tag_operators)})
290+
286291
return math_operators, math_constants
287292

288293
@staticmethod
@@ -302,7 +307,7 @@ def lexer(characters, token_exprs, tuple_template):
302307
tokens.append(token)
303308
break
304309
if not match:
305-
raise RuntimeError('Illegal character: %s\n' % characters[pos])
310+
raise RuntimeError('ERROR: Illegal character: %s\n' % characters[pos])
306311
else:
307312
pos = match.end(0)
308313
return tokens
@@ -319,3 +324,7 @@ def main():
319324

320325
if __name__ == '__main__':
321326
main()
327+
328+
# calc = PyCalc()
329+
# result = calc.calculate('6 < = 6')
330+
# print(result)

0 commit comments

Comments
 (0)