Question: In C#, implement the Recursive Descent Parser (RDP) for the Grammar Details: 1. Create a class called Lexer that takes an input expression as a

In C#, implement the Recursive Descent Parser (RDP) for the Grammar

In C#, implement the Recursive Descent Parser (RDP) for the Grammar Details:

Details:

1. Create a class called Lexer that takes an input expression as a string and outputs its token stream.

2. The Lexer needs to catch any unidentified characters that don't belong to the grammar.

3. The RCP should then proceed to parse the input expression.

4. Please provide comments to explain what you have done with each line of code, and how the code compiles.

The output should appear as shown below.

Enter your expression:

num1 + num2 / (7 + total)

-----------------------------------

Calling Lexer:

num1: IDENT

+: ADD_OP

num2: IDENT

/: DIV_OP

(: LEFT_PAREN

7: INT_LIT

+: ADD_OP

total: IDENT

): RIGHT_PAREN

----------------------------------

Calling the Recursive Descent Parser:

NextToken: IDENT

Enter

Enter

Enter

NextToken: ADD_OP

Exit

Exit

NextToken: IDENT

Enter

Enter

NextToken: DIV_OP

Exit

NextToken: LEFT_PAREN

Enter

NextToken: INT_LIT

Enter

Enter

Enter

NextToken: ADD_OP

Exit

Exit

NextToken: IDENT

Enter

Enter

NextToken: RIGHT_PAREN

Exit

Exit

Exit

NextToken: EOF

Exit

Exit

Exit

Press any key to continue . . .

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!