bison - How do i allow postfix characters on a literal? -
using bison/flex want make valid
a = 9u
i wrote rule allowing 'u' after literals realize flex isnt picking because letters return var instead of ascii value.
how allow postfix character on literal? thinking write in lex rule dont know if nasty surprise happen. best place this?
i'm assuming token number (what you're calling literal) named literal
, , variable names following literals not normal construct (in algebraic languages case, unless want 9 foo
mean 9 * foo
).
you need write bison rule parse sequence literal var
, return number (probably token besides literal
unless want recursive rule, e.g. 9u u
). code rule should check var
u
(or legal postfix) , return error if finds unexpected.
i've used sequences before parse units (e.g. g = 9.81 m/(s^2);
).
if want demand u
follow literal, , result literal
token, you're going have change lex rule, assuming unquoted whitespace not passed on parser.
Comments
Post a Comment