⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lex生成工具生成统计文本.txt

📁 利用LEX生成工具生成统计文本文件中字符、单词和行数
💻 TXT
字号:
程序源代码:
%{
#include<stdio.h>
#include<ctype.h>
int chars=0;   
int words=0;  
int lines=1;   
%}
final [\t\n]                                   /*定义正则表达式*/
letter [A-Za-z]
digit [0-9]
word ({letter}|{digit})+

%%
{final}             {lines++;}                /*行数+1*/                     
{letter}              {chars++;}  
{digit}              {chars++;}               /*字符+1*/
{word}              {words++; chars+=yyleng; } /*word时单词数和字符数同时+1*/

%%
void main()
{
    yylex();
    printf("the numbers of the line is %d\n",lines);    
    printf("the numbers of the word is %d\n",words); 
    printf("the numbers of the char is %d\n",chars); 
}
int yywrap()
{  
   return 1;
}

程序输出测试:
输入:i:integer
      J:integer
输出:the number of the line is 2
      the number of the word is 4
      the number of the char is 20

⌨️ 快捷键说明

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