2

I am using Grako. In my EBNF grammar, I have an expression that consists of a lot of subexpressions that are concatenated using the OR-operator, like so:

expression = subexpressionA | subexpressionB | ...  | subexpressionZ;

The parsing process always fails if the input string contains one of the latter subexpressions, say subexpressionZ. When I rewrite the grammar like this

expression = subexpressionZ | subexpressionB |  ...  | subexpressionA;

the parsing process finishes successfully if the input string contains subexpressionZ but will now fail if it contains subexpressionA.

Has anyone ever had a similar problem? Is that a bug in Grako (I am using 3.6.3.) or am I doing something wrong?

Thanks a lot for any ideas!

Matthias
  • 408
  • 3
  • 14
  • 2
    A bug in Grako is unlikely, since that kind of grammar rules are used in many actively used grammars. It is difficult to assess the problem without an example. Please post a minimal grammar and sample input that reproduces the problem? – Apalala Mar 15 '17 at 15:11
  • This sounds like an ordered-alternative issue, but as Apalala says, you'd have to post a [mcve] to verify that. – rici Mar 16 '17 at 17:56

1 Answers1

2

I solved my problem - a long time ago :) - by splitting up the expressions in a number of sub-expressions like so:

expression1 = subexpressionA | subexpressionB | subexpressionC;
expression2 = subexpressionD | subexpressionE | ...  | subexpressionZ;
expression = expression1 | expression2;

For some reason, this works...

Matthias
  • 408
  • 3
  • 14