简体   繁体   中英

How to show grammar is not LL(1) and convert grammar to LL(1)

I'm trying to find the ambiguity in this grammar so I can remove it and convert it to LL(1), however for the life of me I can't find the ambiguity. Any help will be much appreciated.

D -> if (C) {S} | if (C) {S} else {S}
S -> D | SA | A
A -> V = T;
V -> x | y
T -> 1 | 2
C -> true | false

The grammar is not ambiguous. Nonetheless, it is not LL(1) because when the lookahead token is if , it is not possible to know which of the two productions for D will be used.

To make it LL(1), you will need to left-factor D .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM