From bca0ca0dec74c60c83055dfaf05a71456aa1bb56 Mon Sep 17 00:00:00 2001 From: Shivam Sarodia Date: Tue, 2 May 2017 04:09:46 -0400 Subject: [PATCH] Implement empty statement --- shivyc/parser/statement.py | 3 +++ shivyc/tree/nodes.py | 12 ++++++++++++ tests/frontend_tests/empty_statement.c | 5 +++++ 3 files changed, 20 insertions(+) create mode 100644 tests/frontend_tests/empty_statement.c diff --git a/shivyc/parser/statement.py b/shivyc/parser/statement.py index 2214c30..05bf746 100644 --- a/shivyc/parser/statement.py +++ b/shivyc/parser/statement.py @@ -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 diff --git a/shivyc/tree/nodes.py b/shivyc/tree/nodes.py index e780bf0..3252050 100644 --- a/shivyc/tree/nodes.py +++ b/shivyc/tree/nodes.py @@ -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.""" diff --git a/tests/frontend_tests/empty_statement.c b/tests/frontend_tests/empty_statement.c new file mode 100644 index 0000000..48823e7 --- /dev/null +++ b/tests/frontend_tests/empty_statement.c @@ -0,0 +1,5 @@ +int main() { + ;;;;; + while(0); + for(;0;); +}