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
if and while working
  • Loading branch information
lucafs committed May 11, 2021
commit d2ef31d6654dc48d25a2c834c8a4506e09d8f236
28 changes: 12 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def selectNext(self):
while(tToken_finder(self.origin[self.position]) == "IDENT" or tToken_finder(self.origin[self.position]) == "NUM"):
self.actual.value += self.origin[self.position]
self.position += 1
if(self.actual.value == "else"):
break
if(self.position == len(self.origin)):
break

Expand Down Expand Up @@ -377,10 +379,6 @@ def parseBlock():
Parser.tokens.selectNext()
while(Parser.tokens.actual.type != "CLS_COM"):
commands.children.append(Parser.parseCommand())
if(Parser.tokens.actual.type != "ENDCOM"):
print(Parser.tokens.actual.type)
raise Exception("; not found")
Parser.tokens.selectNext()
if(Parser.tokens.actual.type == "CLS_COM"):
Parser.tokens.selectNext()
else:
Expand All @@ -405,8 +403,8 @@ def parseCommand():
assign.children.append(value)
if Parser.tokens.actual.type != "ENDCOM":
raise Exception("; NOT FOUND")
Parser.tokens.selectNext()
else:
print(Parser.tokens.actual.value)
raise Exception("COMMAND ERROR")

return assign
Expand All @@ -418,6 +416,7 @@ def parseCommand():
print_node.children.append(print_value)
if Parser.tokens.actual.type != "ENDCOM":
raise Exception("; NOT FOUND")
Parser.tokens.selectNext()
return print_node

elif Parser.tokens.actual.type == "WHILE":
Expand All @@ -428,10 +427,7 @@ def parseCommand():
while_node.children.append(Parser.parseOrexPR())
if Parser.tokens.actual.type == 'CLS':
Parser.tokens.selectNext()
if Parser.tokens.actual.type == 'ENDCOM':
while_node = NoOp()
else:
while_node.children.append(Parser.parseCommand())
while_node.children.append(Parser.parseCommand())
else:
raise Exception("WHILE ERROR")
else:
Expand All @@ -445,19 +441,19 @@ def parseCommand():
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_node.children.append(Parser.parseCommand())
if Parser.tokens.actual.type == "ELSE":
print("salve")
Parser.tokens.selectNext()
if_node.children.append(Parser.parseCommand())
else:
raise Exception("IF ERROR")
else:
raise Exception("IF ERROR")

return if_node
elif Parser.tokens.actual.type == "ENDCOM":
return NoOp()
else:
pass
Parser.parseBlock()


@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions teste.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{x1 = 3; /* bla bla $x1 = 9999998 */
while(x1 < 6)
x1 = x1 + 2;
while(x1 < 100000)
x1 = x1 + 65;
println(x1);}