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