- 论坛徽章:
- 0
|
第二章的ch2-05.l:
- %{
- #undef input
- #undef unput
- int input(void);
- void unput(int ch);
- unsigned verbose;
- char *progName;
- %}
- %%
- -h |
- "-?" |
- -help { printf("usage is: %s [-help | -h | -? ] [-verbose | -v]"
- " [(-file| -f) filename]\n", progName);
- }
- -v |
- -verbose { printf("verbose mode is on\n"); verbose = 1; }
- %%
- char **targv; /* remembers arguments */
- char **arglim; /* end of arguments */
- main(int argc, char **argv)
- {
- progName = *argv;
- targv = argv+1;
- arglim = argv+argc;
- yylex();
- }
- static unsigned offset = 0;
- int
- input(void)
- {
- char c;
- if (targv >= arglim)
- return(0); /* EOF */
- /* end of argument, move to the next */
- if ((c = targv[0][offset++]) != '\0')
- return(c);
- targv++;
- offset = 0;
- return(' ');
- }
- /* simple unput only backs up, doesn't allow you to */
- /* put back different text */
- void
- unput(int ch)
- {
- /* AT&T lex sometimes puts back the EOF ! */
- if(ch == 0)
- return; /* ignore, can't put back EOF */
- if (offset) { /* back up in current arg */
- offset--;
- return;
- }
- targv--; /* back to previous arg */
- offset = strlen(*targv);
- }
复制代码
$ flex ch2-05.l
Lichuang@LICHUANG /e/source/lex&&yacc
$ gcc lex.yy.c -lfl
lex.yy.c:514: warning: static declaration of 'input' follows non-static declaration
ch2-05.l:4: warning: previous declaration of 'input' was here
ch2-05.l:37: error: redefinition of 'input'
lex.yy.c:1096: error: previous definition of 'input' was here
环境是MSYS下的flex.
难道是lex和flex的有兼容问题?
 |
|