DataFilter Grammar for [index]

.. expressions like a+b*c[n] were being parsed as equivalent to
   (a+b*c)[n] instead of a+b+(c[n]).

.. to resolve this symbol[index] is declared first in the grammar
   and whilst it will introduce reduce/reduce warnings that is
   actually what we want (we declare it early to override the
   definition from expr below).

.. keener yacc wizards might have a more elegant solution for
   this one....
This commit is contained in:
Mark Liversedge
2020-03-15 14:16:44 +00:00
parent 7f81ac76a9
commit 1231f59b1a
2 changed files with 12 additions and 1 deletions

View File

@@ -2705,6 +2705,7 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, float x, long it, RideItem
returning.vector[1]=calc.b;
returning.vector[2]=calc.r2;
returning.vector[3]=calc.see;
returning.number = calc.m + calc.b + calc.r2 + calc.see; // sum
return returning;
}

View File

@@ -297,7 +297,17 @@ lexpr:
}
;
array: expr '[' expr ']' {
array:
symbol '[' expr ']' { // reduce/reduce conflict, but added here so gets resolved
// first (order appeared in this file.
// e.g. a+b[1] is resolved as a+(b[1]) rather than (a+b)[1]
$$ = new Leaf(@1.first_column, @4.last_column);
$$->type = Leaf::Index;
$$->lvalue.l = $1;
$$->fparms << $3;
$$->op = 0;
}
| expr '[' expr ']' {
$$ = new Leaf(@1.first_column, @4.last_column);
$$->type = Leaf::Index;
$$->lvalue.l = $1;