Assume the following rules of associativity and precedence for expressions: Prec
ID: 671822 • Letter: A
Question
Assume the following rules of associativity and precedence for expressions:
Precedence: Highest *, /
+, -
=, /=, <, <=, >=, >
and
Lowest or
Associativity: Left to right
Write a BNF description of the precedence and associativity rules defined above for the expressions. Assume the only operands are the names a, b, c, d, and e.
Explanation / Answer
Requirement
following rules of associativity and precedence for expressions:
Precedence: Highest *, /
+, -
=, /=, <, <=, >=, >
and
Lowest or
Associativity: Left to right
Write a BNF description of the precedence and associativity rules defined above for the expressions. Assume the only operands are the names a, b, c, d, and e.
Solution
<expression> <expression> or <or_exp> | <or_exp>
<or_exp> <or_exp> and <and_exp> | <and_exp>
< and_exp > <and_exp> = <expr> | <and_exp /= <expr> | <and_exp> < <expr> | <and_exp> <= <expr> | <and_exp> >= <expr> | <and_exp> > <expr> | <expr>
<expr> <expr> + <term> | <expr> – <term> | <term>
< term > < term > * < factor > | < term > / < factor > | < factor >
< factor > ( < expr > ) | <operand>
<operand> a | b | c | d | e
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.