Skip to content
Merged

V2.3 #24

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
final 2.3
  • Loading branch information
lucafs committed May 16, 2021
commit 3800f32a2a3a2c7506da491e2304c20d0193b2be
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def getter(self, name):
try:
return self.sym[name]
except:
raise Exception("Symbol "+name+ " not declared")
return "error"


class Node():
Expand Down Expand Up @@ -126,16 +126,20 @@ def Evaluate(self,ST):
class FirstAssign(Node):
def Evaluate(self, ST):
type = self.children[0]
name = self.children[1]
name = self.children[1]
if(ST.getter(name) != "error"):
raise Exception ("Variable " + name + " aready declared")
ST.setter(name, None ,type)

class Assign(Node):
def Evaluate(self, ST):
name = self.children[0].value
expression = self.children[1].Evaluate(ST)
type = ST.getter(name)[1]
if(type == "error"):
raise Exception ("Symbol "+name+ " not declared")
if(expression[1] != type ):
raise Exception("Can't cast this variable")
raise Exception("Can't cast the "+ name +" variable")
ST.setter(name, expression[0],type)

class Identifier(Node):
Expand Down