views:

143

answers:

1

Hi everybody!!!

I have a problem.

I'm writing a program with flex and I'm using this code:

%union {

    int entero;

    char *cadena;

    TipoDato tipo;

}

This code is for my data types.

I want evaluate the next line: expresion SUM expresion where SUM is the operation sum for evaluate, for example 69 + 60

When I write this

if (($1.tipo == ENT) && ($3.tipo == ENT)){

           $$.tipo = ENT;

} else if (($1.tipo == CADEN) && ($3.tipo == CADEN)) {

     $$.tipo = CADEN;

     } else {

          printf ("Error en la suma: Tipos de datos incompatibles Revise los tipos\n");

          yyerror(parser);

}

I have the next error

../src/buggy.y:350.37-38: $1 de `expresion' no tiene tipo declarado

../src/buggy.y:351.28-29: $1 de `expresion' no tiene tipo declarado

buggy.tab.c: In function ‘yyparse’:

buggy.tab.c:1646: warning: implicit declaration of function ‘yylex’

../src/buggy.y: At top level:

lex.yy.c:1577: warning: ‘yyunput’ defined but not used

lex.yy.c:1618: **warning: ‘input’ defined but not used

Leyendo fichero '../docs/prog1.bgy'.

What is the problem?

Thanks!

Bye!!

+1  A: 

These are all actually warnings, not errors, so your code should work despite them, but they are annoying. To get rid of the bison warnings, you need to use a %type declaration in the top section of your .y file. Somethings like %type <tipo> expression, and then you just refer to $1 and $3 and $$ in your action code (no .tipo suffix, which is automatically supplied by bison due to the %type).

To get rid of the compiler warning in buggy.tab.c, you need to declare yylex in your .y file; something like:

%{
extern int yylex();
%}

in the top section, assuming you don't #define YYLEX_PARAM

Getting rid of the compiler warnings from lex.yy.c is harder; your best bet is probably just to NOT use -Wall when compiling it, as the code generated by flex is not -Wall clean

edit

after some searching, it seems you can get rid of the warning about input by putting a #define YY_NO_INPUT in the top section of your .l file.

Chris Dodd