picoe / Eto.Parse

Recursive descent LL(k) parser for .NET with Fluent API, BNF, EBNF and Gold Grammars
MIT License
148 stars 30 forks source link

GOLD grammar - different Alternative notation #35

Closed tf3pm closed 5 years ago

tf3pm commented 7 years ago

Hi all, could you please help me? I have GOLDparser grammar:

` const string testedGrammer = @" ""Case Sensitive"" = False ""Start Symbol"" =

Identifier = ({Letter}?|{Digit}+)

::= ::= Identifier "; ` this input does not match the grammar: ` const string expression03 = @"45646";` But if I change the notation for the Identifier to: `Identifier = ({Digit}+|{Letter}?)` everything works well. Could you please help me? Thanks, Tomas
cwensley commented 7 years ago

Hi Tomas,

Thanks for submitting the issue, but this is a side-effect of using a recursive descent parser vs. a state parser.

In Eto.Parse, the first alternative {Letter}? will always match and will not try the second alternative, even if it is "more valid". This means the order of the alternatives matter in Eto.Parse, even when using other grammars.

In more detail, {Letter}? basically means, if the current character is a letter, it is a match, otherwise it is still a match with zero-length.

Hope this helps! Curtis.

tf3pm commented 7 years ago

Thanks, Curtis!