0

Ambiguous grammar:

E -> UV | EBE | V | [E]

V -> a | b

U -> < | >

B -> ? | ! | @

Some information:

Order of precedence: ? < ! < @, with unary operators (<,>) being the highest

Binary operators ?, !, @ are right associative.

My attempt:

E -> UV | EBT | V | [E]

T -> E

V -> a | b

U -> < | >

B -> ? | B1

B1 -> ! | B2

B2 -> @

I'm not sure if I left out some corner cases during my conversion. Appreciate if you guys can point some mistakes out and offer some hints.

uohzxela
  • 613
  • 4
  • 14
  • 28

1 Answers1

0

E -> UV | EBE | V | [E] V -> a | b U -> < | > B -> ? | ! | @

Order of precedence: ? < ! < @, with unary operators (<,>) being the highest.

Binary operators ?, !, @ are right associative.

I was confused about your order of precedence, because it implies ! is higher precedence than >.

So assuming this order of precedence:

a,b,<,>,?,!,@

I would note that unambiguous grammars are all about using intermediary characters, normally more than the ambiguous grammars, to ensure that there is a standard procedure of steps to reach a certain terminal symbol, i.e. each string will have the same parse tree. Highest precedence means that it is the closest conversion to the final non-terminal to terminal symbol conversion.

My answer would be:

E -> V?E | V!E | V@E | [E] //Right associativity = right recursive V-> <V | >V | E | T | a | b T-> a | b | E

However very difficult to know without knowing your target string and accepted/not accepted.

Dhruv Ghulati
  • 2,976
  • 3
  • 35
  • 51