Share on Facebook Share on Twitter Email
Answers.com

lex

 
(lĕks) pronunciation
n., pl., le·ges ('jēz').
Law.

[Latin lēx, lēg-.]


Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics

(Yet Another Compiler Compiler) A Unix compiler used to create a compiler. The operators, variables and constants of the program are typically defined in C using lex (LEXical analyzer), which converts them into preprocessed, machine-readable tokens for yacc. The grammar of the new language is written in C and compiled in yacc. The combination of lex (define elements) and yacc (define actions) creates a new compiler. For more information, visit www.epaperpress.com. See bison.

Download Computer Desktop Encyclopedia to your PC, iPhone or Android.

noun

    The formal product of a legislative or judicial body: act, assize, bill1, enactment, law, legislation, measure, statute. See law.

This entry contains information applicable to United States law only.

[Latin, Law.] In medieval jurisprudence, a body or collection of various laws peculiar to a given nation or people; not a code in the modern sense, but an aggregation or collection of laws not codified or systematized. Also, a similar collection of laws relating to a general subject, and not peculiar to any one people.

In modern U.S. and English jurisprudence this term signifies a system or body of laws, written or unwritten, applicable to a particular case or question regarded as local or unique to a particular state, country, or jurisdiction.

n. a Lexus automobile.  This dude's Lex ain't no ghetto sled.

Random House Word Menu:

categories related to 'lex'

Top
Random House Word Menu by Stephen Glazier
For a list of words related to lex, see:

Wikipedia on Answers.com:

Lex (software)

Top

Lex is a computer program that generates lexical analyzers ("scanners" or "lexers").[1][2] Lex is commonly used with the yacc parser generator. Lex, originally written by Mike Lesk and Eric Schmidt[3] and described in 1975,[4] [5] is the standard lexical analyzer generator on many Unix systems, and a tool exhibiting its behavior is specified as part of the POSIX standard.[citation needed]

Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language.

Though traditionally proprietary software, versions of Lex based on the original AT&T code are available as open source, as part of systems such as OpenSolaris and Plan 9 from Bell Labs. Another popular open source version of Lex is flex, the "fast lexical analyzer".

Contents

Structure of a Lex file

The structure of a Lex file is intentionally similar to that of a yacc file; files are divided up into three sections, separated by lines that contain only two percent signs, as follows:

Definition section
%%
Rules section
%%
C code section
  • The definition section is the place to define macros and to import header files written in C. It is also possible to write any C code here, which will be copied verbatim into the generated source file.
  • The rules section is the most important section; it associates patterns with C statements. Patterns are simply regular expressions. When the lexer sees some text in the input matching a given pattern, it executes the associated C code. This is the basis of how Lex operates.
  • The C code section contains C statements and functions that are copied verbatim to the generated source file. These statements presumably contain code called by the rules in the rules section. In large programs it is more convenient to place this code in a separate file and link it in at compile time.

Example of a Lex file

The following is an example Lex file for the flex version of Lex. It recognizes strings of numbers (integers) in the input, and simply prints them out.

/*** Definition section ***/

%{
/* C code to be copied verbatim */
#include <stdio.h>
%}

/* This tells flex to read only one input file */
%option noyywrap

%%
    /*** 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;
}

If this input is given to flex, it will be converted into a C file, lex.yy.c. This can be compiled into an executable which matches and outputs strings of integers. For example, given the input:

abc123z.!&*2gj6

the program will print:

Saw an integer: 123
Saw an integer: 2
Saw an integer: 6

Using Lex with other programming tools

Using Lex with parser generators

Lex and parser generators, such as Yacc or Bison, are commonly used together. Parser generators use a formal grammar to parse an input stream, something which Lex cannot do using simple regular expressions (Lex is limited to simple finite state automata).

It is typically preferable to have a (Yacc-generated, say) parser be fed a token-stream as input, rather than having it consume the input character-stream directly. Lex is often used to produce such a token-stream.

Scannerless parsing refers to where a parser consumes the input character-stream directly, without a distinct lexer.

Lex and make

make is a utility that can be used to maintain programs involving Lex. Make assumes that a file that has an extension of .l is a Lex source file. The make internal macro LFLAGS can be used to specify Lex options to be invoked automatically by make.[6]

See also

References

  1. ^ Levine, John R; Mason, Tony; Brown, Doug (1992). LEX & YACC (2 ed.). O'Reilly. pp. 1–2. ISBN 1-56592-000-7. http://books.google.co.in/books?id=YrzpxNYegEkC&printsec=frontcover#PPA1,M1. 
  2. ^ Levine, John (August 2009). flex & bison. O'Reilly Media. pp. 304. ISBN 978-0-596-15597-1. http://oreilly.com/catalog/9780596155988. 
  3. ^ Lesk, M.E.; Schmidt, E.. "Lex - A Lexical Analyzer Generator". http://dinosaur.compilertools.net/lex/index.html. Retrieved 16 August 2010. 
  4. ^ Lesk, M.E.; Schmidt, E. (July 21, 1975). "Lex – A Lexical Analyzer Generator". UNIX TIME-SHARING SYSTEM:UNIX PROGRAMMER’S MANUAL, Seventh Edition, Volume 2B. bell-labs.com. http://cm.bell-labs.com/7thEdMan/v7vol2b.pdf. Retrieved Dec. 20, 2011. 
  5. ^ Lesk, M.E. (October 1975). "Lex – A Lexical Analyzer Generator". Comp. Sci. Tech. Rep. No. 39 (Murray Hill, New Jersey: Bell Laboratories). 
  6. ^ "make". The Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition (The IEEE and The Open Group). 2004. http://www.opengroup.org/onlinepubs/009695399/utilities/make.html 

External links


 
 
Related topics:
talion
Lex Loci Contractus
Lex Loci Delicti

Related answers:
What is the plural for lex? Read answer...
Is Lex a name? Read answer...
What is lex tool? Read answer...

Help us answer these:
What is lex gerau?
What is the plural of lex?
What is lex legum?

Post a question - any question - to the WikiAnswers community:

 

Copyrights:

American Heritage Dictionary. The American Heritage® Dictionary of the English Language, Fourth Edition Copyright © 2007, 2000 by Houghton Mifflin Company. Updated in 2009. Published by Houghton Mifflin Company. All rights reserved.  Read more
TechEncyclopedia. THIS DEFINITION IS FOR PERSONAL USE ONLY.
All other reproduction is strictly prohibited without permission from the publisher.
© 1981-2012 The Computer Language Company Inc.  All rights reserved.  Read more
Roget's Thesaurus. Roget's II: The New Thesaurus, Third Edition by the Editors of the American Heritage® Dictionary Copyright © 1995 byHoughton Mifflin Company. Published by Houghton Mifflin Company. All rights reserved.  Read more
$copyright.smallImage.alttext West's Encyclopedia of American Law. West's Encyclopedia of American Law. Copyright © 1998 by The Gale Group, Inc. All rights reserved.  Read more
McGraw-Hill Slang Dictionary. McGraw-Hill's Essential American Slang Dictionary. Copyright © 2007 by McGraw-Hill Companies, Inc. All rights reserved.  Read more
Random House Word Menu. © 2010 Write Brothers Inc. Word Menu is a registered trademark of the Estate of Stephen Glazier. Write Brothers Inc. All rights reserved.  Read more
Wikipedia on Answers.com. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article Lex (software) Read more

Follow us
Facebook Twitter
YouTube