Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Lex

< >

Lex is a grammar language created in 1975 by Mike Lesk and Eric Schmidt.

#201on PLDB 49Years Old 3kRepos
Wikipedia

Lex is a computer program that generates lexical analyzers ("scanners" or "lexers"). Lex is commonly used with the yacc parser generator. Lex, originally written by Mike Lesk and Eric Schmidt and described in 1975, is the standard lexical analyzer generator on many Unix systems, and an equivalent tool is specified as part of the POSIX standard. Read more on Wikipedia...


Example from the web:
/*** Definition section ***/ %{ /* C code to be copied verbatim */ #include <stdio.h> %} %% /*** Rules section ***/ /* [0-9]+ matches a string of one or more digits */ [0-9]+ { /* yytext is a string containing the matched text. */ printf("Saw an integer: %s\n", yytext); } .|\n { /* Ignore all other characters. */ } %% /*** C Code section ***/ int main(void) { /* Call the lexer, then quit. */ yylex(); return 0; }
Example from Linguist:
/* +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.zend.com/license/2_00.txt. | | If you did not receive a copy of the Zend license and are unable to | | obtain it through the world-wide-web, please send a note to | | license@zend.com so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Authors: Zeev Suraski <zeev@zend.com> | | Jani Taskinen <jani@php.net> | | Marcus Boerger <helly@php.net> | | Nuno Lopes <nlopess@php.net> | | Scott MacVicar <scottmac@php.net> | +----------------------------------------------------------------------+ */ /* $Id$ */ #include <errno.h> #include "zend.h" #include "zend_globals.h" #include <zend_ini_parser.h> #include "zend_ini_scanner.h" #if 0 # define YYDEBUG(s, c) printf("state: %d char: %c\n", s, c) #else # define YYDEBUG(s, c) #endif #include "zend_ini_scanner_defs.h" #define YYCTYPE unsigned char /* allow the scanner to read one null byte after the end of the string (from ZEND_MMAP_AHEAD) * so that if will be able to terminate to match the current token (e.g. non-enclosed string) */ #define YYFILL(n) { if (YYCURSOR > YYLIMIT) return 0
Example from Wikipedia:
Saw an integer: 123 Saw an integer: 2 Saw an integer: 6

Language features

Feature Supported Example Token
Line Comments ✓ // A comment //
Comments ✓ /* A comment */
MultiLine Comments ✓ /* A comment */ /* */
Semantic Indentation X

- Build the next great programming language · Add · Issues · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements

Built with Scroll v155.3.0