Что такое формат файла L?
A .l file is a plain-text lexical-analyzer specification written in the Lex language. It defines how an input character stream should be broken into tokens - the first step in building a compiler, interpreter, or text-processing tool.
The format was created at Bell Labs in 1975 by Mike Lesk and Eric Schmidt as part of the Unix toolchain. Today virtually all .l files are processed by Flex (Fast Lexical Analyzer), the GNU-era open-source successor developed by Vern Paxson, though the source syntax remains largely the same.
A .l file is divided into three sections separated by %% marker lines:
- Definitions - named regex macros and
%optiondirectives - Rules - pairs of regular expressions and C action code that fire on a match
- User code - optional helper C functions appended verbatim to the output
An optional %{ ... %} block near the top injects C declarations directly into the generated scanner. Running flex yourfile.l (or lex yourfile.l) produces lex.yy.c, a self-contained C source file implementing the scanner as a deterministic finite automaton. That output is compiled with a C compiler and typically linked with a Yacc/Bison grammar file to build a complete language processor.
Note that .l is also used for Lisp source files and Unix troff manual-page sources, so file context matters when identifying the type.
Безопасность и защита
РИСК: LOWA .l Lex source is plain text and safe to open in an editor. The only caution: the rules contain C action code, and a malicious .l could embed harmful C that runs once compiled. Review .l files from untrusted sources before running flex and building them.
Детали формата
в двух словах- Lisp source file (.l) - Some Lisp dialects/implementations use .l for source code; plain text, but a different language than Lex.
- Unix man-page / troff source (.l) - Section-l (local) manual pages in nroff/troff source; documentation, not a lexer spec.
- Interleaf / WordPerfect library (.l) - Legacy library or list files in older document systems; rare.
Программы, открывающие файлы L
Технические подробности
глубокая спецификация| Format type | Plain-text lexical-analyzer specification (source code) |
| Encoding | ASCII / UTF-8 plain text; no binary header or magic bytes |
| File structure | Three sections separated by `%%`: definitions, rules, and user C code |
| Section 1 - Definitions | Named regex macros and `%option` directives (e.g., `%option noyywrap`) |
| Section 2 - Rules | Pairs of regular-expression patterns and C action code blocks executed on match |
| Section 3 - User code | Optional C helper functions copied verbatim into the generated output file |
| C-code injection block | `%{ ... %}` prologue near the top injects C declarations into the generated scanner |
| Primary output | `lex.yy.c` - a C source file implementing a DFA-based scanner |
| MIME type | `text/plain` (informal alias: `text/x-lex`) |
| Processing tools | `lex` (AT&T/POSIX), `flex` (GNU), `win_flex` (Windows via WinFlexBison) |
| Typical file size | 1 KB - 100 KB |
| Scanner algorithm | Compiles regex rules to a deterministic finite automaton (DFA) at build time |
| Common pairing | Combined with a `.y` Yacc or Bison grammar file to build a complete compiler front-end |
| Platform support | Unix, Linux, macOS natively; Windows via MSYS2, Cygwin, or WinFlexBison |
| Extension ambiguity | `.l` is also used for Lisp source files and Unix troff man-page source - file context required |
| Выпущен | Lex, 1975 (Unix); standardized in POSIX (lex utility) |
| Последняя версия | Flex 2.6.4 (2017) is the de-facto current implementation reading .l files |
| Открыть стандартное | Да · без роялти |
| Спецификация | pubs.opengroup.org |
Конвертации L
Вопросы и ответы сообщества
спрошено пользователямиВопросов пока нет - станьте первым, кто спросит о файлах L.