I'm trying to write a EPL parser,so I'm learning flex and bison.I try using it with following rules(SQL):
SELECT { cout<<"SELECT detected"<<endl;return SELECT; }
FROM { cout<<"FROM detected"<<endl;return FROM;}
[a-zA-Z][0-9a-zA-Z]* { cout<<"IDENTIFIER detected"<<endl;yylval.c=yytext;
return IDENTIFIER; }
'$' { return DOL;}
[ \t] { cout<<"space founded:"<<int(yytext[0])<<endl; }
\n { return EOL;}
. {}
and bison rules are:
sel_stmt : {cout<<"VOID"<<endl;}
| SELECT identifier_expr FROM identifier_expr { cout<<"select statement founded"<<endl; }
;
identifier_expr : DOL IDENTIFIER {
$$=$2;
cout<<"ident_expr:"<<$$<<endl;
}
;
all tokens and non-terminals have type "char*"
as the input from stdin is "select $abc from $ddd" reudction happend when lexer returned token FROM,in "identifier_expr" action ,output is "ident_expr:abc from" why this happened?