Consider the following BNF of arithmetic expressions. ::= + | - | <

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Consider the following BNF of arithmetic expressions. ::= + | - | <

Post by answerhappygod »

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).
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply