Module Name:    src
Committed By:   rillig
Date:           Sun Jul 11 17:38:55 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: remove shift/reduce conflict for sizeof

According to the grammar, the expression 'sizeof(int)x' was ambiguous.
Since 'sizeof(int)' is a valid term, that could have been reduced,
which would have resulted in a parse error when trying to parse 'x'.

Now 'sizeof' takes a unary_expression instead of a term.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.307 -r1.308 src/usr.bin/xlint/lint1/cgram.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.307 src/usr.bin/xlint/lint1/cgram.y:1.308
--- src/usr.bin/xlint/lint1/cgram.y:1.307	Sun Jul 11 16:57:21 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sun Jul 11 17:38:55 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.307 2021/07/11 16:57:21 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.307 2021/07/11 16:57:21 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -124,7 +124,7 @@ anonymize(sym_t *s)
 
 %}
 
-%expect 173
+%expect 172
 
 %union {
 	val_t	*y_val;
@@ -280,6 +280,7 @@ anonymize(sym_t *s)
 
 %type	<y_tnode>	primary_expression
 %type	<y_tnode>	postfix_expression
+%type	<y_tnode>	unary_expression
 
 %type	<y_sym>		func_decl
 %type	<y_sym>		notype_decl
@@ -1806,19 +1807,16 @@ postfix_expression:		/* C99 6.5.2 */
 	 }
 	;
 
-term:				/* see C99 6.5.1 */
+unary_expression:		/* C99 6.5.3 */
 	  postfix_expression
-	| T_INCDEC term {
+	| T_INCDEC unary_expression {
 		$$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
 	  }
-	| T_ASTERISK term {
-		$$ = build(INDIR, $2, NULL);
-	  }
 	| T_AMPER term {
 		$$ = build(ADDR, $2, NULL);
 	  }
-	| T_UNARY term {
-		$$ = build($1, $2, NULL);
+	| T_ASTERISK term {
+		$$ = build(INDIR, $2, NULL);
 	  }
 	| T_ADDITIVE term {
 		if (tflag && $1 == PLUS) {
@@ -1827,6 +1825,21 @@ term:				/* see C99 6.5.1 */
 		}
 		$$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
 	  }
+	| T_UNARY term {
+		$$ = build($1, $2, NULL);
+	  }
+	| T_SIZEOF unary_expression {
+		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
+		if ($$ != NULL)
+			check_expr_misc($2, false, false, false, false, false, true);
+	  }
+	| T_SIZEOF T_LPAREN type_name T_RPAREN %prec T_SIZEOF {
+		$$ = build_sizeof($3);
+	  }
+	;
+
+term:				/* see C99 6.5.1 */
+	  unary_expression
 	| T_REAL term {
 		$$ = build(REAL, $2, NULL);
 	  }
@@ -1846,14 +1859,6 @@ term:				/* see C99 6.5.1 */
 		symtyp = FMEMBER;
 		$$ = build_offsetof($3, getsym($5));
 	  }
-	| T_SIZEOF term	{
-		$$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
-		if ($$ != NULL)
-			check_expr_misc($2, false, false, false, false, false, true);
-	  }
-	| T_SIZEOF T_LPAREN type_name T_RPAREN %prec T_SIZEOF {
-		$$ = build_sizeof($3);
-	  }
 	| T_ALIGNOF T_LPAREN type_name T_RPAREN {
 		$$ = build_alignof($3);
 	  }

Reply via email to