Schwierigkeiten während der Kompilation (g++, bison, flex) mit yyparse();

Ich habe ein problem mit der Zusammenstellung von meinem code:

Flex:

%{
#include "lista4.tab.hpp"
#include <stdlib.h>
extern int yylex();
%}
%%
"=" {return EQ;}
"!="    {return NE;}
"<" {return LT;}
">" {return GT;}
":="    {return ASSIGN;}
";" {return SEMICOLON;}
"IF"    {return IF;}
"THEN"{return THEN;}

"END" {return END;}
[_a-z]+ {yylval.text = strdup(yytext); return IDENTIFIER;}
[ \t]+
[0-9]+          {
                yylval.var = atoi (yytext);
                return NUMBER;
                }
[-+/^*'%'()]    {
                return *yytext;
                }
\n              return RESULT;
%%

Bison:

%{
  extern "C"
  {
    int yyparse();
    int yylex(void);
    void yyerror(char *s){}
    int yywrap(void){return 1;}
  }

  #include <iostream>
  #include <vector>
  #include <string>
  #include <stdlib.h>
  #include <map>

  using namespace std;

  vector <string> instructions;
  map <> vars;
%}

%union{
  char* text;
  int var;
}


%token EQ
%token NE
%token ASSIGN
%token SEMICOLON
%token IF
%token THEN
%token <text> IDENTIFIER
%token <var> NUMBER
%token <var> RESULT

%left '+' '-'
%left '*' '/' '%'
%right '^'

%%

exp: NUMBER
| IDENTIFIER
| IDENTIFIER "+" IDENTIFIER
| IDENTIFIER "-" IDENTIFIER
;
%%

int main(void){
  yyparse();
} 

- Und bash-Skript:

#!/bin/bash
clear
rm launcher lex.yy.cpp *.tab.cpp *.tab.hpp
bison  -d -o lista4.tab.cpp *.y
flex -o lex.yy.cpp *.l
g++ -o launcher *.cpp -lfl

Ich gepostet, hier nur der wichtigste Teil des Codes, weil der rest von Ihnen ist hier nicht notwendig. Wie auch immer, wenn jemand möchte sehen, wie ganze code, ich klebte es hier: http://pastebin.com/1rS2FBJj. Aber es ist ein wenig größer und braucht mehr Platz.

Als ich versucht habe, kompilieren alle mit *.c-Dateien, und dann, indem Sie gcc-es war alles in Ordnung. Aber wenn ich wechselte compiler g++ und cpp-Dateien bekomme ich diesen Fehler:

lista4.tab.cpp: In function 'int yyparse()': 
lista4.tab.cpp:1397: Warnung: deprecated conversion from string constant to 'char*' 
lista4.tab.cpp:1540: warning: deprecated conversion from string constant to 'char*' 
/tmp/ccdqpQVx.o: In Funktion `yyparse': 
lista4.tab.cpp:(.text+0x252): undefined reference to `yylex' 
collect2: ld zurückgegeben, 1 exit status 

Könnte jemand mir einen Tipp geben wie man es beheben?

  • Nicht gerade ein fix für das problem, aber -fno-const-strings loswerden der Warnung.
InformationsquelleAutor pidabrow | 2011-06-21
Schreibe einen Kommentar