Dave McGuire wrote: > On Jun 16, 2007, at 1:04 AM, Samuel A. Falvo II wrote: >>> Fortunately, gperf is an easy one to deal with. And damn cool to >>> *use*, too...I've used it in a number of projects and it has been >>> fantastic. >> I did not even know it existed until just now. >> >> It's said that GCC uses gperf for its keyword tables and so forth -- I >> could have sworn they used Flex and Bison? Those don't use gperf as >> far as I'm aware. Hmmm > > It does use flex and bison...but reserved word lookups are done > with gperf. I don't know why that job isn't done by the lexer; I've > not dug into the GCC sources. I am curious about it though.
Compilers do generally use flex/bison for the syntax and the general lexical syntax, but normally there are so many keywords that making a flex rule for every keyword would make for a horribly inefficient flex state machine. So what is normally done in this case is to make a flex rule to match identifiers, and then test in a hash table if that identifier is a keyword. If it is, return the lex code for that keyword. Otherwise, return the lex code for an identifier. This generates a more compact lexical analyzer machine. The gperf program is good at making those hash tables. -- Steve Williams "The woods are lovely, dark and deep. steve at icarus.com But I have promises to keep, http://www.icarus.com and lines to code before I sleep, http://www.picturel.com And lines to code before I sleep." _______________________________________________ geda-user mailing list geda-user@moria.seul.org http://www.seul.org/cgi-bin/mailman/listinfo/geda-user