Consider the following grammar for Boolean expressions. bool-expr → T | → F | → NOT ( bool-expr ) | → ( bool-expr binary-op bool-expr ) binary-op → AND | OR

The recursive descent parser to evaluate syntactically valid Boolean expressions has a single method corresponding to the bool-expr start symbol of this grammar. A tokenizer is used to convert the input into a queue of tokens (Queue) given as the argument to the parser. The tokenizer takes care of the binary-op non-terminal symbol by returning “AND” and “OR” as single tokens. You can assume that the input is syntactically valid, so that no error checking is necessary. Here is a sample value for #tokens. It represents a a boolean expression whose parse tree only has depth 3. Other incoming values can be more complicated. Note that, as terminal symbols, parenthese can be part of a boolean expression. The given sample value represents the boolean expression: NOT ( F )

The sample value promised for #tokens is: <"NOT", "(", "F", ")", "### END OF INPUT ###">

In this case the outgoing value of tokens should be: <"### END OF INPUT ###">

Do not test for equality against “### END OF INPUT ###” or test against the length of tokens. Another sample value for the same boolean expression is: <"NOT", "(", "F", ")", ")", "### END OF INPUT ###">

In this latter case the outgoing value of tokens should be: <")", "### END OF INPUT ###">

Write the code for the following method making sure you use the grammar above as a guide (as discussed in class and in Recursive-Descent Parsing). [http://cse.osu.edu/software/2231/web-sw2/extras/slides/27.Recursive-Descent-Parsing.pdf] [JAVA]

/**

* Evaluates a Boolean expression and returns its value.

*

* @param tokens

*            the {@code Queue} that starts with a bool-expr string

* @return value of the expression

* @updates tokens

* @requires [a bool-expr string is a proper prefix of tokens]

* @ensures

* valueOfBoolExpr =

*   [value of longest bool-expr string at start of #tokens] and

* #tokens = [longest bool-expr string at start of #tokens] * tokens

*

*/

public static boolean valueOfBoolExpr(Queue tokens) {…}

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now