Sun Jul 11 17:52:20 2021 UTC ()
lint: remove redundant %prec from the grammar

Now that the precedence of the unary operators has been modeled via
separate rules, the precedence is no longer needed.

No change to the generated parser, with both yacc or Bison.


(rillig)
diff -r1.308 -r1.309 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.308 -r1.309 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/11 17:38:55 1.308
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/11 17:52:20 1.309
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.308 2021/07/11 17:38:55 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.309 2021/07/11 17:52:20 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
@@ -260,28 +260,26 @@ anonymize(sym_t *s) @@ -260,28 +260,26 @@ anonymize(sym_t *s)
260%left T_COMMA 260%left T_COMMA
261%right T_ASSIGN T_OPASSIGN 261%right T_ASSIGN T_OPASSIGN
262%right T_QUEST T_COLON 262%right T_QUEST T_COLON
263%left T_LOGOR 263%left T_LOGOR
264%left T_LOGAND 264%left T_LOGAND
265%left T_BITOR 265%left T_BITOR
266%left T_BITXOR 266%left T_BITXOR
267%left T_AMPER 267%left T_AMPER
268%left T_EQUALITY 268%left T_EQUALITY
269%left T_RELATIONAL 269%left T_RELATIONAL
270%left T_SHIFT 270%left T_SHIFT
271%left T_ADDITIVE 271%left T_ADDITIVE
272%left T_ASTERISK T_MULTIPLICATIVE 272%left T_ASTERISK T_MULTIPLICATIVE
273%right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG 
274%left T_LPAREN T_LBRACK T_POINT T_ARROW 
275 273
276%token <y_name> T_NAME 274%token <y_name> T_NAME
277%token <y_name> T_TYPENAME 275%token <y_name> T_TYPENAME
278%token <y_val> T_CON 276%token <y_val> T_CON
279%token <y_string> T_STRING 277%token <y_string> T_STRING
280 278
281%type <y_tnode> primary_expression 279%type <y_tnode> primary_expression
282%type <y_tnode> postfix_expression 280%type <y_tnode> postfix_expression
283%type <y_tnode> unary_expression 281%type <y_tnode> unary_expression
284 282
285%type <y_sym> func_decl 283%type <y_sym> func_decl
286%type <y_sym> notype_decl 284%type <y_sym> notype_decl
287%type <y_sym> type_decl 285%type <y_sym> type_decl
@@ -1823,27 +1821,27 @@ unary_expression: /* C99 6.5.3 */ @@ -1823,27 +1821,27 @@ unary_expression: /* C99 6.5.3 */
1823 /* unary + is illegal in traditional C */ 1821 /* unary + is illegal in traditional C */
1824 warning(100); 1822 warning(100);
1825 } 1823 }
1826 $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL); 1824 $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
1827 } 1825 }
1828 | T_UNARY term { 1826 | T_UNARY term {
1829 $$ = build($1, $2, NULL); 1827 $$ = build($1, $2, NULL);
1830 } 1828 }
1831 | T_SIZEOF unary_expression { 1829 | T_SIZEOF unary_expression {
1832 $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type); 1830 $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
1833 if ($$ != NULL) 1831 if ($$ != NULL)
1834 check_expr_misc($2, false, false, false, false, false, true); 1832 check_expr_misc($2, false, false, false, false, false, true);
1835 } 1833 }
1836 | T_SIZEOF T_LPAREN type_name T_RPAREN %prec T_SIZEOF { 1834 | T_SIZEOF T_LPAREN type_name T_RPAREN {
1837 $$ = build_sizeof($3); 1835 $$ = build_sizeof($3);
1838 } 1836 }
1839 ; 1837 ;
1840 1838
1841term: /* see C99 6.5.1 */ 1839term: /* see C99 6.5.1 */
1842 unary_expression 1840 unary_expression
1843 | T_REAL term { 1841 | T_REAL term {
1844 $$ = build(REAL, $2, NULL); 1842 $$ = build(REAL, $2, NULL);
1845 } 1843 }
1846 | T_IMAG term { 1844 | T_IMAG term {
1847 $$ = build(IMAG, $2, NULL); 1845 $$ = build(IMAG, $2, NULL);
1848 } 1846 }
1849 | T_EXTENSION term { 1847 | T_EXTENSION term {
@@ -1852,27 +1850,27 @@ term: /* see C99 6.5.1 */ @@ -1852,27 +1850,27 @@ term: /* see C99 6.5.1 */
1852 | T_REAL T_LPAREN term T_RPAREN { 1850 | T_REAL T_LPAREN term T_RPAREN {
1853 $$ = build(REAL, $3, NULL); 1851 $$ = build(REAL, $3, NULL);
1854 } 1852 }
1855 | T_IMAG T_LPAREN term T_RPAREN { 1853 | T_IMAG T_LPAREN term T_RPAREN {
1856 $$ = build(IMAG, $3, NULL); 1854 $$ = build(IMAG, $3, NULL);
1857 } 1855 }
1858 | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN { 1856 | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
1859 symtyp = FMEMBER; 1857 symtyp = FMEMBER;
1860 $$ = build_offsetof($3, getsym($5)); 1858 $$ = build_offsetof($3, getsym($5));
1861 } 1859 }
1862 | T_ALIGNOF T_LPAREN type_name T_RPAREN { 1860 | T_ALIGNOF T_LPAREN type_name T_RPAREN {
1863 $$ = build_alignof($3); 1861 $$ = build_alignof($3);
1864 } 1862 }
1865 | T_LPAREN type_name T_RPAREN term %prec T_UNARY { 1863 | T_LPAREN type_name T_RPAREN term {
1866 $$ = cast($4, $2); 1864 $$ = cast($4, $2);
1867 } 1865 }
1868 ; 1866 ;
1869 1867
1870generic_selection: /* C11 6.5.1.1 */ 1868generic_selection: /* C11 6.5.1.1 */
1871 T_GENERIC T_LPAREN assignment_expression T_COMMA 1869 T_GENERIC T_LPAREN assignment_expression T_COMMA
1872 generic_assoc_list T_RPAREN { 1870 generic_assoc_list T_RPAREN {
1873 /* generic selection requires C11 or later */ 1871 /* generic selection requires C11 or later */
1874 c11ism(345); 1872 c11ism(345);
1875 $$ = build_generic_selection($3, $5); 1873 $$ = build_generic_selection($3, $5);
1876 } 1874 }
1877 ; 1875 ;
1878 1876