diff --git a/LineNodes.py b/LineNodes.py index 30058be18c264c95e1c898912f5d4f41fbe3b677..ca2938496d64d4a8cb1271a7b51a6b82f161bbd1 100644 --- a/LineNodes.py +++ b/LineNodes.py @@ -31,7 +31,7 @@ def makeNodeFromAllStatement(parseTree, typeName): return WhileNode(child, typeName) elif child.name == 'variableDcl': - return VarDclNode(child, typeName) + return VarDclNode(child, typeName, True) # Creates AST node from statementExpr @@ -94,7 +94,7 @@ class BlockNode(ASTNode): # 1. variableDcl type ID # 2. variableDcl type ID ASSIGN variableInit class VarDclNode(ASTNode): - def __init__(self, parseTree, typeName): + def __init__(self, parseTree, typeName, checkAssign=False): self.parseTree = parseTree self.dclType = None self.name = None # variable name @@ -110,6 +110,11 @@ class VarDclNode(ASTNode): # Handling rule: variableInit expr self.variableInit = makeNodeFromExpr(parseTree.children[3].children[0], typeName) + # Checking for definite assignment + if checkAssign: + if not self.variableInit: + raise Exception("ERROR: local variable declaration not assigned") + self.myType = self.dclType.myType self.children.append(self.dclType) self.children.append(self.variableInit) diff --git a/Test.py b/Test.py index a08be2a913508ac004e0297f812f77447c24e606..e0dcfd6c2655a0b4a8ca3a8ecb6cb457c0b55649 100644 --- a/Test.py +++ b/Test.py @@ -137,8 +137,10 @@ def run(testFiles): # if n == "Tests/A3/J1_accessstaticfield/Main.java": # print(n) # print(t) - - ASTs = astBuild(parseTrees) + try: + ASTs = astBuild(parseTrees) + except Exception as e: + return "AST buidling: " + e.args[0] # for (n, t) in ASTs: # print(n) diff --git a/joosc.py b/joosc.py index 6e1c9699e9473357eae12845c5e156f6943cc4f6..fad79f13709bbcc4b045048c1b65d1256848ccee 100644 --- a/joosc.py +++ b/joosc.py @@ -45,7 +45,10 @@ def main(): parseTrees.append((f, tree)) # Building ASTs from all parse trees - ASTs = astBuild(parseTrees) + try: + ASTs = astBuild(parseTrees) + except Exception as e: # for definite assignemnt + return 42 try: buildEnvAndLink(ASTs)