Skip to content

Commit

Permalink
Implement empty statement
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamSarodia committed May 2, 2017
1 parent 4c31f49 commit bca0ca0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shivyc/parser/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ def parse_expr_statement(index):
Ex: a = 3 + 4
"""
if token_is(index, token_kinds.semicolon):
return nodes.EmptyStatement(), index + 1

node, index = parse_expression(index)
index = match_token(index, token_kinds.semicolon, ParserError.AFTER)
return nodes.ExprStatement(node), index
12 changes: 12 additions & 0 deletions shivyc/tree/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ class Continue(_BreakContinue):
descrip = "continue"


class EmptyStatement(Node):
"""Node for a statement which is just a semicolon."""

def __init__(self):
"""Initialize node."""
super().__init__()

def make_il(self, il_code, symbol_table, c):
"""Nothing to do for a blank statement."""
pass


class ExprStatement(Node):
"""Node for a statement which contains one expression."""

Expand Down
5 changes: 5 additions & 0 deletions tests/frontend_tests/empty_statement.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int main() {
;;;;;
while(0);
for(;0;);
}

0 comments on commit bca0ca0

Please sign in to comment.