Query: lex
OS: centos
Section: 1p
Links: centos man pages all man pages
Forums: unix linux community forum categories
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
LEX(1P) POSIX Programmer's Manual LEX(1P)PROLOGThis manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.NAMElex - generate programs for lexical tasks (DEVELOPMENT)SYNOPSISlex [-t][-n|-v][file ...]DESCRIPTIONThe lex utility shall generate C programs to be used in lexical processing of character input, and that can be used as an interface to yacc. The C programs shall be generated from lex source code and conform to the ISO C standard. Usually, the lex utility shall write the program it generates to the file lex.yy.c; the state of this file is unspecified if lex exits with a non-zero exit status. See the EXTENDED DESCRIPTION section for a complete description of the lex input language.OPTIONSThe lex utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines. The following options shall be supported: -n Suppress the summary of statistics usually written with the -v option. If no table sizes are specified in the lex source code and the -v option is not specified, then -n is implied. -t Write the resulting program to standard output instead of lex.yy.c. -v Write a summary of lex statistics to the standard output. (See the discussion of lex table sizes in Definitions in lex .) If the -t option is specified and -n is not specified, this report shall be written to standard error. If table sizes are specified in the lex source code, and if the -n option is not specified, the -v option may be enabled.OPERANDSThe following operand shall be supported: file A pathname of an input file. If more than one such file is specified, all files shall be concatenated to produce a single lex pro- gram. If no file operands are specified, or if a file operand is '-', the standard input shall be used.STDINThe standard input shall be used if no file operands are specified, or if a file operand is '-' . See INPUT FILES.INPUT FILESThe input files shall be text files containing lex source code, as described in the EXTENDED DESCRIPTION section.ENVIRONMENT VARIABLESThe following environment variables shall affect the execution of lex: LANG Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of IEEE Std 1003.1-2001, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.) LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regular expres- sions. If this variable is not set to the POSIX locale, the results are unspecified. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files), and the behavior of character classes within regular expressions. If this variable is not set to the POSIX locale, the results are unspecified. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES .ASYNCHRONOUS EVENTSDefault.STDOUTIf the -t option is specified, the text file of C source code output of lex shall be written to standard output. If the -t option is not specified: * Implementation-defined informational, error, and warning messages concerning the contents of lex source code input shall be written to either the standard output or standard error. * If the -v option is specified and the -n option is not specified, lex statistics shall also be written to either the standard output or standard error, in an implementation-defined format. These statistics may also be generated if table sizes are specified with a '%' operator in the Definitions section, as long as the -n option is not specified.STDERRIf the -t option is specified, implementation-defined informational, error, and warning messages concerning the contents of lex source code input shall be written to the standard error. If the -t option is not specified: 1. Implementation-defined informational, error, and warning messages concerning the contents of lex source code input shall be written to either the standard output or standard error. 2. If the -v option is specified and the -n option is not specified, lex statistics shall also be written to either the standard output or standard error, in an implementation-defined format. These statistics may also be generated if table sizes are specified with a '%' operator in the Definitions section, as long as the -n option is not specified.OUTPUT FILESA text file containing C source code shall be written to lex.yy.c, or to the standard output if the -t option is present.EXTENDED DESCRIPTIONEach input file shall contain lex source code, which is a table of regular expressions with corresponding actions in the form of C program fragments. When lex.yy.c is compiled and linked with the lex library (using the -l l operand with c99), the resulting program shall read character input from the standard input and shall partition it into strings that match the given expressions. When an expression is matched, these actions shall occur: * The input string that was matched shall be left in yytext as a null-terminated string; yytext shall either be an external character array or a pointer to a character string. As explained in Definitions in lex, the type can be explicitly selected using the %array or %pointer declarations, but the default is implementation-defined. * The external int yyleng shall be set to the length of the matching string. * The expression's corresponding program fragment, or action, shall be executed. During pattern matching, lex shall search the set of patterns for the single longest possible match. Among rules that match the same number of characters, the rule given first shall be chosen. The general format of lex source shall be: Definitions %% Rules %% UserSubroutines The first "%%" is required to mark the beginning of the rules (regular expressions and actions); the second "%%" is required only if user subroutines follow. Any line in the Definitions section beginning with a <blank> shall be assumed to be a C program fragment and shall be copied to the exter- nal definition area of the lex.yy.c file. Similarly, anything in the Definitions section included between delimiter lines containing only "%{" and "%}" shall also be copied unchanged to the external definition area of the lex.yy.c file. Any such input (beginning with a <blank> or within "%{" and "%}" delimiter lines) appearing at the beginning of the Rules section before any rules are specified shall be written to lex.yy.c after the declarations of variables for the yylex() function and before the first line of code in yylex(). Thus, user variables local to yylex() can be declared here, as well as application code to execute upon entry to yylex(). The action taken by lex when encountering any input beginning with a <blank> or within "%{" and "%}" delimiter lines appearing in the Rules section but coming after one or more rules is undefined. The presence of such input may result in an erroneous definition of the yylex() function. Definitions in lex Definitions appear before the first "%%" delimiter. Any line in this section not contained between "%{" and "%}" lines and not beginning with a <blank> shall be assumed to define a lex substitution string. The format of these lines shall be: name substitute If a name does not meet the requirements for identifiers in the ISO C standard, the result is undefined. The string substitute shall replace the string { name} when it is used in a rule. The name string shall be recognized in this context only when the braces are provided and when it does not appear within a bracket expression or within double-quotes. In the Definitions section, any line beginning with a '%' (percent sign) character and followed by an alphanumeric word beginning with either 's' or 'S' shall define a set of start conditions. Any line beginning with a '%' followed by a word beginning with either 'x' or 'X' shall define a set of exclusive start conditions. When the generated scanner is in a %s state, patterns with no state specified shall be also active; in a %x state, such patterns shall not be active. The rest of the line, after the first word, shall be considered to be one or more <blank>-separated names of start conditions. Start condition names shall be constructed in the same way as definition names. Start conditions can be used to restrict the matching of regular expressions to one or more states as described in Regular Expressions in lex . Implementations shall accept either of the following two mutually-exclusive declarations in the Definitions section: %array Declare the type of yytext to be a null-terminated character array. %pointer Declare the type of yytext to be a pointer to a null-terminated character string. The default type of yytext is implementation-defined. If an application refers to yytext outside of the scanner source file (that is, via an extern), the application shall include the appropriate %array or %pointer declaration in the scanner source file. Implementations shall accept declarations in the Definitions section for setting certain internal table sizes. The declarations are shown in the following table. Table: Table Size Declarations in lex Declaration Description Minimum Value %p n Number of positions 2500 %n n Number of states 500 %a n Number of transitions 2000 %e n Number of parse tree nodes 1000 %k n Number of packed character classes 1000 %o n Size of the output array 3000 In the table, n represents a positive decimal integer, preceded by one or more <blank>s. The exact meaning of these table size numbers is implementation-defined. The implementation shall document how these numbers affect the lex utility and how they are related to any output that may be generated by the implementation should limitations be encountered during the execution of lex. It shall be possible to deter- mine from this output which of the table size values needs to be modified to permit lex to successfully generate tables for the input lan- guage. The values in the column Minimum Value represent the lowest values conforming implementations shall provide. Rules in lex The rules in lex source files are a table in which the left column contains regular expressions and the right column contains actions (C program fragments) to be executed when the expressions are recognized. ERE action ERE action... The extended regular expression (ERE) portion of a row shall be separated from action by one or more <blank>s. A regular expression con- taining <blank>s shall be recognized under one of the following conditions: * The entire expression appears within double-quotes. * The <blank>s appear within double-quotes or square brackets. * Each <blank> is preceded by a backslash character. User Subroutines in lex Anything in the user subroutines section shall be copied to lex.yy.c following yylex(). Regular Expressions in lex The lex utility shall support the set of extended regular expressions (see the Base Definitions volume of IEEE Std 1003.1-2001, Section 9.4, Extended Regular Expressions), with the following additions and exceptions to the syntax: "..." Any string enclosed in double-quotes shall represent the characters within the double-quotes as themselves, except that backslash escapes (which appear in the following table) shall be recognized. Any backslash-escape sequence shall be terminated by the closing quote. For example, "