wc.l

来自「WINDOW版的YACC編譯軟體」· L 代码 · 共 28 行

L
28
字号
/*
 *	word count, WC - the program. simple standalone PCLEX application.
 */

%{
#include <stdlib.h>
static unsigned nchar = 0;	/* # of characters in file */
static unsigned nword = 0;	/* # of words in file */
static unsigned nline = 1;	/* # of lines in file */
%}

%%

\n              nchar += 2, ++nline;	/* line boundary in MS-DOS is CR LF */

[^ \t\n]+       ++nword, nchar += yyleng;

.               ++nchar;

%%

main()
{
  yylex();
  printf( "%d\t%d\t%d\n", nchar, nword, nline );
  exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?