[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Using api.token.constructor for tokens without arguments.
From: |
Slava Barinov |
Subject: |
Using api.token.constructor for tokens without arguments. |
Date: |
Tue, 25 Aug 2015 15:20:53 +0300 |
Hello,
I'm experimenting with bison+flex and met an issue: bison won't provide a
token type info. So the situation: I've got a calc++ example and started to
simplify it. For example there are two operations + and - which will increase
and decrease global variables (no arguments needed) so there are lines in
lex.ll
"+" return yy::parser::make_INC(loc);
"-" return yy::parser::make_DEC(loc);
and corresponding
%define api.token.constructor
%define api.value.type variant
%define parse.assert
...
%token INC DEC
...
stmts: stmt {};
| stmts stmt {};
;
stmt: op
;
op: val_op
;
val_op: INC {driver.addOp($1);}
| DEC {driver.addOp($1);}
;
in parse.yy.
Parser generation is fine, I get the line in parse.cpp:
driver.addOp(yystack_[0].value);
And after running the debug output prints
$1 = token INC (1.187-188: )
but the yytypeid_ in variant coming to addOp is zero. So `as<token>()' is not
applicable (segfault) and I can't detect which token it is. Should the token
constructor work for such cases or it's designed only for tokens followed by
arguments?
Thank you,
Slava Barinov
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Using api.token.constructor for tokens without arguments.,
Slava Barinov <=