简体   繁体   中英

Is this grammar LL(1)

I have been asked to convert:

S → Sa | bSb | bc 

to LL(1) so far I have:

S → bY
Y → SbF | cF
F → aF | ε

Is this LL(1)? If not would this be LL(1):

S → bY
Y → bYbF | cF
F → aF | ε

if neither of these would somebody please give me the correct answer and why thanks in advance!

This is what I would do:

S → Sa | bSb | bc 
  1. Remove left recursion:

     F -> aF | EPSILON``` 
  2. Now left factor:

     F -> aF | EPSILON X -> SbF | cF``` 
  3. Check the First and Follows:

     S: b X: b, c F: a, EPSILON``` ```Follows(): S: $, b X: $, b F: $, b``` Everything checks out so it is LL(1) parsable. 

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