Java – LL1 Boolean operator grammar implements a recursive parser

This is a small piece from the original syntax, and I have to implement the correct parser for recursion We must remove the ambiguity from it, left recursive e.t.c, so that we can implement its parser I've finished the other bits, but I can't figure out how to handle the not operator (~)

A valid expression may be 1& ~1,(1& ~1)e.t.c.

I've dealt with parentheses, and & and or symbols, but I can't deal with ~ symbols

This is the original grammar

A -> A & A 
A -> ~A
A -> (A)
A -> 0 | 1

I can't figure out how to deal with ~

This is my solution:

one -> two one'
one' -> ~one|^
two -> three two'
two' -> & three two'|^
three -> four three'
three' -> || four three' | ^
four -> (one) |0 |1

When I implement it, everything applies to parentheses, or operators But negation ~ didn't work So I don't think the syntax is correctly converted to LL (1)

Solution

Finally, I spent a lot of time solving the problem myself This is the solution

The Boolean not or (~) operator takes precedence over any other operator in the above syntax In the above solution, my priority is lower This is the right solution

@L_ 403_ 0@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>