如何分隔条件并重新启动输入文件

时间:2019-04-25 03:36:00

标签: c flex-lexer lex

我要讲的第一点是计算单词,字母和行数,然后将输入文本修改为输出文本,然后考虑开始使用。例如对于计数部分将称为“ 1”,然后

<one> word countword++;
<one> character countcharacter++;
<one> line countline++;
<two> something;

//I have what I want to do but the problem is that it does everything together
//We need separate in conditions
%{
#include <stdio.h>
#include <stdlib.h>
int nCar=0, nPal=0, nLin=0 , num=0;
FILE* file;
%}
word[ ^\t\n]+
endLin   \n
%%
^#.*$ ;
{word} {nPal++;REJECT;}
[ ] {nCar++;fprintf(file, " ");}
[ ]+ {fprintf(file, " ");}
[\t] {nCar++;}
[\t]+ {fprintf(file, "\t");}
[;] {nCar++;fprintf(file, "\n");}
[ñ] {nCar++;fprintf(file, "G");}
[a] {nCar++;fprintf(file, "C");}
{endLin}  {nCar++;nLin++;fprintf(file, "\n");}
. {nCar++;fprintf(file, "%s", yytext);}

0 个答案:

没有答案