


      LLLLEEEEXXXX((((1111))))                      ((((UUUUNNNNIIIIXXXX 5555....0000))))                     LLLLEEEEXXXX((((1111))))



      NNNNAAAAMMMMEEEE
           lex - generate programs for simple lexical tasks

      SSSSYYYYNNNNTTTTAAAAXXXX
           lllleeeexxxx [ ----rrrrccccttttvvvvnnnn ] [ file ] ...

      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
           _L_e_x generates programs to be used in simple lexical analysis
           of text.

           The input _f_i_l_e_s (standard input default) contain strings and
           expressions to be searched for, and C text to be executed
           when strings are found.

           A file lllleeeexxxx....yyyyyyyy....cccc is generated which, when loaded with the
           library, copies the input to the output except when a string
           specified in the file is found; then the corresponding
           program text is executed.  The actual string matched is left
           in _y_y_t_e_x_t, an external character array.  Matching is done in
           order of the strings in the file.  The strings may contain
           square brackets to indicate character classes, as in [[[[aaaabbbbxxxx----zzzz]]]]
           to indicate aaaa, bbbb, xxxx, yyyy, and zzzz; and the operators ****, ++++, and ????
           mean respectively any non-negative number of, any positive
           number of, and either zero or one occurrences of, the
           previous character or character class.  The character .... is
           the class of all ASCII characters except new-line.
           Parentheses for grouping and vertical bar for alternation
           are also supported.  The notation _r{{{{_d,,,,_e}}}} in a rule indicates
           between _d and _e instances of regular expression _r.  It has
           higher precedence than |, but lower than *, ?, +, and
           concatenation.  The character ^^^^ at the beginning of an
           expression permits a successful match only immediately after
           a new-line, and the character $$$$ at the end of an expression
           requires a trailing new-line.  The character //// in an
           expression indicates trailing context; only the part of the
           expression up to the slash is returned in _y_y_t_e_x_t, but the
           remainder of the expression must follow in the input stream.
           An operator character may be used as an ordinary symbol if
           it is within """" symbols or preceded by \\\\.  Thus [[[[aaaa----zzzzAAAA----ZZZZ]]]]++++
           matches a string of letters.

           Three subroutines defined as macros are expected:  iiiinnnnppppuuuutttt(((())))
           to read a character; uuuunnnnppppuuuutttt((((_c)))) to replace a character read;
           and oooouuuuttttppppuuuutttt((((_c)))) to place an output character.  They are
           defined in terms of the standard streams, but you can
           override them.  The program generated is named yyyyyyyylllleeeexxxx(((()))), and
           the library contains a mmmmaaaaiiiinnnn(((()))) which calls it.  The action
           REJECT on the right side of the rule causes this match to be
           rejected and the next suitable match executed; the function
           yyyyyyyymmmmoooorrrreeee(((()))) accumulates additional characters into the same
           _y_y_t_e_x_t; and the function yyyyyyyylllleeeessssssss((((_p)))) pushes back the portion
           of the string matched beginning at _p, which should be



      Page 1                                                   (9010-E)






      LLLLEEEEXXXX((((1111))))                      ((((UUUUNNNNIIIIXXXX 5555....0000))))                     LLLLEEEEXXXX((((1111))))



           between _y_y_t_e_x_t and _y_y_t_e_x_t+_y_y_l_e_n_g.  The macros _i_n_p_u_t and
           _o_u_t_p_u_t use files yyyyyyyyiiiinnnn and yyyyyyyyoooouuuutttt to read from and write to,
           defaulted to ssssttttddddiiiinnnn and ssssttttddddoooouuuutttt, respectively.

           Any line beginning with a blank is assumed to contain only C
           text and is copied; if it precedes %%%%%%%% it is copied into the
           external definition area of the lllleeeexxxx....yyyyyyyy....cccc file.  All rules
           should follow a %%%%%%%%, as in YACC.  Lines preceding %%%%%%%% which
           begin with a non-blank character define the string on the
           left to be the remainder of the line; it can be called out
           later by surrounding it with {{{{}}}}.  Note that curly brackets
           do not imply parentheses; only string substitution is done.

      EEEEXXXXAAAAMMMMPPPPLLLLEEEE
                   D       [0-9]
                   %%
                   if      printf("IF statement\n");
                   [a-z]+  printf("tag, value %s\n",yytext);
                   0{D}+   printf("octal number %s\n",yytext);
                   {D}+    printf("decimal number %s\n",yytext);
                   "++"    printf("unary op\n");
                   "+"     printf("binary op\n");
                   "/*"    {       loop:
                                   while (input() != '*');
                                   switch (input())
                                           {
                                           case '/': break;
                                           case '*': unput('*');
                                           default: go to loop;
                                           }
                                   }

           The external names generated by _l_e_x all begin with the
           prefix yyyyyyyy or YYYYYYYY.

           The flags must appear before any files.  The flag ----rrrr
           indicates RATFOR actions, ----cccc indicates C actions and is the
           default, ----tttt causes the lllleeeexxxx....yyyyyyyy....cccc program to be written
           instead to standard output, ----vvvv provides a one-line summary
           of statistics of the machine generated, ----nnnn will not print
           out the ---- summary.  Multiple files are treated as a single
           file.  If no files are specified, standard input is used.

           Certain table sizes for the resulting finite state machine
           can be set in the definitions section:

                %%%%pppp _n number of positions is _n (default 2000)

                %%%%nnnn _n number of states is _n (500)

                %%%%tttt _n number of parse tree nodes is _n (1000)




      Page 2                                                   (9010-E)






      LLLLEEEEXXXX((((1111))))                      ((((UUUUNNNNIIIIXXXX 5555....0000))))                     LLLLEEEEXXXX((((1111))))



                %%%%aaaa _n number of transitions is _n (3000)

           The use of one or more of the above automatically implies
           the ----vvvv option, unless the ----nnnn option is used.

      SSSSEEEEEEEE AAAALLLLSSSSOOOO
           yacc(1).
           Lex tutorial in the _R_O_S _P_r_o_g_r_a_m_m_e_r'_s _G_u_i_d_e

      BBBBUUUUGGGGSSSS
           The ----rrrr option is not yet fully operational.












































      Page 3                                                   (9010-E)



