ref: 5e36187eb6fac0a74254d40302033d0f043f8e72
parent: d7f2425b01e1c9643b82d5c565d73a0aee04384c
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 28 16:41:27 EDT 2012
Added tree structure for break statement
--- a/flow.c
+++ b/flow.c
@@ -149,6 +149,16 @@
}
static struct node *
+_break(void)
+{
+ expect(BREAK);
+ expect(';');
+ if (blockp == blocks)
+ error("break statement not within loop or switch");
+ return node1(OBREAK, NULL);
+}
+
+static struct node *
stmt(void)
{
register struct node *np;
@@ -161,7 +171,7 @@
case DO: return _do();
case WHILE: return _while();
case CONTINUE:
- case BREAK:
+ case BREAK: return _break();
case RETURN:
case GOTO: return _goto();
case CASE: /* TODO */
--- a/syntax.h
+++ b/syntax.h
@@ -11,7 +11,7 @@
OBOR, OAND, OOR, OTERN, OASSIGN, OA_MUL, OA_DIV,
OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND,
OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH, OIF, OFOR,
- OFEXP, ODO, OWHILE, OLABEL, OGOTO
+ OFEXP, ODO, OWHILE, OLABEL, OGOTO, OBREAK,
};
struct node;
--- a/tree.c
+++ b/tree.c
@@ -184,7 +184,8 @@
[ODO] = {2, "do"},
[OWHILE] = {2, "while"},
[OLABEL] = {2, "label"},
- [OGOTO] = {1, "goto"}
+ [OGOTO] = {1, "goto"},
+ [OBREAK] = {1, "break"},
};
if (!np) {
fputs(" nil", stdout);