1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| /*
* Sample Scanner1:
* Description: Replace the string "username" from standard input
* with the user's login name (e.g. lgao)
* Usage: (1) $ flex sample1.lex
* (2) $ gcc lex.yy.c -lfl
* (3) $ ./a.out
* stdin> username
* stdin> Ctrl-D
* Question: What is the purpose of '%{' and '%}'?
* What else could be included in this section?
*/
%{
/* need this for the call to getlogin() below */
#include <unistd.h>
%}
%%
username printf("%s\n", getlogin());
%%
main()
{
yylex();
} |
Partager