Skip to content

Farewe1ll/flex

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

作业说明

本仓库在原版 flex 基础上实现了 Unicode 扩展,可通过 %option unicode--unicode 开关启用。

复现环境

  1. 系统:macOS (aarch64)。
  2. 依赖:autoconf, automake, bison, texinfo, help2man 已预装;若缺失,可用 Homebrew 安装:
brew install autoconf automake bison texinfo help2man
  1. 工程已包含 configure,可直接执行 ./configure 生成 Makefile。

构建步骤

./configure
make

构建过程中会自动生成两阶段的 flex 可执行文件以及 libfl。若需要重新配置,先 make distclean 再重复上述命令。

功能验证

新增的 Unicode 选项使得规则中的 \uXXXX\UXXXXXXXX 范围会被展开为 UTF-8 模式,字符类可以按码点粒度工作。示例:

%option unicode
CHINESE   [\u4E00-\u9FFF]+
%%
{CHINESE}   printf("CJK:%s\n", yytext);

启用方式:命令行 flex --unicode demo.l,或在源文件中写 %option unicode

测试方法

  1. 进入 tests/,运行内置校验:
make unicode_utf8
./unicode_utf8 unicode_utf8.txt

预期输出包括 CJK, GREEK, ARROWS, SYMBOLS, ASCII 等标识,表明同一类字符被完整识别。 2. 如需运行全部回归测试:

make check

代码阅读指引

  • src/unicode_utils.{c,h}:完成 Unicode 字符类解析与 UTF-8 正则构造。
  • src/scan.l:在词法器级别解析 \u/\U 转义并在编译期转换字符类。
  • tests/unicode_utf8.l:作业附带的示例规则与输入文件。

About

The Fast Lexical Analyzer - scanner generator for lexing in C and C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 76.6%
  • Lex 9.8%
  • Yacc 3.6%
  • M4 2.4%
  • Makefile 2.4%
  • Shell 1.9%
  • Other 3.3%