Friday 17 February 2012

IMPLEMENTATION OF LEXICAL ANALYSE USING LEX TOOL (THEORY)


THEORY:
                                         A language for specifying lexical analyzer.
·        There is a wide range of tools for construction of lexical analyzer. The majority of these tools are based on regular expressions.
·        The one of the traditional tools of that kind is lex.We refer to the tool as the lex compiler and to its input specification as the lex language
           LEX:
·        The lex is used in the manner depicted.A specification of the lexical analyzer is preferred by creating a program lex.l in the lex language.
·        Then lex,l is run through the lex compiler to produce a ‘c’program lex.yy.c
·        The program lex.yy.c consists of a tabular representation of a transition diagram constructed from the regular expression of lex.l together with a standard routine that uses the table of recognize leximes.
·        Lex.yy.c is run through the ‘c’ compiler to produce as object program a.out,which is the lexical analyzer that transform as input stream into sequence of tokens.
                      Creating a lexical analyzer with lex is shown in below.

                                    LEX SOURCE PROGRAM



                     LEX SPECIFICATION:
Ø The lex program consists of  three parts
                %{
                declarations
                %}
                %%
                translation rules
                %%
                auxillary procedures

Ø The declarations section includes declarations of variables,constants and regular definitions.
Ø The regular definitions are statements and are used as components of the regular expressions,appearing in the translation rules.
Ø The translation rules of a lex program are of the form

                    P1{action 1}
                    P2{action 2}
                        .
                        .
                        .
                    pn{action n}
Ø Where each pi is a regular expression and each action is a program fragment described in what action the lexical analyzer should be taken when the pattern matches a lexime.
Ø The third section hold whatever auxillary procedures are neede by the actions.Alternately they are compiled separately and loaded with lexical analyzer.
Ø The lexical analyzer works in coordination with parser,when activated by the parser the lexical analyzer begins reading the character by character at a time.
Ø When the string is matched with one of the regular expression pi,then corresponding action will be executed.the repeated search will be made in order to return all tokens ina source string.
                   The lexical analyzer ignores the whitespaces and comments in the parser.



                 SHORTHAND OPERATORS:
                        
                                     1. []    àIt should indicate the set of characters.
                                     2. [^]  àThe string formed by any characters except within of                                                  that characte classes.
                                       3. *   àZero or more instances.    
                                     4. +  àOne or more instances.
                                     5. ?  àZero or one instance.
                                     6. $ àit match the end of the string.
                                     7. ^ àit match the start of the string.
                                     8.  . àit match any character except newline.
                                     9. {m} àspecify the exactly m copies of the previous regular                                expression should be matched.
                                               10. {m,n} àcauses the resulting regular expression to match                                from m to n repetition of the preciding R.E.
                 EXAMPLE:
                          Absence of m:
                          {,n} à{,6}àcauses the resulting RE to match from 0,1,2,3…6.
                          Absence of n:
                          {m,3} à{3,}àcauses the resulting RE to match from 3,4,……….
                                    11. / à matches the preciding RE but only it followed by the                                  following RE.
                 EXAMPLE:
                          0/1 àmatches ‘0’ in the string ‘01’ but would not match anything in                          the string ‘0’or ‘02’.
                          12. |  àeither this or that
                          13. (…)  àcombine more RE
                          14. \  àused to indicate that the character immediately to its right is to              be taken literally.
                          15. ”…..” àinterprete everything within the quotation mark literally                      character c escape sequence the last layer meaning.


                  FOR MORE:
                           ->EARN MORE MONY  
                           ->DOWNLOADS(SOFTWARE,HACKTOOLS,WALLPAPER,etc.,)


JOB VIRUS.COM






FORR


No comments:

Post a Comment