Imagination is more important than knowledge.Knowledge is limited. Imagination encircles the world.—— Einstein
首先,lex和yacc是开源工具,帮助开发者实现语法,词法分析。如果作为一个开发者去使用它们,就需要阅读它们的说明书,直到你会用,一句话,就是个工具而已。当然,如果你对编译原理很清楚,可以更好地理解它,甚至可以分析它们的源代码哦。
既然是工具,了解它们的话就需要说明书。
Lex和yacc都是贝尔实验室在20世纪70年代发明的。
有时你会碰到bison和flex:
The GNU Project of the Free Software Foundation distributes bison, a yacc replacement; BSD and GNU Project also distribute flex (Fast Lexical Analyzer Generator), “a rewrite of lex intended to right some of that tool’s deficiencies,” according to its reference page.
何时建议你采用lex和yacc:
Lex and yacc help you write programs that transform structured input. This includes an enormous range of applications—anything from a simple text search program that looks for patterns in its input file to a C compiler that transforms a source program into optimized object code.
Lex and yacc are tools designed for writers of compilers and interpreters. Any application that looks for patterns in its input, or has an input or command language is a good candidate for lex and yacc.
Furthermore, they allow for rapid application prototyping, easy modification, and simple maintenance of programs.
When a task involves dividing the input into units and establishing some relationship among those units, you should think of lex and yacc.
推荐几本书:
《lex and yacc--second edition》 – 作者:John R. Levine
《编译原理》,又叫龙书
《自制编程语言》 – 前桥和弥