Installation 如何在Cygwin上安装和使用Lex?

Installation 如何在Cygwin上安装和使用Lex?,installation,cygwin,flex-lexer,lex,Installation,Cygwin,Flex Lexer,Lex,我需要在编译器设计课程中使用Lex,但如何在Cygwin环境中安装和使用它?首先从安装apt cyg软件包管理器。然后 创建一个Lex文件,比如说sample.l。那么 lex sample.l 输出将写入lex.yy.c。您可以使用上一个命令中的-o标志更改此目的地。然后,使用 gcc lex.yy.c -lfl fl,而不仅仅是l,是链接器参数。默认情况下,生成的可执行文件应为a.exe。 如果您没有gcc,请使用 apt-cyg install gcc-core 安装Cygwin软件

我需要在编译器设计课程中使用Lex,但如何在Cygwin环境中安装和使用它?

首先从安装
apt cyg
软件包管理器。然后

创建一个Lex文件,比如说
sample.l
。那么

lex sample.l
输出将写入
lex.yy.c
。您可以使用上一个命令中的
-o
标志更改此目的地。然后,使用

gcc lex.yy.c -lfl
fl
,而不仅仅是
l
,是链接器参数
。默认情况下,生成的可执行文件应为
a.exe
。 如果您没有
gcc
,请使用

apt-cyg install gcc-core

安装Cygwin软件包的正确方法是Cygwin
setup

apt cyg
不受支持、不维护且容易出错

关于Lex,您可以使用
cygcheck

$ cygcheck -p bin/lex
Found 5 matches for bin/lex
flex-2.6.4-2 - flex: A fast lexical analyzer generator
...
因此,您需要安装
flex
软件包。因此,你有:

$ cygcheck -l flex |grep bin
/usr/bin/flex++
/usr/bin/flex.exe
/usr/bin/lex
作为补充信息,C编译器的最新版本是10.2.0-1

$ cygcheck -p usr/bin/gcc
Found 10 matches for usr/bin/gcc
gcc-core-10.2.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-7.4.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-9.3.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-9.3.0-2 - gcc-core: GNU Compiler Collection (C, OpenMP)
...
$ cygcheck -p usr/bin/gcc
Found 10 matches for usr/bin/gcc
gcc-core-10.2.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-7.4.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-9.3.0-1 - gcc-core: GNU Compiler Collection (C, OpenMP)
gcc-core-9.3.0-2 - gcc-core: GNU Compiler Collection (C, OpenMP)
...