Well I tried a number of different changes and noticed some interesting results. First, changing the precedence of the ? operator had no effect, but the issue is operator related. I believe it is an issue of operator ambiguity. Because a binary expression
and my conditional expression both use the common binary operators, there are two possible ways the parser can view the overall expression. I will explain my example since I'm sure my grammar looks odd compared to many. The grammar itself is used to express
dice rolls. Using the following example I will break down the meaning.
- 1d6 means roll 1 six sided die
- +# is a special operator that means to compare the sum of the previous expression (the value on the die) against the number following the operator (in this case 4). So, in this case, if the sum is greater than or equal to 4, the expression 1d6+#4 proves
- ? is an operator that says to evaluate the preceding expression and if true add/subtract/multiply/divide (depending on the binary operator) the expression following the binary operator. In this case add 1d6 + 5 (meaning, roll a single six sided die and
add 5 to the result).
So the whole expression means roll a six sided die and if the result on the die is 4 or higher add another six sided die roll plus 5 to the result.
In the current case of the parser it sees this expression as
which is what I was expecting. I have however noticed that if I change the expression to
it parses correctly, because the * operator has higher precedence than +, so it sees
as a binary expression, rather than seeing
as the binary expression. I also noticed that if I change the language to use some other characters than the standard binary operators after my conditional expression
it then also parses the way I would expect (though that isn't a desirable solution). I just need to somehow tell the parser to choose one match over the other possible match. I thought this might be similar to a dangling else in a way.
Incidentally during testing out these different approaches I noticed the grammar explorer was not refreshing the grammar properly either via auto-refresh, when I pressed the refresh button or when I manually removed and re-added the grammar. Only when I closed
the grammar explorer and re-opened the application did it pick up the changes in my grammar. This of course led to some incorrect results during my testing before I figured out what was going on. I was not sure if you were aware of this bug but I thought I
should mention it in case you were not.