🐐 Fractions
This commit is contained in:
21
cent
21
cent
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user