Bison Internals

GNU/Bison is a LALR parser generator written in C. It can generate C and C++ code that implements LALR and GLR parsers. This project is an effort to document internal data structures of Bison.

Tuesday, June 20, 2006

The nullable list

Bison also creates a list of non-terminals that can expand into the empty string. A vector Nullable is created in nullable.c

Nullable[i] != 0 (zero) if i th non-terminal can expand into the empty string.

The algorithm itself is very simple. If X-> /* empty */ then clearly X is added to Nullable set

if X-> beta where beta contains only non-terminal symbols, X is also added to nullable set if all of the nonterminals can expand to the null string; if beta contains atleast one terminal symbol, then X cannot be included in the nullable set.

The implementation of the above algorithm is not as simple. It takes a good amount of linked list tweaking before we arrive at the final array. Look at nullable_compute () in nullable.c

3 Comments:

  • At 9:21 AM, Anonymous Anonymous said…

    Found this very useful, thanks. Have you played with bison parser in glr mode?

     
  • At 1:17 AM, Anonymous Anonymous said…

    Good fill someone in on and this mail helped me alot in my college assignement. Gratefulness you for your information.

     
  • At 4:53 PM, Anonymous Anonymous said…

    Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

     

Post a Comment

<< Home