visual-decaf / decaf-compiler

Compiler of decaf language
1 stars 3 forks source link

熟悉Flex和Bison工具 #11

Closed DistinctWind closed 1 year ago

DistinctWind commented 1 year ago

为了生成词法分析器和语法分析器,使用一些外部工具来加速这个过程。

任务:阅读flex和bison的文档,熟悉其使用方法。 额外任务:学习flex和bison如何集成到cmake当中。

DistinctWind commented 1 year ago

关于flex、bison工具与cmake的集成

按照官方文档,可以使用find_package(FLEX)find_package(BISON)来让cmake寻找系统中已经安装的flexbison

阅读随cmake安装的模块FindFLEX.cmake的源代码发现,该模块也会寻找win_flex,证实该模块也会寻找Windows下的flex移植版本。

在Windows下,将win_flexwin_bison添加到PATH环境变量中,然后发现确实也能找到:

-- Found FLEX: D:/utils/win_flex_bison/win_flex.exe (found version "2.6.4") 
-- Found BISON: D:/utils/win_flex_bison/win_bison.exe (found version "3.8.2") 

并能正常编译。

在一定程度上解决了跨平台问题。目前的外部工具依赖flex/bison,C++第三方库VCPKG和编译工具集MINGW都有Windows移植版本,并且也能在cmake当中共同合作。

DistinctWind commented 1 year ago

详情请参见Flex的文档和Bison的文档。

其中,flex的文档可以使用info flex查询,也可以将构建flex,然后使用其中的doc文件夹下的.texi文件,利用texi2html工具转换成HTML(这样就能在现代化的浏览器中查看这个文档了)

bison的文档参见这里