Why do tools like yacc and ANTLR generate source code? -


these tools input grammar , output code processes series of tokens more useful, syntax tree. these tools written in form of library instead? reason generating source code output? there performance gain? more flexible end user? easier implement authors of yacc , antlr?

sorry if question vague, i'm curious historical reasons behind decisions authors made, , purpose auto-generated code has in today's environment.

there's big performance advantage achieved parser generator working out interactions of grammar rules respect 1 another, , compiling result code.

one build interpreters accepted grammars , did parsing; there parser types (earley) relatively @ that, , 1 compute grammar interactions @ runtime (earley parsers kind of anyway) rather offline , execute parsing algorithm.

but pay parsing performance penalty of 10 100x slowdown, , big storage demand.

if parsing using small grammars, or parsing small documents, might not matter. grammars many parser generators applied end being big (people keep wanting add things can in language), , end processing pretty big documents. performance matters, , viola, people build code-generating parser generators.

once have tool, easier use in simple cases. have parser generators, can apply them little grammars or parsing little documents.

edit: addendum. historical reason driven space , time demands. earlier systems had not lot of room (32kb in 1975), didn't run fast (1 mips same time frame), , people had big source files already. parser generators tended set of problems; interpreted grammars have had intolerably bad performance.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -