I've tried to parse below text using bison.
signed int c1;
unsigned int c2;
This is bison definition. I removed All of actions because it's pretty complicate to explain and not that necessary.
%type <type_enum> simple_type // enum
%type <str> opt sign // char*
%type <ival> opt sign // int
%%
simple_type: opt_sign opt_sign_type
opt_sign: SQL_SIGNED
| SQL_UNSIGNED
| /* EMPTY */
;
opt_sign_type: SQL_SHORT
| SQL_SHORT INT
| INT
| SQL_LONG
| SQL_LONG INT
| SQL_LONG SQL_LONG
| SQL_LONG SQL_LONG IN
| SQL_BOOL
| BYTE
| CHAR
| SQL_CONTEXT
| STRING
| CCILEN
| VARCHAR
;
%%
Grammar about variable name is defined on higher layer, because there are more types not just 'simple_type'. Below is them.
type: simple_type
| struct_type
| struct_nType
| union_type
| enum_type
| ident
;
ident: IDENT
;
Parser is working well for the signed int c1;
, but for the unsigned int c2;
the type is classified as ident
not simple_type
.
When I print IDENT(=$1)
in action of ident
, it was 'unsigned'.
Why parser is not working for 'unsigned'?