aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/psi/interpreter.py
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-09-27 22:10:55 +0800
committer简律纯 <i@jyunko.cn>2023-09-27 22:10:55 +0800
commit767459d17e031e96d09e533a2a53df896b3a57e1 (patch)
treef7ed6952d85be703511f95e17c13824e0ffc33e8 /src/psi/interpreter.py
parentba4129933cdb6d91e695b2de900b8753652ec385 (diff)
downloadTRPGNivis-767459d17e031e96d09e533a2a53df896b3a57e1.tar.gz
TRPGNivis-767459d17e031e96d09e533a2a53df896b3a57e1.zip
feat(docstring): 添加PEP8规范的Docstring
Diffstat (limited to 'src/psi/interpreter.py')
-rw-r--r--src/psi/interpreter.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/psi/interpreter.py b/src/psi/interpreter.py
index f98a777..8aa8fad 100644
--- a/src/psi/interpreter.py
+++ b/src/psi/interpreter.py
@@ -4,13 +4,53 @@ 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):
@@ -20,6 +60,15 @@ class Interpreter:
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])