tags:

views:

102

answers:

2

Do Lex and Yacc provide optimized code or is it required that we write our own code manually for higher performance?

A: 

Yacc produces a table-driven parser, which can never be as fast as a well-written hand-coded one. I don't know if the same applies to lex.

Marcelo Cantos
[ *citation needed* ]. How would you design a parser with vastly superior performance to the table approach? As far as I was aware of that *is* a pretty fast method of parsing.
Joey
Marcelo Cantos
+1  A: 

The code you write has a substantial effect on the speed, especially on the lexer side. Some versions of Flex come with half a dozen (or so) different word counters, most written with Flex, and a few written by hand -- the code gives a pretty good idea of how to optimize scanning speed (and a fairly reasonable comparison of what you can expect in hand-written vs. machine generated lexers).

On the parser side, you're generally a bit more constrained -- you can't make as many changes without affecting the semantics. Here, a great deal depends on the parser generator you use -- for example, some algorithms for less constrained grammars consistently produce relatively slow parsers, while other algorithms only slow down for the less constrained constructs, and run relatively fast as long as the input doesn't use the more complex constructs.

Jerry Coffin