Menu

Seeing Garbage When Trying To Use Bison

Help
2010-01-16
2012-07-26
  • Nathan Campos

    Nathan Campos - 2010-01-16

    Hello,

    I've downloaded just Bison of the GnuWin32 compiler pack, I've downloaded the
    setup without sources and all got right when installing, then I tried to test
    it with the simple rpcalc.y example:

    /* Reverse polish notation calculator. */
    
    %{
    #define YYSTYPE double
    #include <math.h>
    %}
    
    %token NUM
    
    %% /* Grammar rules and actions follow */
    input:    /* empty */
            | input line
    ;
    
    line:     '\n'
            | exp '\n'  { printf ("\t%.10g\n", $1); }
    ;
    
    exp:      NUM             { $$ = $1;         }
            | exp exp '+'     { $$ = $1 + $2;    }
            | exp exp '-'     { $$ = $1 - $2;    }
            | exp exp '*'     { $$ = $1 * $2;    }
            | exp exp '/'     { $$ = $1 / $2;    }
          /* Exponentiation */
            | exp exp '^'     { $$ = pow ($1, $2); }
          /* Unary minus    */
            | exp 'n'         { $$ = -$1;        }
    ;
    %%
    /* Lexical analyzer returns a double floating point 
       number on the stack and the token NUM, or the ASCII
       character read if not a number.  Skips all blanks
       and tabs, returns 0 for EOF. */
    
    #include <ctype.h>
    
    yylex ()
    {
      int c;
    
      /* skip white space  */
      while ((c = getchar ()) == ' ' || c == '\t')  
        ;
      /* process numbers   */
      if (c == '.' || isdigit (c))                
        {
          ungetc (c, stdin);
          scanf ("%lf", &yylval);
          return NUM;
        }
      /* return end-of-file  */
      if (c == EOF)                            
        return 0;
      /* return single chars */
      return c;                                
    }
    

    But when I've tried to use bison: C:> bison rpcalc.y, I just got a lot of
    garbage: http://nathanpc.pastebin.com/f2fae6710, it's too much big, then I've posted at pastebin.

    • Why is this happening?

    • What I need to do?

    • Have this already happened to you?

    Best Regards,

    Nathan Paulino Campos

     
  • Allan

    Allan - 2010-01-17

    I tried to reproduce this error using the source code you have posted and it
    worked perfectly on both Gnuwin and DJGPP 2.04 beta. Please state your MS
    Windows version and check the versions of m4 and bison. Are you running using
    the MS command window or some other shell? When you install the gnuwin
    packages are you installing all to the same folder or to different folders for
    each package. The way I install them all the .exe and .dll files are in the
    same `bin\' directory.

     
MongoDB Logo MongoDB