在lex初探篇中,每次要定义新的单词,都需要重新编译,这是非常麻烦的。但是如果在词法分析程序运行时能够构建一个单词表,那么就可以在
添加新的单词时不用修改和重新编译lex程序。
symboltable.l
用cygwin生成编译:
flex symboltable.l
gcc -o symboltable lex.yy.c
执行
$ ./symboltable
verb is am are was were be being been do
is
is: verb
asdasdasd
asdasdasd: don't recognize
noun dog cat horse cow
verb chew eat lock