Consider the following BNF of arithmeticexpressions.<expression> ::= <term> + <expression> |<term> - <expression> | <term><term> ::= <factor> * <term> |<factor> / <term> | <factor><factor> ::= ( <expression> ) | <literal><literal> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Write code to build the expression tree of expressionswritten according to this syntax, assuming that:• You have a variable token that contains the first symbol of theexpression.• You have a function gettoken(token) which obtains the next tokenof the expression whenever you call it.• All the expressions submitted as input are compatible with thissyntax (no need to worry about error handling).
Consider the following BNF of arithmetic expressions. ::= + | - | <
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am