Skip to content

Commit

Permalink
HotFix - alter if-elif-else operation
Browse files Browse the repository at this point in the history
  • Loading branch information
VFermat committed Jun 4, 2021
1 parent b339acd commit 5864928
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
32 changes: 11 additions & 21 deletions compiler/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,12 @@ def conditional(self, p):
elif values[-1].type == 'elses':
root = IfOp(values[0], p.or_expr, p.block)
elses = p.elses
root.setElse(elses[2])
root.setElse(elses)
return root
elif values[-1].type == 'elseif':
root = IfOp(values[0], p.or_expr, p.block)
elifs = p.elseif
if elifs[0] == 'else':
root.setElse(elifs[2])
return root
else:
root.addElif(elifs[1], elifs[2])
if len(elifs[3]) > 0:
while True:
if elifs[0] == 'else':
root.setElse(elifs[2])
return root
else:
root.addElif(elifs[1], elifs[2])
if len(elifs) > 3:
elifs = elifs[3]
else:
break
root.setElse(elifs)
return root

@_(
Expand All @@ -140,16 +125,21 @@ def conditional(self, p):
)
def elseif(self, p):
values = p._slice
root = IfOp(values[0], p.or_expr, p.block)
if values[-1].type == 'EOL':
return ['elif', p.or_expr, p.block, []]
return root
elif values[-1].type == 'elseif':
return ['elif', p.or_expr, p.block, p.elifs]
elif_ = p.elifs
root.setElse(elif_)
return root
elif values[-1].type == 'elses':
return ['elif', p.or_expr, p.block, p.elses]
else_ = p.elses
root.setElse(else_)
return root

@_('ELSE block EOL')
def elses(self, p):
return ['else', p.block, p.block, []]
return p.block

@_('WHILE LPAREN or_expr RPAREN block EOL')
def loop(self, p):
Expand Down
12 changes: 0 additions & 12 deletions helpers/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@ def evaluate(self, table: SymbolTable) -> NoReturn:
with then:
self.commandTrue.evaluate(table)
with otherwise:
# for ind, elif_ in enumerate(self.elifClauses):
# elifEntry = self.builder.append_basic_block(
# name=f"elif_{self.id}_{ind}")
# ifOut = self.builder.append_basic_block(
# name=f"elif_out_{self.id}_{ind}")
# typ, value, cond = elif_[0].evaluate(table)
# self.builder.cbranch(cond, elifEntry, ifOut)
# pos = self.builder.position_at_start(elifEntry)
# com = elif_[1].evaluate(table)
# typ, value, cond = self.condition.evaluate(table)
# self.builder.cbranch(cond, elifEntry, ifOut)
# self.builder.position_at_start(ifOut)
if self.commandElse:
self.commandElse.evaluate(table)

Expand Down

0 comments on commit 5864928

Please sign in to comment.