Fix: add semantic check in grammar
[babeltrace.git] / formats / ctf / metadata / ctf-parser.y
index 76125677c94d4c30bfcfd5e3543e0700a825b8e2..58ea245b8d30f2b43b17cb26b7a8a72594bd0dc2 100644 (file)
@@ -1225,21 +1225,25 @@ unary_expression:
                postfix_expression
                {       $$ = $1;                                }
        |       PLUS postfix_expression
-               {       $$ = $2;                                }
-       |       MINUS postfix_expression
                {
                        $$ = $2;
-                       if ($$->u.unary_expression.type != UNARY_SIGNED_CONSTANT
-                               && $$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
+                       if ($$->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT
+                               && $$->u.unary_expression.type != UNARY_SIGNED_CONSTANT) {
                                reparent_error(scanner, "expecting numeric constant");
-
+                       }
+               }
+       |       MINUS postfix_expression
+               {
+                       $$ = $2;
                        if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
                                $$->u.unary_expression.type = UNARY_SIGNED_CONSTANT;
                                $$->u.unary_expression.u.signed_constant =
                                        -($$->u.unary_expression.u.unsigned_constant);
-                       } else {
+                       } else if ($$->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT) {
                                $$->u.unary_expression.u.signed_constant =
                                        -($$->u.unary_expression.u.signed_constant);
+                       } else {
+                               reparent_error(scanner, "expecting numeric constant");
                        }
                }
        ;
This page took 0.024156 seconds and 4 git commands to generate.