-
-
Save yxy/7e10ed5af23c36b1a9d0 to your computer and use it in GitHub Desktop.
unix tool wc written in lex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
int nchar, nword, nline; | |
%} | |
%% | |
\n { nline++; nchar++ ;} | |
[^ \t\n]+ { nword++; nchar += yyleng; } | |
. { nchar++; } | |
%% | |
int main(int argc, char *argv[]) { | |
yyin = fopen(argv[1], "r"); | |
yylex(); | |
printf("%d\t%d\t%d\n", nchar, nword, nline); | |
fclose(yyin); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment