From d39d20aa6e00fbc9e24ec864b3f071f45e934d5a Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Mon, 7 Mar 2022 18:13:35 +0000 Subject: [PATCH] Added a reminder in the Parser in the event of bad syntax. --- parser.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/parser.c b/parser.c index 0080194..2469279 100644 --- a/parser.c +++ b/parser.c @@ -133,9 +133,13 @@ Expr* Primary() { if (Match(1, LParen)) { expr = Expression(); - Expr* temp = calloc(1, sizeof(Expr)); - if (!Check(RParen)) printf("Unbalanced\n"); //Todo: something or another... + if (!Check(RParen)) { + free(expr); + printf("Unbalanced\n"); //Todo: something or another... + return NULL; + } //Consume(RParen, "Expect ')' after expression."); + Expr* temp = calloc(1, sizeof(Expr)); temp->type = GROUPING; temp->expression.Grouping.expression = expr; @@ -183,7 +187,11 @@ Token* AdvanceParser() { return Previous(); } - +//In the Java implementation this get's called in catch blocks. +//Obviously that's not going to fly in C, so I need some way to +//"unwind" the stack. Maybe synchronizing (setting the Current variable) +//will be enough, and simply return NULLs up the call stack. +//Naive but might work in the future for this. void SynchronizeParser(void) { AdvanceParser(); //Discard tokens until we find a statement boundary, or at least something that looks like one.