Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C++ code, implement a recursive descent parser for a logic calculator base

ID: 3758853 • Letter: U

Question

Using C++ code, implement a recursive descent parser for a logic calculator based on the Grammar below.

The user can use either capital or lower case 'T' and 'F' in their expression.

Use either a ';' or '=' to indicate the expression should be evaluated immediately.

The program should not exit when it encounters an error in the expression. Rather, it should output error information and then accept the next expression.

Use either a capital or lowercase 'Q' to indicate you want to exit the program.

Grammar

Note: This grammar uses the '|' symbol as a terminal. In place of that symbol, we will use '' to separate replacement options for each grammar rule.

Expression Term Expression | Term

Term Factor Term & Factor

Factor Primary Factor ^ Primary

Primary T F ( Expression ) ! Expression

Hints

Beware: In this grammar '&' represents logical AND, and '|' represents logical OR. In C++ '&' represents bitwise AND, and '|' represents bitwise OR. Make sure you use the appropriate logical versions in your code, i.e. '&&' for logical AND, and '||' for logical OR.

Note that if you use type bool in your Token (which you should), then exclusive or can be done using the C++ '!=' logical operator.

If you get an error in the expression, you will want to clear whatever is in your token stream and in cin so old unprocessed parts of a bad expression do not mess up the next expression. The Bingo code has an example of how to clear cin.

You cannot cout a boolean variable directly.

Beware of boolean short circuit. You want to avoid it.

Code Requirements

Functions for the grammar rules will return type bool.

You must use a recursive descent parser.

Example Run

Explanation / Answer

C++ code:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote