Added math constants to Parser evaluator

This commit is contained in:
Dmitriy Shishkov 2023-10-17 23:02:00 +03:00
parent f017e5e6ce
commit 416db85a29
Signed by: dm1sh
GPG Key ID: 027994B0AA357688
2 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,6 @@
import numpy as np
CONSTANTS = {
"e": np.e,
"pi": np.pi,
}

View File

@ -1,5 +1,3 @@
from collections.abc import Mapping
from .expression import BinaryExpression, Expression, UnaryExpression, ValueExpression
from .operation import (
BraceOperation,
@ -10,6 +8,7 @@ from .operation import (
)
from .tokenizer import Token, Tokenizer
from .types import ValueType
from .constants import CONSTANTS
class Parser:
@ -64,7 +63,8 @@ class Parser:
self.__debug_expr = repr(self.val_stack)
def evaluate(self, variables: Mapping[str, ValueType]):
def evaluate(self, variables: dict[str, ValueType]):
variables |= CONSTANTS
return self._evaluator(variables)
def do_one(self):