Let’s say I have this grammar:
A: ε
| B 'a'
B: ε
| B 'b'
What is considered to be the closure of the item A: • B 'a'?
In other words, how do I deal with the epsilon transitions when figuring out closures?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is pretty straightforward. Included in the closure of
are all the rules
where first(R1) is not empty. For each (nonempty) token K in first(R1), you’ll need to (transitively!) include
etc. but presumably you are already clear on this.
You specific question is what happens if R1 can be empty? Then you also
need to include
Similarly for R2 being empty, if R1 can be empty, and similarly for Ri being empty if R1 .. Ri-1 can be empty. In extreme circumstances, all the Ri can be empty (lots of optional subclauses in your grammar), and you can end up including
Note that determining that first(R1) “can be empty” is itself a transitive closure question.
The GLR parser generator that I built for DMS precomputes first_can_be_empty using Warshall’s algorithm and then uses that in the closure construction.