📄 wordcount2.l
字号:
%{{* 下面的例子改编自lex和yacc第二版 对单词计数,并可以统计多个文件 编译:lex wordcount2 wordcnt2.dpr 用法: wordcnt2 或者 wordcnt2 wordcount.l wordcount2.l *} program WordCnt2;{$APPTYPE CONSOLE}uses SysUtils, LexLib;var CharCount, WordCount, LineCount:integer; CurrentFile:integer;//重定义yywrap,来实现对EOF的重新处理function yywrap: Boolean;begin if (CurrentFile<=ParamCount) then begin if CurrentFile>1 then begin Writeln(format('字符数:%d 单词数:%d 行数:%d', [CharCount, WordCount, LineCount])); CharCount:=0; WordCount:=0; LineCount:=0; end; if not FileExists(ParamStr(CurrentFile)) then begin Writeln('无法打开输入文件'); Halt; end; AssignFile(yyinput, ParamStr(CurrentFile)); Reset(yyinput); inc(CurrentFile); //close(yyinput); //close(yyoutput); result := false;//返回false,表示还有一个文件要处理 end else begin Writeln(format('字符数:%d 单词数:%d 行数:%d', [CharCount, WordCount, LineCount])); close(yyinput); close(yyoutput); result:=true; end;end (*yywrap*);%}word [^ \t\n]+eol \n%%{word} begin inc(WordCount); inc(CharCount,yyleng); end;{eol} begin inc(CharCount); inc(LineCount); end;. inc(CharCount);%%begin if paramcount >1 then begin CurrentFile:=1; yywrap; end; yylex; readln;end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -