0

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'?

  • Wouldn't that suggest that `SQL_SIGNED` was returned by the tokenizer (`yylex`) for `signed`, and that `IDENT` was returned by the tokenizer for `unsigned`? – ikegami Aug 26 '20 at 06:15
  • hollyyyyylyl you're right, there was a scanning problem in tokenizer!!!! I have to take a cheat day tonight for celebrating myself THKS!!! – JungJung Aug 26 '20 at 08:12
  • imho, you have destroyed completely the problem trying to explain it better. Think that if you change the code, the problem can simply dissapear. You say the bar doesn't work, that's not a description. Please post a complete example that exhibits the problem you have (if possible minimal, but still showing the problem you have) and don't describe where you think the problem is. That's simply not true (if the problem was there you hve solved it) see [this page](https://stackoverflow.com/help/minimal-reproducible-example) before posting in SO. – Luis Colorado Aug 26 '20 at 18:04

0 Answers0