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 derives list

The next task for bison is to generate a list of rules assosciated with Non-terminals. By simply walking thru all the rules, and some complex linked list programming, an array DERIVES[0..NVARS] is computed in the file derives.c (derives_compute()). I am able to document the structure of the derives array for now. Why is this array required and how it will be used will be filled in later.

A look at the print_derives() funtion reveals the structure of DERIVES:

Derives[i] = list of rules with i th nonterminal as LHS.

The list of rules is flat list of rule numbers followed by NULL.

e.g, S->NUM X | Y
X -> NUM
Y -> 'a'

derives[0] = 0 NULL (Non terminal $accept is the LHS of rule 0 $accept -> S $end)
derives[1] = 1 2 NULL (S is the LHS of rules 1 and 2)
derives[2] = 3 NULL
derives[3] = 4 NULL

0 Comments:

Post a Comment

<< Home