regex - Lex: Avoid a quoted expression -


i'm trying build lex program should avoid quoted sequence of characters. not(":="). i've written far can't seem able desired output:

/* definitions */ assgn   ":=" symbol  [^{assgn}]  %% . ":="    {printf("found - %s\n",yytext);} {symbol}  {printf("error: unmatched symbol \'%s\'\n", yytext);} % 

input:

:= & | # 

output:

found - := error: unmatched symbol ':'  error: unmatched symbol '=' error: unmatched symbol '&' error: unmatched symbol '|' error: unmatched symbol '#' 

desired output:

found - := error: unmatched symbol '&' error: unmatched symbol '|' error: unmatched symbol '#' 

i want program avoids ":=" whole still reads single character ":". how correct this?

the following little complete (f)lex program precisely desired. flex not rescan matched token unless ask (or, of course, there undefined behaviour in code corrupts flex's internal data structures.)

%{   #include <stdio.h> %} %option nodefault noyywrap noinput nounput %%  [[:space:]]+    /* ignore spaces */ ":="            {printf("found - %s\n",yytext);} .               {printf("error: unmatched symbol \'%s\'\n", yytext);} 

with above file stored in only:=.l, following:

$ lex -o only:=.c only:=.l $ gcc -o only:= -wall only:=.c -lfl $ ./only:= := & | # found - := error: unmatched symbol '&' error: unmatched symbol '|' error: unmatched symbol '#' 

(-lfl adds minimal definition of main())


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -