-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoelang.py
40 lines (30 loc) · 1.01 KB
/
joelang.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
from joe_compiler.joe_compiler_repo.utils.strings_with_arrows import *
import string
import os
import math
from joe_compiler.joe_compiler_repo.component.lexer import Lexer
from joe_compiler.joe_compiler_repo.component.interpreter import Interpreter
from joe_compiler.joe_compiler_repo.component.parser import Parser
from joe_compiler.joe_compiler_repo.context import Context
#######################################
# CONSTANTS
#######################################
DIGITS = '0123456789'
LETTERS = string.ascii_letters
LETTERS_DIGITS = LETTERS + DIGITS
def run(fn, text):
# Generate tokens
lexer = Lexer(fn, text)
tokens, error = lexer.make_tokens()
if error: return None, error
# Generate AST
parser = Parser(tokens)
ast = parser.parse()
if ast.error: return None, ast.error
# Run program
interpreter = Interpreter()
context = Context('<program>')
context.symbol_table = global_symbol_table
result = interpreter.visit(ast.node, context)
return result.value, result.error