Files
pebble/main.py

42 lines
1017 B
Python

from src.ast.expr import Expr, BinaryExpr, UnaryExpr, LiteralExpr, GroupingExpr
from src.ast.printer import AstPrinter
from src.lexer import Lexer
from src.parser.parser import Parser
from src.token import Token, TokenType
def main():
source: str = """() {} +- += / /= // sefs + {, )
}:: *
"This is a string"
3.1415
123
"This is
another string" """
path: str = "examples/07_math.peb"
with open(path, "r") as f:
source = f.read()
lexer: Lexer = Lexer()
tokens: list[Token] = lexer.process(source, path)
print(tokens)
printer: AstPrinter = AstPrinter()
ast: Expr = BinaryExpr(
UnaryExpr(
Token(TokenType.MINUS, "-", None, None),
LiteralExpr(123)
),
Token(TokenType.STAR, "*", None, None),
GroupingExpr(LiteralExpr(45.67))
)
print(printer.print(ast))
parser: Parser = Parser()
ast = parser.process(tokens)
print(printer.print(ast))
if __name__ == '__main__':
main()