nearley: Limiting Parsings for Ambiguous Grammars (Bocages)

I know its a long shot and not really something earley was meant for, but are there any methods or optimizations we can implement to deal with ambiguous grammars with exponential parsings? For instance:

num -> num "+" num | [0-9]:+

This seems simple, but nearley can’t deal well with large statements of this type because the amount of possible parsings is exponential with the number of plus signs. Could we implement the option of limiting the number of parsings?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 23 (14 by maintainers)

Most upvoted comments

That’s not a well-written grammar, though. You should write num -> num "+" [0-9]:+ | [0-9]:+. If there’s an ambiguous grammar, the assumption is that you want all possible parsings (I can think of use-cases where this is a legitimate assumption).