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

C++ Code Implement a recursive descent parser for a logic calculator based on th

ID: 3758992 • Letter: C

Question

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

Explanation / Answer

#include #include #include using namespace std; class Token { **Tokentype** type; string value; int linenum; public: Token(**Tokentype** t, string v = "") { type = t; value = v; } **Tokentype** getType() { return type; } string getValue() { return value; } int getLinenum() { return linenum; } }; vector int_list; vector float_list; class PTree { **PTreeNodetype** type; PTree *left; PTree *right; public: PTree(**PTreeNodetype** t, PTree *l = 0, PTree *r = 0) { type = t; left = l; right = r; } **PTreeNodetype getType**() { return type; } }; // expr ::= term PLUS expr | term MINUS expr | term PTree * Expr() { PTree *term = **Term**(); Token *t; if (!term) return 0; t = **getToken**(); if (t == NULL) { delete t; return 0; } if (t->getType() != **T_SC**) { if (t->getType() == **T_RPAREN**) { **pushbacktoken**(t); return new PTree(**EXPR**, term); } if (t->getType() != **T_PLUS** && t->getType() != **T_MINUS**) { cout