🐐 Fractions

This commit is contained in:
2026-04-01 14:45:48 +02:00
parent 2f138093e3
commit bd27857472
8 changed files with 378 additions and 67 deletions

21
cent
View File

@@ -10,8 +10,12 @@ Options:
-c Run the compiler
FILE The file to compile/interpret
"""
from docopt import docopt
import sys
from docopt import docopt
from rply.errors import LexingError
from centvrion.errors import CentvrionError
from centvrion.lexer import Lexer
from centvrion.parser import Parser
from centvrion.ast_nodes import Program
@@ -25,13 +29,20 @@ def main():
lexer = Lexer().get_lexer()
parser = Parser()
tokens = lexer.lex(program_text)
program = parser.parse(tokens)
try:
tokens = lexer.lex(program_text)
program = parser.parse(tokens)
except LexingError as e:
pos = e.source_pos
char = program_text[pos.idx] if pos.idx < len(program_text) else "?"
sys.exit(f"CENTVRION error: Invalid character {char!r} at line {pos.lineno}, column {pos.colno}")
if isinstance(program, Program):
if args["-i"]:
program.eval()
try:
program.eval()
except CentvrionError as e:
sys.exit(f"CENTVRION error: {e}")
else:
raise Exception("Compiler not implemented")
else: