Consider the following grammar for Boolean expressions. bool-expr → T → F → NOT (…
- User
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 height 3. Other incoming values can be more complicated. Note that, as terminal symbols, parentheses can be part of a boolean expression. The given sample value represents the boolean expression:
codeNOT ( F )A possible sample value promised for #tokens could be:
code<"NOT", "(", "F", ")", "### END OF INPUT ###">In this case the outgoing value of tokens should be:
code<"### 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 could be:
code<"NOT", "(", "F", ")", ")", "### END OF INPUT ###">In this latter case the outgoing value of tokens should be:
code<")", "### END OF INPUT ###">Finally, yet another sample value for the same boolean expression could be:
code<"NOT", "(", "F", ")">In this last case the outgoing value of tokens should be:
code<>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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /**
- Evaluates a Boolean expression and returns its value.
- @param tokens
-
code
the {@code Queue<String>} that starts with a bool-expr string - @return value of the expression
- @updates tokens
- @requires [a bool-expr string is a prefix of tokens]
- Assistant