Implement BNF grammar using a Parser. Test the parser using examples. Consider the following grammar to evaluate algebraic expressions: <expression ::= <expression> + <term> | <expression> - <term> | <term><term> ::= <term> * <factor> | <term> / <factor> | <factor><factor> ::= <primary> ^ <factor> | <primary><primary> ::= -<primary> | <element><element> ::= (<expression>) | <variable> | <number><number> ::= <digit> | <number> <digit><digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9<variable> := x | y Part 1. Modify the Parser program for a recursive-descent  recognizer that decides whether the input string is in the language generated by the grammar above, i.e. whether it has a parse tree. It halts normally if so and throws a SyntaxError if not.   sample code for parser: sebesta/parser at master · huichen-cs/sebesta · GitHub

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.5: Virtual Functions
Problem 5E
icon
Related questions
Question

 Implement BNF grammar using a Parser. Test the parser using examples.

Consider the following grammar to evaluate algebraic expressions:

<expression ::= <expression> + <term> | <expression> - <term> | <term>
<term> ::= <term> * <factor> | <term> / <factor> | <factor>
<factor> ::= <primary> ^ <factor> | <primary>
<primary> ::= -<primary> | <element>
<element> ::= (<expression>) | <variable> | <number>
<number> ::= <digit> | <number> <digit>
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<variable> := x | y

Part 1. Modify the Parser program for a recursive-descent  recognizer that decides whether the input string is in the language generated by the grammar above, i.e. whether it has a parse tree. It halts normally if so and throws a SyntaxError if not.

 

sample code for parser: sebesta/parser at master · huichen-cs/sebesta · GitHub

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Sorting
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning