BrimVeyn/ft_lex
POSIX Lex utility implementation in Zig
ft_lex is a full-featured reimplementation of the classic lex
utility, built as part of the 42 school curriculum. It adheres strictly to the POSIX 2024 specification, covering all required features and bonus challenges.
ft_lex
is a lexical analyzer generator that transforms .l
files (Lex source files) into efficient C or Zig source code capable of scanning and tokenizing input streams. The core of this project involves implementing the full lex pipeline from regular expression parsing to optimized scanner generation.
Fully supports Extended Regular Expressions (ERE) as defined by POSIX.
Implements all POSIX-defined scanner macros and functions:
input()
, unput()
, yywrap()
, yymore()
, yyless()
BEGIN
and exclusive
/inclusive
modes/
, and anchors ^
and $
REJECT
base
, check
, next
, default
arrays).l
file actually uses.-g
flag) β generates .dot
files representing the NFA and DFA for each start condition, useful for visualization with GraphvizThis project is written entirely in Zig. To build:
zig build libl
zig build
To run the lexical analyzer generator:
./zig-out/bin/ft_lex input.l
To see all available options:
./zig-out/bin/ft_lex --help
To generate a scanner and compile it:
./zig-out/bin/ft_lex input.l
cc -o scanner ft_lex.yy.c src/libl/libl.a
./scanner < input.txt
Check the examples/
directory for .l
files demonstrating:
REJECT
, yymore()
, yyless()
input()
and unput()
REJECT
, yymore()
or trailing contexts (/
) may significantly increase DFA size and complexity.lex
/flex
implementations.lex
Specification (2024)Bryan VAN PAEMEL β github.com/BrimVeyn
This project was completed as part of the 42 school's advanced UNIX curriculum. All mandatory and bonus objectives have been implemented.