Added math constants to Parser evaluator
This commit is contained in:
parent
f017e5e6ce
commit
416db85a29
6
parser/parser/constants.py
Normal file
6
parser/parser/constants.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import numpy as np
|
||||||
|
|
||||||
|
CONSTANTS = {
|
||||||
|
"e": np.e,
|
||||||
|
"pi": np.pi,
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
from collections.abc import Mapping
|
|
||||||
|
|
||||||
from .expression import BinaryExpression, Expression, UnaryExpression, ValueExpression
|
from .expression import BinaryExpression, Expression, UnaryExpression, ValueExpression
|
||||||
from .operation import (
|
from .operation import (
|
||||||
BraceOperation,
|
BraceOperation,
|
||||||
@ -10,6 +8,7 @@ from .operation import (
|
|||||||
)
|
)
|
||||||
from .tokenizer import Token, Tokenizer
|
from .tokenizer import Token, Tokenizer
|
||||||
from .types import ValueType
|
from .types import ValueType
|
||||||
|
from .constants import CONSTANTS
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
@ -64,7 +63,8 @@ class Parser:
|
|||||||
|
|
||||||
self.__debug_expr = repr(self.val_stack)
|
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)
|
return self._evaluator(variables)
|
||||||
|
|
||||||
def do_one(self):
|
def do_one(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user