Hola, estoy usando una api c (que la probe con un archivo punto .c y funciona bien), pero la quiero usar en bison, para poder sacar formulas de una tabla y luego poder analizarlas.
Mi codigo es el siguiente:
%{
#define YYSTYPE double
#include <math.h>
%}
/* BISON Declarations */
%token NUM
%left '-' '+'
%left '*' '/'
%left NEG /* negation--unary minus */
%right '^' /* exponentiation */
/* Grammar follows */
%%
input: /* empty string */
| input line
;
line: '\n'
| exp '\n' { printf ("\t%.10g\n", $1); }
| error '\n' { yyerrok; }
;
exp: NUM { $$ = $1; }
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
| exp '/' exp { $$ = $1 / $3; }
| '-' exp %prec NEG { $$ = -$2; }
| exp '^' exp { $$ = pow ($1, $3); }
| '(' exp ')' { $$ = $2; }
;
%%
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
/* error handling function */
int yyerror (char *s) {
printf("pepe %s\n", s);
return 0;
}
int main (int argc,char *argv[]) {
int c;
char nombre[80];
int valor1;
int valor2;
int valor3;
c = argc;
yyparse();
};
#include <stdio.h>
#include <mysql.h>
int main2 (int argc, char *argv[]) {
MYSQL *dbase;
MYSQL *mysql;
int result = 0;
int legajo1;
int legajo2;
dbase=mysql_init(mysql);
dbase->reconnect=1;
char *server="127.0.0.1";
char *user="root";
char *password="";
char *database="fullahead";
MYSQL *mysql_init(MYSQL *mysql);
if (!mysql_real_connect(dbase, server, user, password, database, 0, NULL, 0) ) {
printf("Notificacion: %s",mysql_error(dbase));
printf("\n\n Recuerda el uso es: %s host db user password\n\n",argv[0]);
return(-1);
} else {
printf("OK conexion establecida!!");
#define PEPITO 260
char *query;
query = (char *) malloc( PEPITO);
sprintf(query,"select * from hbr_conceptos where csc_id ='%s'", argv[4]);
mysql_real_query(dbase,query,strlen(query));
MYSQL_RES *res = mysql_store_result(dbase);
MYSQL_ROW row;
while ((row = mysql_fetch_row(res)))
{
printf("%s - %s -%s -%s \n", row[0], row[1], row[2], row[19]);
}
}}
Yo compilo así:
cc lex.yy.c Mesclando.tab.c -o Mescla -lfl –lm
Pero no se si lo estoy haciendo bien, los errores que me da son los siguientes:
Mesclando.y:65:19: mysql.h: No such file or directory
Mesclando.y: In function `main2':
Mesclando.y:68: error: `MYSQL' undeclared (first use in this function)
Mesclando.y:68: error: (Each undeclared identifier is reported only once
Mesclando.y:68: error: for each function it appears in.)
Mesclando.y:68: error: `dbase' undeclared (first use in this function)
Mesclando.y:69: error: `mysql' undeclared (first use in this function)
Mesclando.y
error: `MYSQL_RES' undeclared (first use in this function)
Mesclando.y
error: `res' undeclared (first use in this function)
Mesclando.y
error: `MYSQL_ROW' undeclared (first use in this function)
Mesclando.y
error: syntax error before "row"
Mesclando.y
error: `row' undeclared (first use in this function)
Como los tengo que definir?? Porque en C no me tira esos errores, ya están definidas en realidad..Gracias, espero ayuda!