mardi 20 septembre 2016

My lex pattern doesn't work to match my input file, how to correct it?

I've got a simple pattern to match: head+content+tail, I've got a lex file like below:

$ cat b.l
%{
#include<stdio.h>
%}
%%
"12" {printf("head\n");}
"34" {printf("tail\n");}
.* {printf("content\n");}
%%

I hope when meeting "12" it will print "head", when meet "34" it will print "tail", any other contiguous string, it will print "content".

So I compile and run it:

lex b.l && gcc lex.yy.c -ll
$ echo '12sdaesre34'|a.out
content

My expectation is, it will print

head
content
tail

But actually it prints only "content" line. Did I get anything wrong, how to correct it?

Thanks!

Aucun commentaire:

Enregistrer un commentaire