%{
unsigned long charCount=0, wordCount=0, lineCount=0;
%}
word [^ \t\n]+
eol \n
%%
{word} { wordCount++; charCount+=yyleng; }
{eol} {charCount++; lineCount++; }
. {charCount++;}
%%
int main(void)
{
FILE *file;
char fn[20];
printf("Type a ipnut file Name:");
scanf("%s",fn);
file=fopen(fn, "r");
if (!file) {
fprintf(stderr,"file '%s' could not be opened. \n",fn);
exit(1);
}
yyin=file;
yylex();
printf("%d %d %d %s \n", lineCount, wordCount, charCount,fn);
return 0;
}
yywrap() { return 1; }
'노트 > 소스 코드' 카테고리의 다른 글
| [R] Co-occurrence Matrix (0) | 2016.02.09 |
|---|---|
| [Java] Polynomials with integer coefficients (0) | 2016.01.18 |
| [C] Multi Thread Server Example (0) | 2011.12.28 |
| [Java] Twitter Capturer (with JSON) (NOT BRUSH) (0) | 2011.12.28 |
| [C++] Dijkstra Algorithm (NOT BRUSH) (0) | 2011.12.28 |
| [C] English Morpheme Analyzer (With Lex) (0) | 2011.12.28 |
| [Java] Simple Thread Example - Horse Race (0) | 2011.12.28 |
| [JavaScript] Layer Popup Example (0) | 2011.12.28 |
| [Java] Notepad (0) | 2011.12.28 |
| [Java] RSS Reader (0) | 2011.12.28 |