The epsilon is the empty string. It's possible to have epsilon or let's say "no terminal" below the B, because of B -> epsilon. But it's not possible for S. Look, if you have S -> Ba, what happens when B is empty, then the B kinda "disappears" and a is the first letter below the S.
Please help, I'm stuck on this problem: "Use the Factorisation method to obtain an LL(1) grammar from the following grammar: S -> aaSb S -> abSb S -> abcSb S -> b" I worked out the director sets as {a},{b},{c},{b} (in order top to bottom), is this right? I cannot find a suitable factorisation... this is driving me nuts!
Thomas Dennis I had to look some things up first. The director set (as www.cs.bgu.ac.il/~comp131/wiki.files/ps4.pdf tells me) is whether the first set or if the nonterminal can be empty, the first set merged with the follow set. You don't have any productions here. The first set contains the first terminal that is below a nonterminal or in this case below the rhs of a grammar. For S -> aaSb you say it's a. Correct, because you see the leftmost symbol on the rhs is an a. But for S-> abSb and S -> abcSb it's an a aswell. That's where you have the ll(1) conflict, because if you began with an S and you know that your next input symbol is an a, you don't know if you should take rule 1, 2 or 3 as next, because they all could give you an a as next symbol. To resolve the conflict, you merge the same beginnings of rhs into one rule. The first 3 rules can give me an a, so I want to factor out a from S -> aaSb, S -> abSb, S -> abcSb I keep a and exchange the rest by a new nonterminal: S -> aX (former a of the first three S-rules) X -> aSb (former rhs of the first S-rule without that a) X -> bSb (from second S-rule) X -> bcSb (from third S-rule) Now if you have an S and your next input symbol is an a, you know exactly which rule to take, as there's only one possibility. However. If your nonterminal is X and your next input symbol is b, you have another conflict between two rules that you have to choose from. To resolve this conflict as well, you have to factor out b and add another symbol for the rest of the rhs. Can you figure the next step out on your own?
Thomas Dennis Yes, exactly. And yes, First(S)={a,b}, that's why they're both in the director set of the rule before the last rule. Thank you for the question. Maybe I make a video about that kind of problem.
what we studied is that what follows A are the FIRST(B) because we have the rule S---> aAB and we get FOLLOW(A)={b} (we don't add Ɛ) but because we have Ɛ in FIRST(B) we have to add the FOLLOW(B) to the set of FOLLOW(A) and it becomes {$,a,b} and what follows A also follows S since we have this A--->S so FOLLOW(S)={$,a,b}. please correct me if i'm wrong! i have an important homework! thank you in advance.
Epsilon is the empty word. If the B in Ba is epsilon, then the a is the first terminal. If you have the sequence Ba, it can never become an empty sequence, hence epsilon is not included in the first set.
Mariapia Colavito That's because I don't answer the question in this video, but in two others. One of them is this: ua-cam.com/video/YOV-eR2ejuY/v-deo.html Thank you for mentioning. I'll add links to both videos to the description.
The question is which string (in this case of length 1, hence one terminal) comes "first" if we have aAB. Of course we're assuming that we're reading from left to right, so what's leftmost comes "first". In a CFG if we generated a terminal we can't get rid of it anymore. aAB already contains the a leftmost, which is a terminal, so the only terminal we can get leftmost when having aAB is a.
Great video thanks a lott ! (Passed the exam :) )
+goutham gandi Congratulations!
***** Thank you :)
Sorry, but First(S) = First(A) = {a,b,epsilon} ? Why not the epsilon?
The epsilon is the empty string. It's possible to have epsilon or let's say "no terminal" below the B, because of B -> epsilon. But it's not possible for S. Look, if you have S -> Ba, what happens when B is empty, then the B kinda "disappears" and a is the first letter below the S.
Please help, I'm stuck on this problem:
"Use the Factorisation method to obtain an LL(1) grammar from the following grammar:
S -> aaSb
S -> abSb
S -> abcSb
S -> b"
I worked out the director sets as {a},{b},{c},{b} (in order top to bottom), is this right? I cannot find a suitable factorisation... this is driving me nuts!
Thomas Dennis I had to look some things up first.
The director set (as www.cs.bgu.ac.il/~comp131/wiki.files/ps4.pdf tells me) is whether the first set or if the nonterminal can be empty, the first set merged with the follow set. You don't have any productions here.
The first set contains the first terminal that is below a nonterminal or in this case below the rhs of a grammar. For S -> aaSb you say it's a. Correct, because you see the leftmost symbol on the rhs is an a. But for S-> abSb and S -> abcSb it's an a aswell. That's where you have the ll(1) conflict, because if you began with an S and you know that your next input symbol is an a, you don't know if you should take rule 1, 2 or 3 as next, because they all could give you an a as next symbol.
To resolve the conflict, you merge the same beginnings of rhs into one rule. The first 3 rules can give me an a, so I want to factor out a from S -> aaSb, S -> abSb, S -> abcSb
I keep a and exchange the rest by a new nonterminal:
S -> aX (former a of the first three S-rules)
X -> aSb (former rhs of the first S-rule without that a)
X -> bSb (from second S-rule)
X -> bcSb (from third S-rule)
Now if you have an S and your next input symbol is an a, you know exactly which rule to take, as there's only one possibility. However. If your nonterminal is X and your next input symbol is b, you have another conflict between two rules that you have to choose from. To resolve this conflict as well, you have to factor out b and add another symbol for the rest of the rhs. Can you figure the next step out on your own?
Thomas Dennis
Yes, exactly. And yes, First(S)={a,b}, that's why they're both in the director set of the rule before the last rule.
Thank you for the question. Maybe I make a video about that kind of problem.
what we studied is that what follows A are the FIRST(B) because we have the rule S---> aAB and we get FOLLOW(A)={b} (we don't add Ɛ) but because we have Ɛ in FIRST(B) we have to add the FOLLOW(B) to the set of FOLLOW(A) and it becomes {$,a,b} and what follows A also follows S since we have this A--->S so FOLLOW(S)={$,a,b}.
please correct me if i'm wrong! i have an important homework! thank you in advance.
Oh, I see, I made a mistake. You're right. Thanks for the correction.
Why isn't epsilon included in the first (Ba)?
Epsilon is the empty word. If the B in Ba is epsilon, then the a is the first terminal. If you have the sequence Ba, it can never become an empty sequence, hence epsilon is not included in the first set.
***** Thank you for the quick reply. This has helped me more than my professor.
Thanks for this answer!
It's very clear, thank you!
Sorry, i don't understand if this grammar is LL(1) or not..
Mariapia Colavito That's because I don't answer the question in this video, but in two others. One of them is this: ua-cam.com/video/YOV-eR2ejuY/v-deo.html Thank you for mentioning. I'll add links to both videos to the description.
thanks
Follow(B) should be {a, b, $}. So add "b" as well.
+ali aliyev This mistake is already mentioned in the video description and in an annotation, but thanks.
why is also follow to {b}?
Because B is at the end of a right rule side of S, hence B inherits the Follow set of S.
Thank you very much!!!!!!
You're welcome. :)
why do we have to start with First(B)
We can start with any First set we want. B doesn't expand to other nonterminals, so I don't have to change it afterwards. It's just convenient.
That inglisch is ja geil :D
Meinst du Dinglisch? 🤣
2 years ago I saw this video to study for a college exam, now I want to make a calculator so I came back here xd
Welcome back!
God bless this video, thank you
Why is First(aAB) = {a}?
The question is which string (in this case of length 1, hence one terminal) comes "first" if we have aAB. Of course we're assuming that we're reading from left to right, so what's leftmost comes "first". In a CFG if we generated a terminal we can't get rid of it anymore. aAB already contains the a leftmost, which is a terminal, so the only terminal we can get leftmost when having aAB is a.
thanks!
Follow(B) = {$,a,b}
As Follow(S)={$,b}
probably the worst english i ve heard in my life :D
You should've heard me in school, even my German friends were laughing about my pronunciation back then. I think I have improved a lot. :D