I'm taking a class and trying to do some homework. I need to use flex and bison to parse some code.
The default type of YYSTYPE is int
, even though I never declared it that way. Is that a default from bison?
It would help me a lot to pass strings back. I read this: http://stackoverflow.com/questions/1014619/how-to-solve-bison-warning-has-no-declared-type This looks like a good approach. (I don't need the full power of a union yet, just the char* part, but I might as well use the union because it might be helpful later.)
It's not working for me. I get these errors:
y:111.37-38: $1 of `ConstExpression' has no declared type
y:113.34-35: $1 of `ConstFactor' has no declared type
y:114.35-36: $1 of `ConstFactor' has no declared type
y:119.34-35: $1 of `Type' has no declared type
y:109.23-48: warning: type clash on default action: <str> != <>
y:115.23-27: warning: type clash on default action: <str> != <>
[...more of the same snipped...]
Here are the declarations from my y
grammar file:
%union {
char *str;
}
%type<str> ConstExpression ConstFactor Type
Here is one line from my .l
file:
[a-zA-Z]+[a-zA-Z0-9]* { yylval.str = strdup(yytext); return yident;}
What else do I need to do to resolve the errors?