I'm writing some kind of calculator using Jflex and CUP, I was able to make my grammar for infix, postfix and prefix notation as seen below, they works well if I just use each grammar and don't combine them.
The problem now is how can I combine them without getting a reduce/shift error, I've been doing this a few days now and I can't really figure it out. The main problem is when F --> NUMBER and E --> NUMBER they will have a reduce/shift error, I also tried adding more rules to try to mitigate the reduce/shift error but I'm not getting it correctly. Take note also that I was able to combine any combination of two but not three of them.
One approach I did is to try to merge my prefix and postfix to my infix by changing E to T and creating a new Rule T --> E|Number, but I still
It would be very helpful if someone could give me an explanation on how I can try to combine them.
Here is my Grammar
/* INFIX */
E --> E - T | E + T| T
T --> T * F | T / F | F
F --> NUMBER
/*PRE fix */
E --> + E E | - E E | / E E | * E E | NUMBER
/*POST fix*/
E --> E E + | E E -| E E * |E E / |NUMBER