Files
plthy/plthy
2024-02-19 11:21:07 +01:00

42 lines
994 B
Python
Executable File

#! /home/nikolaj/.pyenv/shims/python
"""
Usage:
plthy (-h| --help)
plthy (-i| -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 plthy_impl.lexer import Lexer
from plthy_impl.parser import Parser
from plthy_impl.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):
if args["-i"]:
program.eval()
else:
raise Exception("Compiler not implemented")
else:
raise Exception("Output not of type 'Program'", type(program))
if __name__ == "__main__":
main()