I'm trying to add 2 things to my grammar:
Unary minus sign, i.e. '-', and
Parentheses
Here's my grammar so far:
<comp> ::= <expr> | <comp> <op0> <expr>
<expr> ::= <term> | <expr> <op1> <term>
<term> ::= <darg> | <term> <op2> <darg>
<darg> ::= <digit> | <darg> <digit>
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<op0> ::= > | < | =< | => | =
<op1> ::= + | -
<op2> ::= * | /
I've tried everything and can't figure this out. How can I make the unary minus sign be at the highest level of precedence, followed by parentheses next and then the remaining operators as they are described?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…