2025-10-13 06:55:35 +11:00
|
|
|
from lexer import Lexer
|
2025-10-13 17:41:07 +11:00
|
|
|
from plasma_parser import Parser
|
|
|
|
|
from AST import Program
|
|
|
|
|
import json
|
2025-10-13 06:55:35 +11:00
|
|
|
|
|
|
|
|
LEXER_DEBUG: bool = True
|
2025-10-13 17:41:07 +11:00
|
|
|
PARSER_DEBUG: bool = True
|
2025-10-13 06:55:35 +11:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-10-13 07:07:32 +11:00
|
|
|
with open("tests/parser.pla") as f:
|
2025-10-13 06:55:35 +11:00
|
|
|
code: str = f.read()
|
|
|
|
|
|
|
|
|
|
if LEXER_DEBUG:
|
|
|
|
|
debug_lex: Lexer = Lexer(source=code)
|
|
|
|
|
while debug_lex.current_char is not None:
|
2025-10-13 17:41:07 +11:00
|
|
|
print(debug_lex.next_token())
|
|
|
|
|
|
|
|
|
|
l: Lexer = Lexer(source=code)
|
|
|
|
|
p: Parser = Parser(lexer=l)
|
|
|
|
|
|
|
|
|
|
if PARSER_DEBUG:
|
|
|
|
|
print("===== PARSER DEBUG =====")
|
|
|
|
|
program: Program = p.parse_program()
|
|
|
|
|
|
|
|
|
|
with open("debug/ast.json", "w") as f:
|
|
|
|
|
json.dump(program.json(), f, indent=4)
|
|
|
|
|
|
|
|
|
|
print("Wrote AST to debug/ast.json successfully.")
|