help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem about using flex


From: Ouyang Yingxiu
Subject: Problem about using flex
Date: Tue, 14 Mar 2006 00:22:28 +0800

Dear Sir:

Thank for your greate work for flex. I am a new man to flex, and I am learning 
to use your tool flex by reading the accompanying mannual provided by you.

I come to a problem that when I present my script to flex, it generate a 
surprise  code which turns out to the unexpected runtime result.

I try to modify the script by rearrange the line, BEGIN(FNAME), from bottom to 
elsewhere, and I get the correct run time result.

The version of Flex I am using now is 2.5, and the compile is visual studio.net 
2005 runing on window server 2003. The script is at the very end of the mail.

After successfully compiling the generated file, I run the exe file with the 
comand line "-f tmd.c -h". The result is "Use File Name: tmd.c '\n' Use File 
Name: -h" but not the wanted one "Use File Name: tmd.c '\n' Usage is: testlex 
[-help | -h | -?][-verbose | -v][(-file|-f) filename]", where "testlex" is the 
executable file  name on windows.

Can you help me?  Thanks for you help.

sincerely yours
        Ouyang Yingxiu
address@hidden
          2006-03-13


//////////////////////////////////Pcl.l/////////////////////////////////////////////////
%{
/* This demonstrate example  */
char *progName;
unsigned verbose;
%}
%x FNAME
%%
-h      |
"-?"    |
-help   {
            printf("Usage is: %s [-help | -h | -?][-verbose | -v]"
                   "[(-file|-f) filename]\n", progName);
         }
<FNAME>[^ ]+ {
                printf("Use File Name: %s\n", yytext); 
                BEGIN(INITIAL);
             }
-v      |
-verbose { printf("Verbose is off"); verbose = 1;}
.       | {printf("%s", yytext);ECHO;}
-f      |
-file   {BEGIN(FNAME);}

%%
int main(int argc, char **argv)
{
    char szCmdLine[200];
    int i=0;
    int len=0;
    progName = argv[0];
    memset(szCmdLine, 0, sizeof(szCmdLine));
    if (argc<2)
    {
        return 0;
    }
    
    for (i=0; i<argc-1; i++)
    {
        len += strlen(argv[i+1]);
        strcat(szCmdLine, argv[i+1]);
        szCmdLine[len++] = ' ';
        szCmdLine[len] = '\0';
    }
   yy_scan_string(szCmdLine);
   yylex();
}

int yywrap()
{
    return 1;
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]