I have a problem compiling my 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(); }
And bash script:
I have placed here only the most important part of the code, because the rest of them are not needed here. In any case, if someone wants to see the whole code, I inserted it here: http://pastebin.com/1rS2FBJj . But it is a little bigger and takes up more space.
When I tried to compile all the * .c files and then gcc, everything was fine. But when I switched the compiler to g ++ and the files to cpp, I get this error:
lista4.tab.cpp: In function 'int yyparse ()':
lista4.tab.cpp: 1397: warning: deprecated conversion from string constant to 'char *'
lista4.tab.cpp: 1540: warning: deprecated conversion from string constant to 'char *'
/tmp/ccdqpQVx.o: In function `yyparse ':
lista4.tab.cpp :(. text + 0x252): undefined reference to `yylex '
collect2: ld returned 1 exit status
Can someone give me advice on how to fix it?
source share