Thank you for you fast answer. I've already tried this way but it doesn't work fine. I'm newbie, so I think I don't know something useful.
If I use a rule like that you wrote, Bison shows this message "The identifier was: (null)". I've red something about yylval, so if I type in Lex file: yylval=yytext, and so the same your rule shows me "The identifier was: snoopy*charlie", and not only "snoopy". What do you thing about this behaviour? 2009/4/29 Mike Aubury <mike.aub...@aubit.com> > Something like : > > > A: B C D { > printf("The identifier was: %s", $2); > } > | B E D { > printf("It wasn't an identifier..."); > } > ; > > > > > > 2009/4/29 Mark Redd <markred...@gmail.com> > >> Hello everybody, >> I would like to receive an hint about reading parser stack. >> >> Suppose my (fantasy) bison grammar is this: >> >> %start A >> >> A : B C D | B E D >> >> B: ID >> C: '*' >> D: IDENTIFIER >> E: '-' >> >> where IDENTIFIER has been defined like [a-zA-Z0-9]+ using flex. >> >> How can I print "the identifier was: %s" when C matches (but not when E >> does >> it) without rewriting the grammar? >> In particular, I need to know what I have to write in >> C: '*' { printf("The identifier was: %s", ?????); } >> >> Note that it isn't my very problem, but it's a model of this and so I'd >> like >> a general answer. So I can't modify my grammar and I don't want to read >> only >> the last token in parser, but sometimes I'm interested in reading the last >> n >> tokens. >> >> Thank you! >> Mark Redd >> _______________________________________________ >> help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison >> > > _______________________________________________ help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison