Question: ) Generating a grammar Give a grammar for Java's boolean expressions. (That is: a grammar describing exactly what you are allowed to put inside the
) Generating a grammar
Give a grammar for Java's boolean expressions. (That is: a grammar describing exactly what you are allowed to put inside the parentheses of a Java if () statement.)
For this problem, assume that you already have grammar rules for a Java numeric expression (NumExpr, probably similar but, for Java, more-complete-than the book's Example 2.4, p.46), for a Java identifier (Id), and that the only boolean operators you want to handle are &&,||,!,== and the numeric predicates >, >=, and ==. (You do not need to worry about making a grammar that enforces precedence, although you are welcome to.) For this problem, you may use extended BNF constructs ? or (or equivalently, written as and ).
Using your grammar, give a parse tree (not a derivation) for: a+2 > 5 || (!false == x) In the tree, for children of NumExpr and Id, you can just use to skip from the non-terminal directly to its children, since you didn't write the exact rules for those nonterminals. I recommend drawing your tree freehand3.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
