Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool/Application to calculate first and follow sets

I am currently working on a parser and it seems that I have made a few mistakes druing the follow set calculation. So I was wondering if someone know a good tool to calculate follow and first sets so I could skip/reevaluate this error prone part of the parser construction.

like image 885
Nicola Coretti Avatar asked Apr 20 '11 13:04

Nicola Coretti


3 Answers

Take a look at http://hackingoff.com/compilers/predict-first-follow-set

It's an awesome tool to compute first and follow sets in a grammar. also, you can check your answer with this visualization tools:

http://smlweb.cpsc.ucalgary.ca/start.html

like image 71
Vahid Kharazi Avatar answered Jan 23 '23 08:01

Vahid Kharazi


I found my mistake by comparing my first/follow-sets with the one generated by this web-app

like image 36
Nicola Coretti Avatar answered Jan 23 '23 06:01

Nicola Coretti


Most parser generators that I've encountered don't have obvious means to dump this information, let alone dump it in a readable way. (I built one that does, for the reason you are suggesting, but it isn't available by itself and I doubt you want the rest of the baggage).

If your parser definition doesn't work, you mostly don't need to know these things to debug it. Staring at the rules amazingly enough helps; it also helps to build the two smallest grammar instances you can think of, one being something you expect to be accepted, and the other being a slight variant that should be rejected.

In spite of having a parser generator that will dump this information, I rarely resort to using it to debug grammars, and I've built 20-30 pretty big grammars with it.

like image 27
Ira Baxter Avatar answered Jan 23 '23 08:01

Ira Baxter