编写 .l文件
%{
c 头文件 和变量定义
%}
%%
{pattern} {c action code;}
%%
c function definition
compile && link
flex -o my.c my.l
gcc -o my my.c -lfl
当无main函数时, 需要 -lfl && %option noreject noyywrap
中文支持:
.l 文件与需要检测的数据文件是同一编码, 否则识别不出来
vim securecrt centos 编辑显示中文:
centos 编辑i18n文件, 设置utf8
securecrt 设置成utf8
~/.vimrc: set encoding=utf8 && set termencoding=utf8
====================================================================
example:
makefile:
# Basic Makefile -- provides explicit rules
# Creates "myprogram" from "scan.l" and "myprogram.c"
#
CC = g++
CFLAGS = -g
LDFLAGS = #-lfl, can use this if && only if no main provided,
LEX=flex
check: k2.o check.o
$(CC) -o $@ $(LDFLAGS) $^
check.o: check.cpp
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
k2.o: k2.cpp
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
k2.cpp: k2.l
$(LEX) $(LFLAGS) -o $@ $^
clean:
$(RM) *.o k2.cpp
check.cpp: test code