So I've got a Bison rule that looks like this:
VAR ID ':' INT '=' intexp ';' {printf("id is '%s'\n", $2);}
and I'm trying to print the value of the 'ID' using $2
when I pipe in my test code to parse
var x : int = 5;
Bison is printing:
id is 'x : int = 5;'
instead of what I want:
id is 'x'
ID is declared in my lexer as:
{ID} { yylval.id = yytext; return ID; }
and if I do a printf inside the lexer right here, the value of yytext is correct ('x')
And this is where I'm stuck. Using $2 prints the whole rest of the expression instead of just the specific ID and I have no idea why. Any insight would be greatly appreciated.