Lexical Analyzer using LEX

Program to design a Lexical Analyzer using LEX :

ALGORITHM :

  1. Start the program.
  2. Lex program consists of three parts.
    • Declaration %%
    • Translation rules %%
    • Auxilary procedure.
  3. The declaration section includes declaration of variables, maintest, constants and regular definitions.
  4. Translation rule of lex program are statements of the for
    • P1 {action}
    • P2 {action}
    •  …
    •  Pn {action}
  5. Write a program in the vi editor and save it with .l extension.
  6. Compile the lex program with lex compiler to produce output file as lex.yy.c.
    eg $ lex filename.l
    $ cc lex.yy.c -ll
  7. Compile that file with C compiler and verify the output.

C SOURCE CODE :

key.txt

int
void
main
char
if
for
while
else
printf
scanf
include
stdio.h
conio.h

oper.txt

( open para
) closepara
{ openbrace
} closebrace
< lesser
> greater
” doublequote
‘ singlequote
: colon
; semicolon
# preprocessor
= equal
== asign
% percentage
^ bitwise
& reference
* star
+ add
– sub
backslash

/ slash

input.c

OUTPUT :

lexical analyzer using LEX


Leave a Reply

Your email address will not be published. Required fields are marked *