aboutsummaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-12-03 04:13:40 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-12-03 04:13:40 +0000
commit6ad3e61a2b5c0629012d6db2c3bb56e55a3a567b (patch)
treecc8e7119e0b7c1a13ad288a3fe55081ad85851cc /parser.c
parent0f0862245f0a73c589116eb401b0eeaab5c5e780 (diff)
downloadobf-6ad3e61a2b5c0629012d6db2c3bb56e55a3a567b.tar.gz
obf-6ad3e61a2b5c0629012d6db2c3bb56e55a3a567b.tar.bz2
obf-6ad3e61a2b5c0629012d6db2c3bb56e55a3a567b.zip
Fix errors due to no loops
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/parser.c b/parser.c
index 101f3e3..c7765ad 100644
--- a/parser.c
+++ b/parser.c
@@ -121,26 +121,29 @@ struct PResult parse_buffer(buffer_t *buffer)
}
// Third pass: setup loop references
- node_t *stack[loops];
- memset(stack, 0, loops);
size_t stackptr = 0;
- for (size_t i = 0; i < usable; ++i)
+ if (loops)
{
- node_t *node = nodes + i;
- if (node->type == LIN)
- stack[stackptr++] = node;
- else if (node->type == LOUT)
+ node_t *stack[loops];
+ memset(stack, 0, loops);
+ for (size_t i = 0; i < usable; ++i)
{
- if (stackptr == 0)
+ node_t *node = nodes + i;
+ if (node->type == LIN)
+ stack[stackptr++] = node;
+ else if (node->type == LOUT)
{
- print_error(buffer->name, node->row, node->col,
- "ERROR: Unbalanced square brackets!");
- goto error;
+ if (stackptr == 0)
+ {
+ print_error(buffer->name, node->row, node->col,
+ "ERROR: Unbalanced square brackets!");
+ goto error;
+ }
+ // Access last IN loop
+ --stackptr;
+ node->loop_ref = stack[stackptr] - nodes;
+ stack[stackptr]->loop_ref = i;
}
- // Access last IN loop
- --stackptr;
- node->loop_ref = stack[stackptr] - nodes;
- stack[stackptr]->loop_ref = i;
}
}