forked from mbbill/flexbison
-
Notifications
You must be signed in to change notification settings - Fork 10
/
fb2-1.l
39 lines (31 loc) · 760 Bytes
/
fb2-1.l
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
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Companion source code for "flex & bison", published by O'Reilly
* Media, ISBN 978-0-596-15597-1
* Copyright (c) 2009, Taughannock Networks. All rights reserved.
* See the README file for license conditions and contact info.
* $Header: /home/johnl/flnb/code/RCS/fb2-1.l,v 2.1 2009/11/08 02:53:18 johnl Exp $
*/
/* fb2-1 even more like unix wc with explicit input */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}
%%
[a-zA-Z]+ { words++; chars += strlen(yytext); }
\n { chars++; lines++; }
. { chars++; }
%%
main(argc, argv)
int argc;
char **argv;
{
if(argc > 1) {
if(!(yyin = fopen(argv[1], "r"))) {
perror(argv[1]);
return (1);
}
}
yylex();
printf("%8d%8d%8d\n", lines, words, chars);
}
yywrap() { return 1; }