S
Steven T. Hatton
This is just idle curiosity. I was playing with this code from the Lex &&
Yacc book [http://www.oreilly.com/catalog/lex/], and discovered that it
does strange things with strings beginning with numbers.
$ cat example.l
%{
/*
* this sample demonstrates (very) simple recognition:
* a verb/not a verb.
*/
%}
%%
[\t ]+ /* ignore white space */ ;
is |
am |
are |
were |
was |
be |
being |
been |
do |
does |
did |
will |
would |
should |
can |
could |
has |
have |
had |
go { printf("%s: is a verb\n", yytext); }
[a-zA-Z]+ { printf("%s: is not a verb\n", yytext); }
..|\n { ECHO; /* normal default anyway */ }
%%
main()
{
yylex();
}
###############################
$ ls
example.l
$ flex example.l
$ ls
example.l lex.yy.c
$ gcc -o example lex.yy.c -lfl
$ ls
example example.l lex.yy.c
$ ./example
test
test: is not a verb
is
is: is a verb
is123
is: is a verb
123
123is
123is: is a verb
^D
C is actually older than Lex, but I suspect the techniques used to scan
early C code were similar to what was incorporated into Lex. Anybody know
about this?
Yacc book [http://www.oreilly.com/catalog/lex/], and discovered that it
does strange things with strings beginning with numbers.
$ cat example.l
%{
/*
* this sample demonstrates (very) simple recognition:
* a verb/not a verb.
*/
%}
%%
[\t ]+ /* ignore white space */ ;
is |
am |
are |
were |
was |
be |
being |
been |
do |
does |
did |
will |
would |
should |
can |
could |
has |
have |
had |
go { printf("%s: is a verb\n", yytext); }
[a-zA-Z]+ { printf("%s: is not a verb\n", yytext); }
..|\n { ECHO; /* normal default anyway */ }
%%
main()
{
yylex();
}
###############################
$ ls
example.l
$ flex example.l
$ ls
example.l lex.yy.c
$ gcc -o example lex.yy.c -lfl
$ ls
example example.l lex.yy.c
$ ./example
test
test: is not a verb
is
is: is a verb
is123
is: is a verb
123
123is
123is: is a verb
^D
C is actually older than Lex, but I suspect the techniques used to scan
early C code were similar to what was incorporated into Lex. Anybody know
about this?