I'm assuming the token for a number (what you're calling literal) is named LITERAL
, and that variable names immediately following literals are not a normal construct (in algebraic languages this is usually the case, unless you want 9 foo
to mean 9 * foo
).
You need to write a bison rule to parse the sequence LITERAL VAR
and return a number (probably another token besides LITERAL
unless you want a recursive rule, e.g. 9u u
). The code for this rule should check that VAR
is u
(or another legal postfix) and return an error if it finds something unexpected.
I've used sequences like this before to parse units (e.g. g = 9.81 m/(s^2);
).
If you want to demand that the u
immediately follow the literal, and the result be a LITERAL
token, then you're going to have to change your lex rule, assuming unquoted whitespace is not passed on to the parser.