flex et bison: g++ erreur de compilation

Je suis en train de compiler les scanner et de l'analyseur pour le jouet de la langue à l'aide de g++. Voici le code pour chaque fichier que j'utilise (si vous le souhaitez, je peux poster à pastebin ou n'importe où ailleurs).

caesar.ll

/* Simple scanner for a Caesar language */
%{
#include "caesar.tab.h"
#include <iostream>
#include <string>
int chars = 0;
int words = 0;
int lines = 0;
%}
/* Define constants */
OWS            [" "\t]*
COMMA          {OWS}","{OWS}
ID             [A-Za-z_][A-Za-z0-9_]*
INT            ([0-9]+)|("0x"[A-Ha-h0-9]+)
FLOAT          [0-9]+"."[0-9]+
BSTREAM        b[\'\"].*[\'\"]
USTREAM        u?[\'\"].*[\'\"]
ARRAY          {LBRACE}({INT}|{FLOAT})({COMMA}({INT}|{FLOAT})){RBRACE}
LIST           {LBRACKET}.*({COMMA}.*){RBRACKET}
RANGE          {LBRACE}{INT}":"{INT}(":"{INT})?{RBRACE}
ARGS           {ID}({COMMA}{ID})*
LPARENTHESIS   "("{OWS}
RPARENTHESIS   {OWS}")"
LBRACE         "{"{OWS}
RBRACE         {OWS}"}"
LBRACKET       "["{OWS}
RBRACKET       {OWS}"]"
%%
%{
/*============================================================================*/
/* Define types */
/*============================================================================*/
%}
{INT} {
cout << "int: " << yytext << endl;
yylval = atoi(yytext);
return INT;
} /* int type */
{FLOAT} {
cout << "float: " << yytext << endl;
yylval = atof(yytext);
return FLOAT;
} /* float type */
{BSTREAM} {
cout << "bstream: " << yytext << endl;
return BSTREAM;
} /* bstream type */
{USTREAM} {
cout << "ustream: " << yytext << endl;
return USTREAM;
} /* ustream type */
%{
/*============================================================================*/
/* Define operators */
/*============================================================================*/
%}
"+"    { return ADD; }
"-"    { return SUB; }
"*"    { return MUL; }
"/"    { return DIV; }
"//"   { return FDIV; }
"|"    { return ABS; }
"\n"   { return EOL; }
%{
/*============================================================================*/
/* Define statements */
/*============================================================================*/
%}
{RANGE} {
cout << "range: " << yytext << endl;
return RANGE;
} /* range function */
%%

caesar.yy

/* Simple parser for a Caesar language */
%{
#include <iostream>
using namespace std;
%}
/* Define built-in types */
%token INT FLOAT BSTREAM USTREAM 
%token ADD SUB MUL DIV FDIV ABS
%token EOL
%%
calclist: /* nothing */
| calclist exp EOL {
cout << $2 << endl;
}
| calclist EOL {
cout << ">>> ";
}
;
exp: factor
| exp ADD exp { $$ = $1 + $3; }
| exp SUB factor { $$ = $1 - $3; }
| exp ABS factor { $$ = $1 | $3; }
;
factor: term
| factor MUL term { $$ = $1 * $3; }
| factor DIV term { $$ = $1 / $3; }
;
term: INT
| ABS term { $$ = $2 >= 0? $2 : - $2; }
;
%%
main()
{
cout << ">>> ";
yyparse();
}
yyerror(char *error)
{
cerr << error;
}

Makefile

caesar: caesar.ll caesar.yy
bison -d caesar.yy
flex caesar.ll
g++ -o $@ caesar.tab.cc lex.yy.c -lfl

Quand j'essaie de le compiler en utilisant make, je vois quelques erreurs:

bison -d caesar.yy
caesar.yy: conflicts: 3 shift/reduce
flex caesar.ll
g++ -o caesar caesar.tab.cc lex.yy.c -lfl
caesar.tab.cc: In function 'int yyparse()':
caesar.tab.cc:1281:16: error: 'yylex' was not declared in this scope
caesar.tab.cc:1470:35: error: 'yyerror' was not declared in this scope
caesar.tab.cc:1612:35: error: 'yyerror' was not declared in this scope
caesar.yy: At global scope:
caesar.yy:46:20: error: ISO C++ forbids declaration of 'yyerror' with no type [-fpermissive]
caesar.ll:3:24: fatal error: caesar.tab.h: No such file or directory
compilation terminated.
make: *** [caesar] Error 1

Pourriez-vous m'aider, s'il vous plaît? Merci!

Mise à JOUR: j'ai déjà correction d'une erreur avec les mauvais type de fonction.

  • Ne même pas essayer d'y faire il compile en C++. Le C et le C++ sont deux langues distinctes.
InformationsquelleAutor ghostmansd | 2012-10-22