✨
This commit is contained in:
0
centvrion/__init__.py
Normal file
0
centvrion/__init__.py
Normal file
@@ -1,7 +1,7 @@
|
||||
import random
|
||||
import roman
|
||||
|
||||
from rply.token import BaseBox
|
||||
from rply.token import BaseBox as BB
|
||||
|
||||
NUMERALS = [
|
||||
("I", 1),
|
||||
@@ -37,6 +37,10 @@ def make_string(n):
|
||||
else:
|
||||
raise Exception(n)
|
||||
|
||||
class BaseBox(BB):
|
||||
def eval(self, vtable, ftable, modules):
|
||||
return None
|
||||
|
||||
class ExpressionStatement(BaseBox):
|
||||
def __init__(self, expression) -> None:
|
||||
self.expression = expression
|
||||
@@ -373,7 +377,7 @@ class Program(BaseBox):
|
||||
statements_string = f"statements([{rep_join(self.statements)}])"
|
||||
return f"{modules_string},\n{statements_string}"
|
||||
|
||||
def eval(self):
|
||||
def eval(self, *_):
|
||||
vtable = {"ERVMPE": False}
|
||||
ftable = {}
|
||||
modules = [module.module_name for module in self.modules]
|
||||
@@ -1,8 +1,7 @@
|
||||
from multiprocessing.dummy import Array
|
||||
from rply import ParserGenerator
|
||||
|
||||
from lexer import all_tokens
|
||||
import ast_nodes
|
||||
from centvrion.lexer import all_tokens
|
||||
from . import ast_nodes
|
||||
|
||||
ALL_TOKENS = list(set([i[0] for i in all_tokens]))
|
||||
|
||||
@@ -17,7 +16,7 @@ class Parser():
|
||||
]
|
||||
)
|
||||
|
||||
def parse(self):
|
||||
def parse(self, tokens_input) -> ast_nodes.BaseBox:
|
||||
@self.pg.production('program : opt_newline module_calls statements')
|
||||
def program(tokens):
|
||||
return ast_nodes.Program(tokens[-2], tokens[-1])
|
||||
@@ -181,6 +180,5 @@ class Parser():
|
||||
def error_handle(token):
|
||||
raise ValueError(token)
|
||||
|
||||
|
||||
def get_parser(self):
|
||||
return self.pg.build()
|
||||
parser = self.pg.build()
|
||||
return parser.parse(tokens_input)
|
||||
12
main.py
12
main.py
@@ -1,5 +1,5 @@
|
||||
from lexer import Lexer
|
||||
from parser import Parser
|
||||
from centvrion.lexer import Lexer
|
||||
from centvrion.parser import Parser
|
||||
|
||||
text_input = """
|
||||
VOCA FORS
|
||||
@@ -22,14 +22,12 @@ DICE "You guessed correctly!"
|
||||
"""
|
||||
|
||||
lexer = Lexer().get_lexer()
|
||||
pg = Parser()
|
||||
pg.parse()
|
||||
parser = pg.get_parser()
|
||||
parser = Parser()
|
||||
|
||||
tokens = lexer.lex(text_input)
|
||||
#for token in tokens:
|
||||
# print(token)
|
||||
|
||||
x = parser.parse(tokens)
|
||||
program = parser.parse(tokens)
|
||||
#print(x)
|
||||
x.eval()
|
||||
program.eval()
|
||||
|
||||
Reference in New Issue
Block a user