Menu

#6 Syntax error, unexpected TOKEN, expecting $end  Edit

2.0
wont-fix
nobody
1 (9)
2018-10-12
2016-09-15
Anonymous
No

Hello Alex,

I've got another question.
I have defined my grammar in the lex file:

%% 

[0-9]+\.[0-9]       {
                        yylval.fval = atof(yytext);
                        return T_FLOAT;
                    }

\n                  {
                        std::cout << "Found a linebreak" << std::endl;
                    }
%%

My token handling in the .y file (I use verbose error ouput with '%error-verbose'):

%union {
    int ival;
    float fval;
    char *sval;
}

// Define the tokens with their data type.
%token <fval> T_FLOAT
%token <sval> T_STRING 

%%
group_float:
    T_FLOAT 
    {
        std::cout << " A float was found:" << $1 << std::endl;
    } 
;

group_string:
    T_STRING 
    {
        std::cout << "A string was found: " << $1 << std::endl;
    }

;
%%

After compiling and pressing 'Debug' I receive an error with the following description:
> Parse error! syntax error, unexpected T_FLOAT, expecting $end

My input file:

1.2
5.6

The output on the console can be seen in the attachment.

Can you tell me why the parser does not go to the next token it receives (the second float value) after it prints the linebreak?

Thanks
Sebastian

2 Attachments

Discussion

1 2 3 4 > >> (Page 1 of 4)
  • Alex Zhondin

    Alex Zhondin - 2016-09-16

    Actually I'm not familiar with flex/bison syntax.
    Try to find solution or ask your question on stackoverflow, googling really helped me when I digged in flex/bison stuff several years ago.

     
  • Anonymous

    Anonymous - 2016-09-16

    Hi Alex, I found an explanation for this behaviour here:
    http://www.4answered.com/questions/view/1a4f2a0/Expecting-end-after-first-input

    One has to write a complete context free grammar, then the result is as desired!

    Thank for your advices,
    Sebastian

     

    Last edit: Anonymous 2018-10-12
  • Alex Zhondin

    Alex Zhondin - 2016-09-16
    • status: open --> closed
     
  • Anonymous

    Anonymous - 2018-10-12
    • labels: --> 1
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     Hello Alex,
    
    -I've got another question.
    +I've got another question.
     I have defined my grammar in the lex file:
    
     ~~~
    @@ -12,12 +12,12 @@
                        }
    
     \n                 {
    -                       std::cout << "Found a linebreak" << std::endl;
    +                       std::cout &lt;&lt; &#34;Found a linebreak&#34; &lt;&lt; std::endl;
                        }
     %%
     ~~~
    
    -My token handling in the .y file (I use verbose error ouput with '%error-verbose'):
    +My token handling in the .y file (I use verbose error ouput with &#39;%error-verbose&#39;):
     ~~~
     %union {
        int ival;
    @@ -26,29 +26,29 @@
     }
    
     // Define the tokens with their data type.
    -%token <fval> T_FLOAT
    -%token <sval> T_STRING 
    +%token &lt;fval&gt; T_FLOAT
    +%token &lt;sval&gt; T_STRING 
    
     %%
     group_float:
        T_FLOAT 
        {
    -       std::cout << " A float was found:" << $1 << std::endl;
    +       std::cout &lt;&lt; &#34; A float was found:&#34; &lt;&lt; $1 &lt;&lt; std::endl;
        } 
     ;
    
     group_string:
        T_STRING 
        {
    -       std::cout << "A string was found: " << $1 << std::endl;
    +       std::cout &lt;&lt; &#34;A string was found: &#34; &lt;&lt; $1 &lt;&lt; std::endl;
        }
    
     ;
     %%
     ~~~
    
    -After compiling and pressing 'Debug' I receive an error with the following description:
    -> Parse error! syntax error, unexpected T_FLOAT, expecting $end
    +After compiling and pressing &#39;Debug&#39; I receive an error with the following description:
    +&gt; Parse error! syntax error, unexpected T_FLOAT, expecting $end
    
     My input file:
     ~~~
    
    • status: closed --> unread
    • Attachments has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +1,2 @@
    +acunetix.txt (0 Bytes; text/plain)
     console_output.PNG (2.1 kB; image/png)
    
     
  • Anonymous

    Anonymous - 2018-10-12
    • labels: --> 1
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     Hello Alex,
    
    -I've got another question.
    +I&#39;ve got another question.
     I have defined my grammar in the lex file:
    
     ~~~
    @@ -12,12 +12,12 @@
                        }
    
     \n                 {
    -                       std::cout << "Found a linebreak" << std::endl;
    +                       std::cout &lt;&lt; &#34;Found a linebreak&#34; &lt;&lt; std::endl;
                        }
     %%
     ~~~
    
    -My token handling in the .y file (I use verbose error ouput with '%error-verbose'):
    +My token handling in the .y file (I use verbose error ouput with &#39;%error-verbose&#39;):
     ~~~
     %union {
        int ival;
    @@ -26,29 +26,29 @@
     }
    
     // Define the tokens with their data type.
    -%token <fval> T_FLOAT
    -%token <sval> T_STRING 
    +%token &lt;fval&gt; T_FLOAT
    +%token &lt;sval&gt; T_STRING 
    
     %%
     group_float:
        T_FLOAT 
        {
    -       std::cout << " A float was found:" << $1 << std::endl;
    +       std::cout &lt;&lt; &#34; A float was found:&#34; &lt;&lt; $1 &lt;&lt; std::endl;
        } 
     ;
    
     group_string:
        T_STRING 
        {
    -       std::cout << "A string was found: " << $1 << std::endl;
    +       std::cout &lt;&lt; &#34;A string was found: &#34; &lt;&lt; $1 &lt;&lt; std::endl;
        }
    
     ;
     %%
     ~~~
    
    -After compiling and pressing 'Debug' I receive an error with the following description:
    -> Parse error! syntax error, unexpected T_FLOAT, expecting $end
    +After compiling and pressing &#39;Debug&#39; I receive an error with the following description:
    +&gt; Parse error! syntax error, unexpected T_FLOAT, expecting $end
    
     My input file:
     ~~~
    
    • status: closed --> open
     
  • Anonymous

    Anonymous - 2018-10-12
    • labels: --> 1
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     Hello Alex,
    
    -I've got another question.
    +I&#39;ve got another question.
     I have defined my grammar in the lex file:
    
     ~~~
    @@ -12,12 +12,12 @@
                        }
    
     \n                 {
    -                       std::cout << "Found a linebreak" << std::endl;
    +                       std::cout &lt;&lt; &#34;Found a linebreak&#34; &lt;&lt; std::endl;
                        }
     %%
     ~~~
    
    -My token handling in the .y file (I use verbose error ouput with '%error-verbose'):
    +My token handling in the .y file (I use verbose error ouput with &#39;%error-verbose&#39;):
     ~~~
     %union {
        int ival;
    @@ -26,29 +26,29 @@
     }
    
     // Define the tokens with their data type.
    -%token <fval> T_FLOAT
    -%token <sval> T_STRING 
    +%token &lt;fval&gt; T_FLOAT
    +%token &lt;sval&gt; T_STRING 
    
     %%
     group_float:
        T_FLOAT 
        {
    -       std::cout << " A float was found:" << $1 << std::endl;
    +       std::cout &lt;&lt; &#34; A float was found:&#34; &lt;&lt; $1 &lt;&lt; std::endl;
        } 
     ;
    
     group_string:
        T_STRING 
        {
    -       std::cout << "A string was found: " << $1 << std::endl;
    +       std::cout &lt;&lt; &#34;A string was found: &#34; &lt;&lt; $1 &lt;&lt; std::endl;
        }
    
     ;
     %%
     ~~~
    
    -After compiling and pressing 'Debug' I receive an error with the following description:
    -> Parse error! syntax error, unexpected T_FLOAT, expecting $end
    +After compiling and pressing &#39;Debug&#39; I receive an error with the following description:
    +&gt; Parse error! syntax error, unexpected T_FLOAT, expecting $end
    
     My input file:
     ~~~
    
    • status: closed --> accepted
     
  • Anonymous

    Anonymous - 2018-10-12
    • status: open --> pending
     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12
    • status: pending --> closed
     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12
    • status: closed --> open
    • Milestone: 1.0 --> 2.0
     
  • Anonymous

    Anonymous - 2018-10-12
    • status: closed --> unread
    • Milestone: 1.0 --> 2.0
     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12
    • status: unread --> pending
     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12
    • status: closed --> wont-fix
     
  • Anonymous

    Anonymous - 2018-10-12
    • status: pending --> closed
     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
  • Anonymous

    Anonymous - 2018-10-12
    • status: unread --> accepted
     
  • Anonymous

    Anonymous - 2018-10-12

    1

     
1 2 3 4 > >> (Page 1 of 4)

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.