Skip to contentSkip to conversation

ssfilter: Eliminate shift/reduce conflicts

PATCH In review Phil Sutter 2 participants 2 messages Mar 24, 2018 – Mar 27, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ssfilter: Eliminate shift/reduce conflicts

The problematic bit was the 'expr: expr expr' rule. Fix this by making 'expr' token represent a single filter only and introduce a new token 'exprlist' to represent a combination of filters.

---
 misc/ssfilter.y | 52 +++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)
misc/ssfilter.y +27 -25
index 4db3c95faa3cc..88d4229a9b241 100644
@@ -42,7 +42,7 @@ static void yyerror(char *s)
 %nonassoc '!'
 
 %%
-applet: null expr
+applet: null exprlist
         {
                 *yy_ret = $2;
                 $$ = $2;
@@ -51,6 +51,32 @@ applet: null expr
         ;
 null:   /* NOTHING */ { $$ = NULL; }
         ;
+exprlist: expr
+        | '!' expr
+        {
+                $$ = alloc_node(SSF_NOT, $2);
+        }
+        | '(' exprlist ')'
+        {
+                $$ = $2;
+        }
+        | exprlist '|' expr
+        {
+                $$ = alloc_node(SSF_OR, $1);
+                $$->post = $3;
+        }
+        | exprlist '&' expr
+        {
+                $$ = alloc_node(SSF_AND, $1);
+                $$->post = $3;
+        }
+        | exprlist expr
+        {
+                $$ = alloc_node(SSF_AND, $1);
+                $$->post = $2;
+        }
+        ;
+
 expr:	DCOND HOSTCOND
         {
 		$$ = alloc_node(SSF_DCOND, $2);
@@ -128,30 +154,6 @@ expr:	DCOND HOSTCOND
         {
                 $$ = alloc_node(SSF_S_AUTO, NULL);
         }
-        | expr '|' expr
-        {
-                $$ = alloc_node(SSF_OR, $1);
-	        $$->post = $3;
-        }
-        | expr expr
-        {
-                $$ = alloc_node(SSF_AND, $1);
-	        $$->post = $2;
-        }
-        | expr '&' expr
-
-        {
-                $$ = alloc_node(SSF_AND, $1);
-	        $$->post = $3;
-        }
-        | '!' expr
-        {
-                $$ = alloc_node(SSF_NOT, $2);
-        }
-        | '(' expr ')'
-        {
-                $$ = $2;
-        }
 ;
 %%
 
Signature · 1 line
2.16.1
#1 lore raw
Quoted 5 lines · On Sat, 24 Mar 2018 18:45:14 +0100 Phil Sutter <[email protected]> wrote:

The problematic bit was the 'expr: expr expr' rule. Fix this by making 'expr' token represent a single filter only and introduce a new token 'exprlist' to represent a combination of filters.

Thanks for fixing this. It was always a nuisance.