Running the code below in iTerm2 bash. Code file was created using Vim.
/* just like Unix wc */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}
%%
[a-zA-Z]+ { words++; chars += strlen(yytext); }
{ chars++; lines++; }
. { chars++; }
%%
main(int argc, char **argv)
{
yylex();
printf("%8d%8d%8d
", lines, words, chars);
}
I ran commands
$flex fb1-1.1
$cc lex.yy.c -lfl
This is the error that it returns
fb1-1.1:17:1: warning: type specifier missing, defaults to 'int'
[-Wimplicit-int]
main(int argc, char **argv)
^
1 warning generated.
ld: library not found for -lfl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
EDIT: Works now. Changed the main() to
int main(int argc, char* argv[])
Also ran changed -lfl to -ll
$flex fb1-1.1
$cc lex.yy.c -ll
$./a.out
this is a text
^D
1 4 15
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…