In some version of linux (e.g., Mandrake) lex is called flex.
main() in your code, put the following line at
the beginning of your lex specification file:
%option main
This makes sure that a default main() and yywrap() are created for you.
lex example.l
gcc -o example lex.yy.c
./example
yywrap() in your code. In the
simplest case, your lex specification file should look like the
following:
...definitions...
%%
...rules...
%%
...additional user code...
main() {
yylex();
}
int yywrap() { return 1; }
You can compile your specification file with the same method as
before.
...definitions...
%%
...rules...
%%
...additional user code...
int yywrap() { return 1; }
...declarations...
%%
...rules...
%%
...additional user code...
main() {
return yyparse();
}
int yyerror( char *s ) { fprintf( stderr, "%s\n", s); }
...declarations...
%%
...rules...
%%
#include "lex.yy.c"
...additional user code...
main() {
return yyparse();
}
int yyerror( char *s ) { fprintf( stderr, "%s\n", s); }
lex example.l
yacc example.y
gcc -o example y.tab.c
./example