You are on page 1of 1

1.

 Discuss the specification of lexical analyzer generator Lex


Lexical Analyzer Generator systematically translate regular definitions into C source code
for efficient scanning. Generated code is easy to integrate in C applications. Flex is a latter
version of lex.
A  lex consists of three parts:
1. regular definitions, C declarations in %{ %}
        %%
2. translation rules
        %%
3. user-defined auxiliary procedures
The translation rules are of the form:
    p1     { action1 }
    p2     { action2 }
    …
    pn     { actionn }
Lex/flex regular definitions are of the form:
       name definition
E.g. Digit   [0-9]
Example of lex specification
%{
    #include <stdio.h>
%}
%%
[0-9]+   { printf(“%s\n”, yytext); }
. | \n     {  }
%%
main()
{ yylex();
}

You might also like