prepared interpreter fix

This commit is contained in:
weckyy702
2021-01-24 21:42:39 +01:00
parent 5e024f07f5
commit db3472f5ba
4 changed files with 375 additions and 328 deletions

View File

@@ -0,0 +1,25 @@
from typing import Iterable, List
from draw.Iinstruction import Iinstruction
class Function_scope(Iterable):
def __init__(self, child_instructions: List[Iinstruction], name: str, return_type: str, args: List[str]) -> None:
self.contents = child_instructions
self.name = name
self.return_type = return_type
self.args = args
def get_height(self) -> int:
h = 0.0
for inst in self.contents:
h += inst.getblkheight()
return int(h)
def get_width(self) -> int:
w = 200.0
for inst in self.contents:
w = max(w, inst.getblkwidth())
return int(w)
def __iter__(self):
return self.contents.__iter__()

View File

@@ -1,9 +1,10 @@
import logging
import re
from typing import Dict, List, Match, Tuple, Union
from typing import Dict, List, Match, Tuple, Union, Iterable
from errors.custom import InterpreterException, JavaSyntaxError, ScopeNotFoundException
from draw.Iinstruction import *
from interpreter.function_scope import *
logging.warning("""Because the Interpreter is still WIP, some Java language features are not supported. These include:
*foreach loops (will throw JavaSyntaxError)
@@ -12,28 +13,6 @@ logging.warning("""Because the Interpreter is still WIP, some Java language feat
*Generics
Please remove these features from the source code as they will result in incorrect behaviour""")
class Function_scope(Iterable):
def __init__(self, child_instructions: List[Iinstruction], name: str, return_type: str, args: List[str]) -> None:
self.contents = child_instructions
self.name = name
self.return_type = return_type
self.args = args
def get_height(self) -> int:
h = 0.0
for inst in self.contents:
h += inst.getblkheight()
return int(h)
def get_width(self) -> int:
w = 200.0
for inst in self.contents:
w = max(w, inst.getblkwidth())
return int(w)
def __iter__(self):
return self.contents.__iter__()
class JavaInterpreter:
def __init__(self, filepath: str) -> None:
@@ -212,7 +191,6 @@ class JavaInterpreter:
instructions.append(for_instruction("while " + cond, child_instructions))
return instructions, idx
except IndexError:
raise JavaSyntaxError("Ill-formed for loop construct!")
except: