From f7d79724c35d2efd81389eee7c5c922a1ef361f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind?= Date: Sun, 13 Feb 2022 18:07:47 +0100 Subject: [PATCH] Added precedence --- exercises/02/vslc/src/parser.y | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/exercises/02/vslc/src/parser.y b/exercises/02/vslc/src/parser.y index e567c41..f72326e 100644 --- a/exercises/02/vslc/src/parser.y +++ b/exercises/02/vslc/src/parser.y @@ -5,6 +5,12 @@ %token FUNC PRINT RETURN CONTINUE IF THEN ELSE WHILE DO OPENBLOCK CLOSEBLOCK %token VAR NUMBER IDENTIFIER STRING +%left '|' '&' '^' +%left '+' '-' +%left '*' '/' +%nonassoc UMINUS +%right '~' + %% program: global_list { @@ -217,7 +223,7 @@ expression: | expression '/' expression { node_init($$ = malloc(sizeof(node_t)), EXPRESSION, strdup("/"), 2, $1, $3); } - | '-' expression { + | '-' expression %prec UMINUS { node_init($$ = malloc(sizeof(node_t)), EXPRESSION, strdup("-"), 1, $2); } | '~' expression {