xref: /netbsd-src/external/bsd/flex/dist/examples/manual/yymore2.lex (revision 3c3a7b7603b4ed4cb76dd5c5a3e781ddca2349bb)
1 /*
2  * yymore.lex: An example of using yymore()
3  *             to good effect.
4  */
5 
6 %{
7 #include <memory.h>
8 
yyerror(char * message)9 void yyerror(char *message)
10 {
11   printf("Error: %s\n",message);
12 }
13 
14 %}
15 
16 %x STRING
17 
18 %%
19 \"   BEGIN(STRING);
20 
21 <STRING>[^\\\n"]*  yymore();
22 <STRING><<EOF>>    yyerror("EOF in string.");       BEGIN(INITIAL);
23 <STRING>\n         yyerror("Unterminated string."); BEGIN(INITIAL);
24 <STRING>\\\n      {
25                      bcopy(yytext,yytext+2,yyleng-2);
26                      yytext += 2; yyleng -= 2;
27                      yymore();
28                   }
29 <STRING>\"        {
30                      yyleng -= 1; yytext[yyleng] = '\0';
31                      printf("string = \"%s\"",yytext); BEGIN(INITIAL);
32                   }
33 %%
34