The manual clearly says:
YYSETSTATE (s)
[...]
The parameter to YYSETSTATE is a signed integer that uniquely identifies
the specific instance of YYFILL (n) that is about to be called.
[...]
The problem is, I'm calling my YYSETSTATE defined macro from a bison parser. How can I begin a state without knowing the integer
UI? In other words, how can I get the identifier of a state I want to begin.
On lexer:
<MY_STATE>{NAME} {
return FN_NAME;
}
On parser:
expr: { push_state( ? ) } /* what's the identifier of MY_STATE? */
'(' FN_NAME VALUE VALUE ')' { compile_expr($2, $3, $4); }
;
I don't think you should ever invoke the YYSETSTATE
macro. It's used as part of re2c
's control-inversion mechanism, enabled with the -f
command-line flag, which turns the scanner into a "push" scanner. That's a handy feature, but it has nothing to do with start conditions, and it's hard to imagine a circumstance in which you could break through the abstraction to directly set the state.
re2c
does have a feature similar to flex
's start conditions, which is enabled with the -c
command-line flag. To set the current condition, you use YYSETCONDITION
, which takes a value from an enumeration of start conditions. If you also supply the -t
command-line flag, re2c
will create a header file with this enumeration, so that you can perform YYSETCONDITION
from other translation units.