Skip to content

Commit

Permalink
added equation support &more bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RezSat committed May 12, 2024
1 parent f431f53 commit c8fd75a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .function_definition import FunctionDefinition
from .function_call import FunctionCall
from .assignment import VariableAssignment
from .equation import Equation

__all__ = [
'Node',
Expand All @@ -23,4 +24,5 @@
'FunctionDefinition',
'FunctionCall',
'VariableAssignment',
'Equation'
]
15 changes: 15 additions & 0 deletions src/nodes/equation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .node import Node

class Equation(Node):
def __init__(self, left, right):
self.left = left
self.right = right

def __repr__(self):
return str(
{ "Equation": {
"Left": self.left,
"Right": self.right
}
}
)
7 changes: 5 additions & 2 deletions src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
TODO:
parenthesis means multiplication ( well sometimes )
statement separation
variable assignments
equation
inequality
Expand All @@ -27,7 +26,11 @@ def advance(self):
self.current_token = None

def parse(self):
node = self.parse_expression()
node = self.parse_expression()
# fix errors like let x = 4x = 6 -> {'Equation': {'Left': {'Variable': 'x', 'Value': {'BinaryOperation': '*', 'Left': {'Number': '4'}, 'Right': {'Symbol': 'x'}}}, 'Right': None}}
if self.current_token != None and self.current_token.value == "=":
right = self.parse_expression()
return Equation(node, right)
return node

def parse_expression(self):
Expand Down

0 comments on commit c8fd75a

Please sign in to comment.