diff options
| author | 2024-02-24 12:48:55 +0800 | |
|---|---|---|
| committer | 2024-02-24 12:48:55 +0800 | |
| commit | ae345a2f193a4d6022edda76523a39f6e891843e (patch) | |
| tree | fbe13a483db44dbb4ac222f1cd29583edda9341f /psi/interpreter.py | |
| parent | 9b916be9c8db9eedabde0331aef0cc53b5918b34 (diff) | |
| download | TRPGNivis-ae345a2f193a4d6022edda76523a39f6e891843e.tar.gz TRPGNivis-ae345a2f193a4d6022edda76523a39f6e891843e.zip | |
refactor!: rewrite python package
Diffstat (limited to 'psi/interpreter.py')
| -rw-r--r-- | psi/interpreter.py | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/psi/interpreter.py b/psi/interpreter.py deleted file mode 100644 index 8aa8fad..0000000 --- a/psi/interpreter.py +++ /dev/null @@ -1,75 +0,0 @@ -from psi.lexer import Token - - -__all__ = ['Interpreter'] - -class Interpreter: - """ - A class representing an interpreter for Psi code. - - Args: - ast: The abstract syntax tree (AST) of the code to be interpreted. - - Returns: - None - - Example: - ```python - interpreter = Interpreter(ast) - interpreter.interpret() - ``` - """ - - def __init__(self, ast): - """ - Initializes an Interpreter object. - - Args: - ast: The abstract syntax tree (AST) of the code to be interpreted. - - Returns: - None - """ - self.ast = ast - - def interpret(self): - """ - Interprets the code represented by the AST. - - Returns: - The result of the interpretation. - """ - return self.interpret_expr(self.ast) - - def interpret_expr(self, node): - """ - Interprets an expression node in the AST. - - Args: - node: The expression node to be interpreted. - - Returns: - The result of the interpretation. - """ - if isinstance(node, Token): - return node.value - elif isinstance(node, list): - for expr in node: - result = self.interpret_expr(expr) - if result is not None: - return result - - def interpret_condition(self, node): - """ - Interprets a condition node in the AST. - - Args: - node: The condition node to be interpreted. - - Returns: - The result of the interpretation. - """ - variable = self.interpret_expr(node[0]) - value = self.interpret_expr(node[2]) - - return variable == value |
