Ask Question

Create an unambiguous grammar which generates basic mathematical expressions (using numbers and the four operators +, -, *, / ). Without parentheses, parsing and mathematically evaluating expressions created by this string should give the result you'd get while following the order of operations. For now, you may abstract "number" as a single terminal, n. In the order of operations, * and / should be given precedence over + and -. Aside from that, evaluation should occur from left to right. So 8/4*2 would result in 4, not 1.

+5
Answers (1)
  1. 11 September, 19:35
    0
    Let G denote an unambiguous Grammar capable of producing simple mathematical expressions, involving operators +,-,*,/. These operators are left associative (which ensures left to right evaluation). S is the start symbol of the Grammar i. e. the production starts from S. n denotes a number and is a terminal i. e. we can't produce anything further from n. Then, the solution is as follows:

    S → S + T |S - T | S

    T→T | F | T*F|F

    F → n

    Here, S, T and F are variables. Note that /, * have been given precedence over +,-.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create an unambiguous grammar which generates basic mathematical expressions (using numbers and the four operators +, -, *, / ). Without ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers