%{ #include "iburg.h" #include "y.tab.h" static int braces = 0; %} %option warn %option nodefault %option noyywrap %option yylineno %x CSTRING %x ECHO %% "%{" { printlineno(); BEGIN(ECHO); } "%}" BEGIN(INITIAL); [%\n] fputc(yytext[0], outfp); [^%\n]* fputs(yytext, outfp); "{" { yylval.string = stringf("#line %d\n", yylineno); braces = 1; BEGIN(CSTRING); return CFRAGMENT; } "{" { braces++; yylval.string = strdup(yytext); return CFRAGMENT; } "}" { braces--; if (braces == 0) BEGIN(INITIAL); else { yylval.string = strdup(yytext); return CFRAGMENT; } } [^{}]+ { yylval.string = strdup(yytext); return CFRAGMENT; } "%%" return PPERCENT; "%term" return TERMINAL; "%start" return START; "PATTERNS" return PATTERNS; "pat" return PAT; "when" return WHEN; "emit" return EMIT; "cost" return COST; [A-Za-z_][A-Za-z0-9_]* { yylval.string = strdup(yytext); return ID; } [0-9]+ { yylval.n = atoi(yytext); return INT; } [ \t\r\n]* ; . return yytext[0]; %% /* vim: set sw=4 ts=4 expandtab : */