i hate python

This commit is contained in:
Michael Zhang 2021-10-01 12:50:41 -05:00
parent ceaa9de8c5
commit b636e86c56
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
10 changed files with 18 additions and 53 deletions

View file

@ -1,5 +0,0 @@
import sys
import agtest.driver
if __name__ == "__main__":
agtest.driver.run(sys.argv[1])

41
old.py
View file

@ -1,41 +0,0 @@
from typing import Generic, TypeVar, Optional, Callable
T = TypeVar("T")
class Thunk(Generic[T]):
value: Optional[T]
def __init__(self, func: Callable[[], T]):
self.func = func
self.value = None
def get(self) -> T:
if self.value is None:
self.value = self.func()
return self.value
class Node:
value: Thunk[int]
class Add(Node):
def __init__(self, left: Node, right: Node):
self.value = Thunk(lambda: left.value.get() + right.value.get())
class Mul(Node):
def __init__(self, left: Node, right: Node):
self.value = Thunk(lambda: left.value.get() * right.value.get())
class Lit(Node):
def __init__(self, num: int):
self.num = num
self.value = Thunk(lambda: num)
if __name__ == "__main__":
tree = Add(Mul(Lit(3), Lit(4)), Lit(5))
print(tree.value.get())

15
setup.cfg Normal file
View file

@ -0,0 +1,15 @@
[metadata]
name = click
[options.entry_points]
console_scripts =
agt = agtest.driver:run
[options]
packages = find:
package_dir = = src
include_package_data = true
python_requires = >= 3.6
[options.packages.find]
where = src

View file

@ -3,10 +3,4 @@ from setuptools import setup
setup(
name="agtest",
version="0.1.0",
packages=["agtest"],
entry_points={
'console_scripts': [
'agt = agtest.driver.run',
],
},
)

View file

@ -8,7 +8,9 @@ from pathlib import Path
from agtest.ast import Parser
from agtest.gen import GenResult
grammar = path.join(path.dirname(path.realpath(__file__)), "grammar.lark")
src_dir = path.dirname(path.realpath(__file__))
print("SOURCE", src_dir)
grammar = path.join(src_dir, "grammar.lark")
p = lark.Lark(open(grammar).read(), start="program", parser="lalr")
def run(path: Path):