I already wasted two much time on converting it, but I always get up getting common prefix ID.
Can anyone explain it to me? as I am trying to do it for a very large grammar and need my basics clear.
A, B, C, D are the only Non-Terminals.
A : ‘(‘ B ‘)’
| ID ASSIGN C
| C
C : C '+' D
| C '-' D
| D
D : ID
| ID '(' actuals ')'
| ID '(' ')'
| INT_LIT
| ‘(‘ C ‘)’
B : B ';' A | A
In LL, a production can't have multiple options starting with the same terminal, so you pull those common parts into a shared head, if you will. So
D : ID
| ID '(' actuals ')'
| ID '(' ')'
| INT_LIT
| ‘(‘ C ‘)’
becomes something along the lines of
D : D_things_that_start_with_ID
| D_things_that_do_not_start_with_ID
where
D_things_that_start_with_ID :
ID D_things_that_follow_ID
D_things_that_follow_ID :
epsilon
| '(' actuals ')'
| '(' ')'
D_things_that_do_not_start_with_ID :
INT_LIT
| ‘(‘ C ‘)’
and so on for other common lead symbols.
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.