# BNF grammar for boolean expression

A) Create a BNF grammar that describes simple Boolean expressions of the form

var AND var

var OR var

where var is one of the symbols w, x, y, and z.

B) Modify your grammar from part (a) so that the Boolean expressions can be of the form

expr AND expr

expr OR expr

where expr is either a simple variable (w, x, y, or z) or an expression of the form

(var == var)

(var < var)

(var > var)

C) Modify your grammar one more time to allow a Boolean expression to have an arbitrary number of terms connected by either AND or OR. That is, your expressions can be of the form

expr AND expr OR expr OR expr AND expr....

© BrainMass Inc. brainmass.com October 9, 2019, 9:37 pm ad1c9bdddfhttps://brainmass.com/math/boolean-algebra/bnf-grammar-boolean-expressions-191933

#### Solution Preview

a.

<goal> ::= <var> AND <var> | <var> OR <var>

<var> ::= w | x | y | z

b.

<goal> ::= <expr> AND <expr> | <expr> ...

#### Solution Summary

Change in grammar is incremental, corresponding to modifications in Boolean expression specification.