Ask Question
20 November, 22:05

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. 20 November, 22:50
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers