Skip to content
Merged

V2.2 #21

Show file tree
Hide file tree
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
Next Next commit
while working
  • Loading branch information
lucafs committed May 11, 2021
commit 11dbdb17fbd5d401fb10e1f27fed90b05bdd5594
27 changes: 23 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def Evaluate(self, st):


class IfOp(Node):

def Evaluate(self, st):
if (self.children[0].Evaluate(st)):
self.children[1].Evaluate(st)
Expand Down Expand Up @@ -229,6 +228,8 @@ def selectNext(self):
self.actual.type = "READ"
elif(self.actual.value == "if"):
self.actual.type = "IF"
elif(self.actual.value == "else"):
self.actual.type = "ELSE"
elif(self.actual.value == "while"):
self.actual.type = "WHILE"
return self.actual
Expand Down Expand Up @@ -424,19 +425,37 @@ def parseCommand():
Parser.tokens.selectNext()

if Parser.tokens.actual.type == 'OPN':
Parser.tokens.selectNext()
while_node.children.append(Parser.parseOrexPR())
if Parser.tokens.actual.type == 'CLS':
Parser.tokens.selectNext()
while_node.children.append(Parser.parseCommand())
if Parser.tokens.actual.type == 'ENDCOM':
while_node = NoOp()
else:
while_node.children.append(Parser.parseCommand())
else:
raise Exception("WHILE ERROR")
else:
raise Exception("WHILE ERROR")
return while_node

elif Parser.tokens.actual.type == "IF":
pass
if_node = IfOp("if",[])
Parser.tokens.selectNext()
if Parser.tokens.actual.type == 'OPN':
if_node.children.append(Parser.parseOrexPR())
if Parser.tokens.actual.type == 'CLS':
Parser.tokens.selectNext()
if Parser.tokens.actual.type == 'ENDCOM':
if_node.children.append(NoOp())
else:
if_node.children.append(Parser.parseCommand())
if Parser.tokens.actual.type == "ELSE":
print("salve")
else:
raise Exception("IF ERROR")
else:
raise Exception("IF ERROR")

else:
pass

Expand Down
12 changes: 3 additions & 9 deletions teste.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{x1 = 3; /* bla bla $x1 = 9999998 */
y2 = 4;
x = 1 + 2;
z_final = x1 + y2 *33;
x = 2;
while (x && 4){
println(x);
x = x+1;}

println(2);}
while(x1 < 6)
x1 = x1 + 2;
println(x1);}