使用lex进行简单的变量赋值

时间:2015-07-29 22:14:48

标签: regex lex

我有一个配置文件如下。

e_type=15                                                                                                                                                                           
HID=h_ID

我使用以下lex文件来识别模式。

%选项noyywrap

%{

#include <stdio.h>
#include <stdlib.h>

%}

%%
e_type=[0-9]+               { printf("Keyword: %s\n", yytext);}
[^\t\n\r]                     {   }   
%%

int main(int argc,char **argv)
{
    if(argc > 1)
    {   
        FILE *file;
        file = fopen(argv[1], "r");
        if(!file)
        {
            fprintf(stderr, "Could not open %s \n", argv[1]);
            exit(1);
        }
        yyin = file;
    }   
    yylex();
}

我按如下方式编译程序

 flex test.l ; gcc lex.yy.c -o test

我运行程序。

./test tmp.conf 

我得到的输出是

Keyword: e_type=15

我想将15的值分开并将其分配给变量。我该怎么做。

0 个答案:

没有答案