Skip to content

Commit

Permalink
added print
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSecondComing123 committed Feb 15, 2022
1 parent a002994 commit 7bbbfcd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codepage.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
codepage = ["+", "-", "×", "÷", "g"]
codepage = ["+", "-", "×", "÷", "g", "¶"]
11 changes: 6 additions & 5 deletions elements.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from functions import *

elements = {
"+": [2, add],
"-": [2, sub],
"×": [2, mul],
"÷": [2, div],
"g": [0, g]
"+": [2, Add],
"-": [2, Sub],
"×": [2, Mul],
"÷": [2, TrueDiv],
"g": [0, g],
"¶": [1, Print]
}
13 changes: 9 additions & 4 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,26 @@
p8 = 128


def add(a1, a2):
def Add(a1, a2):
"""Add two numbers"""
return Token(TokenType.NUMBER, a1.value + a2.value)


def sub(a1, a2):
def Sub(a1, a2):
"""Subtract two numbers"""
return Token(TokenType.NUMBER, a1.value - a2.value)


def mul(a1, a2):
def Mul(a1, a2):
"""Multiplies too numbers"""
return Token(TokenType.NUMBER, a1.value * a2.value)


def div(a1, a2):
def TrueDiv(a1, a2):
"""Divides two numbers"""
return Token(TokenType.NUMBER, a1.value / a2.value)


def Print(a1):
"""Prints something"""
print(a1)
1 change: 1 addition & 0 deletions interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ def interprete(tokens: list[Token]) -> Union[TokenList, None]:
print(interprete(parse(tokenize("-2 1"))))
print(interprete(parse(tokenize("×7 2"))))
print(interprete(parse(tokenize("÷10 2"))))
interprete(parse(tokenize("¶+1 ×3 3")))

0 comments on commit 7bbbfcd

Please sign in to comment.