PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Lex

Lex

Lex is a grammar language created in 1975.

#289on PLDB 47Years Old 1.1kUsers
2Books 0Papers 3kRepos

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 ϴ

Books about Lex from ISBNdb

title authors year publisher
Lex & Yacc Doug Brown Doug and John R. Levine and Tony Mason and Tony Mason and Doug Brown 2012 O’Reilly Media
Hands-On Chatbot Development with Alexa Skills and Amazon Lex Sam Williams 28-09-2018 Packt Publishing
dns.html · lex.html · xojo.html

View source

PLDB - Build the next great programming language · v2022 · Day 32 · Docs · Build · Acknowledgements · Traffic Today · Traffic Trends · Mirrors · GitHub · feedback@pldb.com