From d393fab31f442aeca57b5390a61bb73c87ec719c Mon Sep 17 00:00:00 2001 From: songWukong Date: Sun, 19 Nov 2017 08:26:21 +0200 Subject: [PATCH 1/4] test --- src/source.bas | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/source.bas b/src/source.bas index ea4bbba..78dcbaa 100644 --- a/src/source.bas +++ b/src/source.bas @@ -4,5 +4,4 @@ PRINT 2 PRINT 123 PRINT "3*2+2*(5-6)-234 =" PRINT 3*2+2*(5-6)-234 -PRINT "23-698*(4*(63-25*69)-56) =" -PRINT 23-698*(4*(63-25*69)-56) \ No newline at end of file + From 519b0c75cb5f3e0c7704f1938386daec99f01a66 Mon Sep 17 00:00:00 2001 From: songWukong Date: Sun, 19 Nov 2017 08:32:58 +0200 Subject: [PATCH 2/4] test --- src/source.bas | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/source.bas b/src/source.bas index d334f02..fe7ef1d 100644 --- a/src/source.bas +++ b/src/source.bas @@ -3,11 +3,4 @@ PRINT "Hi" PRINT 2 PRINT 123 PRINT 111 -PRINT "3*2+2*(5-6)-234 =" -PRINT 3*2+2*(5-6)-234 -<<<<<<< HEAD -======= -PRINT "23-698*(4*(63-25*69)-56) =" -PRINT 23-698*(4*(63-25*69)-56) ->>>>>>> ef933419b5179f25ea77e6320dd1f77674ace507 From f74b942631ddb664cd1b9e2f906481fed891ebe9 Mon Sep 17 00:00:00 2001 From: songWukong Date: Sun, 19 Nov 2017 08:38:29 +0200 Subject: [PATCH 3/4] test --- src/source.bas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source.bas b/src/source.bas index fe7ef1d..350008e 100644 --- a/src/source.bas +++ b/src/source.bas @@ -3,4 +3,4 @@ PRINT "Hi" PRINT 2 PRINT 123 PRINT 111 - +PRINT 2*(23+23) From 0553760b118bd0292ad46b3fed534acc19fa0eaa Mon Sep 17 00:00:00 2001 From: songWukong Date: Sun, 19 Nov 2017 20:13:02 +0200 Subject: [PATCH 4/4] assign variables added --- src/interpreter.py | 45 ++++++++++++++++++++++++++++++++++++++++----- src/source.bas | 9 +++------ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/interpreter.py b/src/interpreter.py index 6aac0fa..b827153 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -1,8 +1,11 @@ from calc import * class Interpreter: + + __variables = {} def __init__(self, calc): + self.calc = calc def run(self): @@ -43,7 +46,11 @@ def __tokenize_Statement__(self, code): if (token == "PRINT"): del code[0] - self.__parse_Print__(code) + self.__parse_Print__(code) + + elif (token == "LET"): + del code[0] + self.__parse_Let__(code) return 1 @@ -68,8 +75,8 @@ def __parse_String__(self, code): del code[0] i += 1 - return string; - + return string; + def __parse_Print__(self, code): @@ -80,9 +87,37 @@ def __parse_Print__(self, code): elif (code[0].isdigit()): num = self.calc.parse_Formula(code) - print num + print num + + + def __parse_Let__(self, code): + + varName = "" + varVal = "" + + while (code[0] != "="): + varName += code[0] + del code[0] + + if (code[0] == "="): + del code[0] + + try: + while (code[0] != "\n"): + + if (code[0].isdigit()): + varVal += code[0] + del code[0] + + except (IndexError): + self.__variables[varName] = int(varVal) + print self.__variables + return + + self.__variables[varName] = int(varVal) + print self.__variables calc = Calc() interpreter = Interpreter(calc) -interpreter.run() +interpreter.run() \ No newline at end of file diff --git a/src/source.bas b/src/source.bas index 350008e..35c0cc4 100644 --- a/src/source.bas +++ b/src/source.bas @@ -1,6 +1,3 @@ -PRINT "Hello, world" -PRINT "Hi" -PRINT 2 -PRINT 123 -PRINT 111 -PRINT 2*(23+23) +LET a=10 +LET b=2 +LET c=4 \ No newline at end of file