문제

Here is the ambiguous grammar for a simple DDC compiler in BNF form:

<expr> ::= <term> | <expr> <op1> <expr>
<term> ::= <decimal arg> | <term> <op2> <decimal arg>
<decimal arg> ::= <digit> | <decimal arg> <digit>
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<op1> ::= + | -
<op2> ::= * | /

How can I make this grammar unambiguous?

도움이 되었습니까?

해결책

I believe you meant the first rule to be

<expr> ::= <term> | <expr> <op1> <term>

which will make the grammar unambiguous.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top