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
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
sample code for parser: sebesta/parser at master · huichen-cs/sebesta · GitHub
Step by step
Solved in 2 steps