Fix DataFilter grammar for logical expressions

.. NP > 200 && IF > 0.85 didn't work because the datafilter
   grammar needed fixing up for precedence of the && and || operators.

.. this has been fixed by embedding into the grammar; binary expressions
   and logical expressions are now declared individually.

.. the generated tree uses the same encoding so no changes required
   to the code, just the grammar
This commit is contained in:
Mark Liversedge
2015-08-11 09:14:43 +01:00
parent 46769d6ca9
commit c500d8bb36

View File

@@ -70,7 +70,7 @@ extern Leaf *root; // root node for parsed statement
char function[32];
}
%type <leaf> symbol value lexpr;
%type <leaf> symbol value lexpr expr;
%type <op> lop cop bop;
%left ADD SUBTRACT DIVIDE MULTIPLY POW
@@ -83,24 +83,31 @@ extern Leaf *root; // root node for parsed statement
filter: lexpr { root = $1; }
;
lexpr : '(' lexpr ')' { $$ = new Leaf();
$$->type = Leaf::Logical;
$$->lvalue.l = $2;
$$->op = 0; }
| lexpr lop lexpr { $$ = new Leaf();
lexpr : expr lop expr { $$ = new Leaf();
$$->type = Leaf::Logical;
$$->lvalue.l = $1;
$$->op = $2;
$$->rvalue.l = $3; }
| '(' expr ')' { $$ = new Leaf();
$$->type = Leaf::Logical;
$$->lvalue.l = $2;
$$->op = 0; }
| expr
;
| lexpr cop lexpr { $$ = new Leaf();
expr : '(' expr ')' { $$ = new Leaf();
$$->type = Leaf::Logical;
$$->lvalue.l = $2;
$$->op = 0; }
| expr cop expr { $$ = new Leaf();
$$->type = Leaf::Operation;
$$->lvalue.l = $1;
$$->op = $2;
$$->rvalue.l = $3; }
| lexpr bop lexpr { $$ = new Leaf();
| expr bop expr { $$ = new Leaf();
$$->type = Leaf::BinaryOperation;
$$->lvalue.l = $1;
$$->op = $2;
@@ -110,7 +117,6 @@ lexpr : '(' lexpr ')' { $$ = new Leaf();
;
cop : EQ
| NEQ
| LT