Question

Add a unary minus operator that has higher precedence than either + or *, to the...

Add a unary minus operator that has higher precedence than either + or *, to the following the grammar (below):

<assign> -> <id> = <expr>

<id> -> A | B | C

<expr> -> <expr> + < term> | <term>

<term> -> <term> * <factor> | <factor>

<factor> -> ( <expr> ) | <id>

please dont copy and paste

0 0
Add a comment Improve this question Transcribed image text
Answer #1

To add an operator of higher precedence always add it in lower level of grammer so that it is evaluated first(as grammer is left recursive). In the answer 1 that's the ereason -<id> is below <term> which consists of *. so always -will be evaluated first. Same is the case with answer 2.

Answer1:

< assign > ==> < id > = < expr >

<id> ==> A | B | C

< expr > ==> < expr > + < term > | < term >

< term > ==> < term > * < factor > | < factor >

< factor > ==> ( <expr> ) | +<id> | – <id>

--------------------------------------------------------------------------------------------------------------------

Answer 2:

< assign > ==> < id> = <expr>

< id > ==> A | B | C

< expr > ==> < expr > + <term> | <term> | - <factor>

<term> ==> <term> * <factor> | <factor>

<factor> ==> (<expr>) | <id>

Add a comment
Know the answer?
Add Answer to:
Add a unary minus operator that has higher precedence than either + or *, to the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT