-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bac5e9
commit 4b4eb0c
Showing
7 changed files
with
85 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
from functions import * | ||
from typing import Callable | ||
|
||
|
||
class Element: | ||
def __init__(self, *, arity: int, func: Callable): | ||
self.arity = arity | ||
self.func = func | ||
|
||
def __call__(self, *args, **kwargs): | ||
return self.func(*args, **kwargs) | ||
|
||
|
||
elements = { | ||
"+": [2, Add], | ||
"-": [2, Sub], | ||
"×": [2, Mul], | ||
"÷": [2, TrueDiv], | ||
"ⁱ": [2, Power], | ||
"g": [0, lambda *x: g], # g (and other constants) must be a lambda because the interpreter tries to call it | ||
"¶": [1, Print] | ||
"+": Element(arity=2, func=Add), | ||
"-": Element(arity=2, func=Sub), | ||
"×": Element(arity=2, func=Mul), | ||
"÷": Element(arity=2, func=TrueDiv), | ||
"ⁱ": Element(arity=2, func=Power), | ||
"g": Element(arity=0, func=lambda *x: g), | ||
# g (and other constants) must be a lambda because the interpreter tries to call it | ||
"¶": Element(arity=1, func=Print) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
class Structure: | ||
def __repr__(self): | ||
return "Structure()" | ||
from tokenizer import Token # Used as a annotation | ||
|
||
|
||
class ForLoop: | ||
""" | ||
For loop structure class. | ||
Syntax: | ||
def parse(self, token_list): | ||
return token_list | ||
↹number{body} | ||
(Borrowed from SYNTAX.md) | ||
""" | ||
|
||
def __init__(self, number: Token, body: Token): | ||
self.number = number | ||
self.body = body | ||
|
||
def __repr__(self): | ||
return f"ForLoop(number={self.number}, body={self.body})" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters