This commit is contained in:
NikolajDanger
2022-06-14 08:59:38 +02:00
parent f2a15dd586
commit ba8451638d
5 changed files with 182 additions and 80 deletions

39
cent Executable file
View File

@@ -0,0 +1,39 @@
#! /home/nikolaj/.pyenv/shims/python
"""
Usage:
cent (-h|--help)
cent -i FILE
cent -c FILE
Options:
-h --help Print this help screen
-i Run the interpreter
-c Run the compiler
FILE The file to compile/interpret
"""
from docopt import docopt
from centvrion.lexer import Lexer
from centvrion.parser import Parser
from centvrion.ast_nodes import Program
def main():
args = docopt(__doc__)
file_path = args["FILE"]
with open(file_path, "r", encoding="utf-8") as file_pointer:
program_text = file_pointer.read() + "\n"
lexer = Lexer().get_lexer()
parser = Parser()
tokens = lexer.lex(program_text)
program = parser.parse(tokens)
if isinstance(program, Program):
program.eval()
else:
raise Exception("Output not of type 'Program'", type(program))
if __name__ == "__main__":
main()