Sample lex code - lexcode.l
%{ //definition section #include <stdio.h> %} %% //rules section [0123456789]+ printf("NUMBER\n"); [a-zA-Z][a-zA-Z0-9]* printf("WORD\n"); %% //user subroutings
Compilation
lex lexcode1.l
Creates lex.yy.c
cc lex.yy.c -o lexcode1 -lfl
Execution
./lexcode1
Sample inputs and their outputs
foo
WORD
bar
WORD
123
NUMBER
bar123
WORD
123bar
NUMBER
WORD
No comments :
Post a Comment