0

Is the following good grammar for Nearley.js? It describes logical expressions with variables, negation, conjunction and parentheses.

It's a bit convoluted (?), but I didn't know other way how to make precedence work.

expression -> _ conjunction _      {% function(d) { return d[1] } %}

# Parentheses
parens ->
  "(" _ conjunction _ ")"          {% function(d) { return d[2] } %}
| variable                         {% id %}

# Negations
negation ->
  "~" _ parens                     {% function(d) { return {negation: [d[2]]} } %}
| parens                           {% id %}

# Conjunctions
conjunction ->
  conjunction _ "/\\" _ negation   {% function(d) { return {conjunction: [d[0], d[4]]} } %}
| negation                         {% id %}

# Variables
variable -> [A-Z]                  {% function(d) { return {variable: d} } %}

_ -> [\s]:*                        {% function(d) { return null } %}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.