From 2052e9a084b305bb75d595a00f8b7d73dc1f8efa Mon Sep 17 00:00:00 2001 From: weckyy702 Date: Mon, 28 Dec 2020 01:02:54 +0100 Subject: [PATCH] started implementing variable support for interpreter --- interpreter/interpret_source.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/interpreter/interpret_source.py b/interpreter/interpret_source.py index 0cb714a..472ca5a 100644 --- a/interpreter/interpret_source.py +++ b/interpreter/interpret_source.py @@ -8,13 +8,20 @@ from draw.Iinstruction import * COMMENT_PATTERN = re.compile(r"""^//|^/\*\*|^\*|^--""") REMOVE_KEYWORDS = [' ', "public", "private", ';'] -FUNCTION_IDENTIFIERS = ["void", "boolean", "int", "float"] +VARIABLE_TAGS = ["byte", "short", "int", "long", "float", "double", "boolean", "char", "String"] +FUNCTION_IDENTIFIERS = ["void"] +FUNCTION_IDENTIFIERS.extend(VARIABLE_TAGS) WHILE_TAG = "solange " #german for 'while'. Change this depending on your language REPLACE = dict((re.escape(k), '') for k in REMOVE_KEYWORDS) remove_pattern = re.compile("|".join(REPLACE.keys())) +variable_regex = "^(" +for kw in FUNCTION_IDENTIFIERS: + variable_regex += fr"""{kw}|""" +variable_pattern = re.compile(variable_regex[0:-1]+"$(.*)") + function_regex = "^(" for kw in FUNCTION_IDENTIFIERS: function_regex += fr"""{kw}|"""