I have tried put my rules to https://www.cs.princeton.edu/courses/archive/spring20/cos320/LL1/ but it can't parse string
for name := num to num do begin operator ; end ;
S ::= for NAME := NUM1 T NUM2 do LIST C
NAME ::= name
NUM1 ::= num T
T ::= to NUM2
NUM2 ::= num
LIST ::= begin O
O ::= operator C D
C ::= ;
D ::= O
D ::= end C
The grammar is LL(1), but this tool it seems to use
Sinternally for the start rule, and you already have it in your grammar. If you rename it to 'X' (for example) it seems to be recognized. Also you probably do not wantNUM1 ::= num TasTis already available afterNUM1in ruleSthat should be renamed. You may also not wantT ::= to NUM2to haveNUM2asNUM2is already inSafterT.Based on your comment down, I will update the answer. As I have written up, the grammar is probably not what you want, here is the changed grammar:
I have removed the
TfromNUM1andNUM2fromT, because they are already expected inST. I have also removedCfrom the end ofST, because theLISThasOin its end that hasC Dalready. The original question was is the grammar LL(1), and 'yes' it is. But does the grammar recognize what you expect is another question.If however you need exactly your original grammar, then this input will be accepted: