CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    32

    [RESOLVED] flex "flex scanner push-back overflow"

    flex is happy when i run "flex scanner.l", but returns the error "flex scanner push-back overflow" when i run "flex new_scanner.l"

    here are the files:

    scanner.l:
    Code:
    /* scanner for a toy Pascal-like language */
    %{
    #include <math.h> /* needed for call to atof() */
    %}
    DIG [0-9]
    ID    [a-z][a-z0-9]*
    %%
    {DIG}+                  printf("Integer: %s (%d)\n", yytext, atoi(yytext));
    {DIG}+"."{DIG}*         printf("Float: %s (%g)\n", yytext, atof(yytext)); 
    if|then|begin|end       printf("Keyword: %s\n",yytext);
    "("                     printf("Open paren\n");
    ")"                     printf("Close paren\n");
    {ID}                    printf("Identifier: %s\n",yytext);
    "+"|"-"|"*"|"/"         printf("Operator: %s\n",yytext); 
    ">"|"<"                 printf("Relational operator: %s\n",yytext); 
    "{"[^}\n]*"}"           /* skip one-line comments */
    [ \t\n]+                /* skip whitespace */
    .                       printf("UNRECOGNIZED: %s\n",yytext); 
    %%
    main(){ yylex(); }
    new_scanner.l:
    Code:
    /* scanner for a toy Pascal-like language */
    %{
    #include <math.h> /* needed for call to atof() */
    %}
    DIG [0-9]
    ID    [a-z][a-z0-9]*
    VAL {DIG}+"."?{DIG}*|{ID}
    SP [ \t\n]*
    EXP {EXP}{SP}("+"|"-"|"*"|"/"){SP}{VAL}|{VAL}
    %%
    {EXP}{SP}(">"|"<"){SP}{EXP} printf("Conditional: %s\n", yytext);
    {DIG}+                  printf("Integer: %s (%d)\n", yytext, atoi(yytext));
    {DIG}+"."{DIG}*         printf("Float: %s (%g)\n", yytext, atof(yytext)); 
    if|then|begin|end       printf("Keyword: %s\n",yytext);
    "("                     printf("Open paren\n");
    ")"                     printf("Close paren\n");
    {ID}                    printf("Identifier: %s\n",yytext);
    "+"|"-"|"*"|"/"         printf("Operator: %s\n",yytext); 
    ">"|"<"                 printf("Relational operator: %s\n",yytext); 
    "{"[^}\n]*"}"           /* skip one-line comments */
    [ \t\n]+                /* skip whitespace */
    .                       printf("UNRECOGNIZED: %s\n",yytext); 
    %%
    main(){ yylex(); }
    I tried ignoring the error, since lex.yy.c was still created, and entered "cc lex.yy.c -lfl", but I get the error:
    Code:
    /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libfl.a(libmain.o): In function `main':
    (.text+0x21): undefined reference to `yylex'
    collect2: ld returned 1 exit status
    If it helps, I'm accessing the linux account via ssh (copied the error message from the putty.log). I'm just entering these commands into the command line and editing the files with emacs. I have a very limited access to the system, and I don't know how to get rid of that error. I need to add those lines for the project.
    Last edited by Nim; October 14th, 2009 at 01:02 PM.

  2. #2
    Join Date
    Feb 2009
    Posts
    32

    Re: flex "flex scanner push-back overflow"

    This is screwed up. I've narrowed the issue down to one line in new_scanner.l:
    Code:
    EXP {EXP}{SP}("+"|"-"|"*"|"/"){SP}{VAL}|{VAL}
    I ruled it further down to the recursive definition! I don't understand, and I must less care. I rewrote it without the {EXP} and now it works!
    Code:
    BINOP "+"|"-"|"*"|"/"
    EXP_END ({SP}{BINOP}{SP}{VAL})*
    and I rewrote the conditional regex:
    Code:
    {VAL}{EXP_END}{SP}(">"|"<"){SP}{VAL}{EXP_END}
    win.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured