lex&yacc系列(1)--- lex和yacc简介

本文探讨了Lex和Yacc这两款由贝尔实验室在20世纪70年代开发的开源工具,如何帮助程序员进行语法和词法分析,特别是在编译器和解释器的编写中。Lex和Yacc能有效处理输入文件的模式搜索,从简单的文本搜索到复杂的C编译器源代码转换,加速应用原型设计,简化程序修改和维护。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

《编译原理》,又叫龙书

《自制编程语言》 – 前桥和弥

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

First Snowflakes

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值