Reputation: 11
So, I'm very new to flex/bison but I need to write this parser to recognize a simple integer calculator and I was having trouble getting flex and bison to talk to each other.
Flex returns token values like it should and all, but I can't quite get it to actually return semantic values. This is my flex file:
%option noyywrap
%{
#include "test_Calc_Answer.tab.h"
#include <malloc.h>
#include <process.h>
#define fileno _fileno
%}
NUM [0-9]
%%
"{"[\^{}}]*"}"
[ \t]+
[\n] {
return (int)'\n';
}
"+" {
return (int)'+';
}
"-" {
return (int)'-';
}
"*" {
return (int)'*';
}
"/" {
return (int)'/';
}
{NUM}+ {
int i, value = 0;
for(i = yyleng-1; i>=0; i--)
value = 10*value + ( yytext[i] - '0' );
yyval = value;
return DIGIT;
}
%%
When I try compiling the generated code, I get a 'yyval undeclared' error. I noticed it is declared in the *.tab.h file so I can't understand what the problem could be. Tell me if I need to provide additional information...
Thanks, sorry for my noobness or if I re-asked a question.
Upvotes: 1
Views: 3509
Reputation: 27652
The variable for the lexical value is usually called yylval and not yyval, so that is almost certainly what the variable in your *.tab.h is called.
Upvotes: 3