Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 46 lines (37 sloc) 1.34 KB
#!/usr/bin/python
# -*- coding: latin1 -*-
import argparse
from triestin import Tokenizer, Parser, Generator, State
def triestin(**kwargs):
tokens = Tokenizer(**kwargs).tokenize()
# for i in tokens:
# print(i)
tree = Parser(tokens).parse()
# print(tree)
return Generator().generate(tree)
# print(triestin(filename='trst.src'))
if __name__=="__main__":
print("Triestin v0.0.1")
print("ctrl+C per uscire")
local_state = State()
while True:
try:
# Python 2 on CLI
user_input = raw_input('triestin> ')
output = triestin(source_code=user_input)
local_state.add_history(output)
if output['state'] == 'exec':
exec(output['code'])
if output['state'] == 'eval':
if type(eval(output['code'])) == tuple:
print(eval(output['code'])[0])
else:
print(eval(output['code']))
if output['state'] == 'anzi':
if local_state.history[-2]['node'] == 'AssignNode':
prev_node = local_state.history[-2]
prev_var = prev_node['code'].split('=')[0].strip()
new_code = '{} = {}'.format(prev_var, output['code'])
exec(new_code)
except Exception as e:
print(e)