kach / nearley

📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
https://nearley.js.org
MIT License
3.59k stars 232 forks source link

Ambiguity problem with FEEL #615

Open al66 opened 2 years ago

al66 commented 2 years ago

I'm writing a interpreter for the FEEL expression language used in DMN (imicros-feel-interpreter). Everything is fine beside the problem with the foreseen ambiguity in the language. Unfortunately I have no idea, how to solve this problem with nearley.

FEEL allows names like Profit and loss
Dependent on the scope they can be a name Profit and loss or the logical expression Profit and loss. (This is only an example - FEEL also allow other operators in the names - like ./+-*).

The grammer is simplified something like this:

Expression -> Logical
        | Name

Name -> %word (%whitespace %word):*

Logical -> Expression %and Expression

If I allow keywords in names, I will get two results. With the postprocessing I can check, if the name "Profit and loss" is in the context and accept or reject. But I have no idea how I can eliminate the logical result, when there is a valid name.

Any idea is welcome.

(The full grammar I'm using can be found in the package under lib/feel.grammar.ne)