I have faced a problem when using PLY. I want to create a call graph generator by PLY. In some situation, I need to discard some tokens in the grammar file. That is because I need to do something when the parser recognize that token before I discard it, so I can't just discard in the lexer file. For example, the 'IF' token is the one which I want to discard. So I try to do something to discard it in the grammar file. Just like:
def p_if(p):
'if : IF'
print "if"
parser.symstack.pop()
But things didn't go the way I think. I print the symstack(it's a atribute of parser, and parser is a LRParser instance of yacc.py), and the symstack list just contain the previous tokens but not 'if'. So I am wondering how to discard a token in this situation. Could anyone help me? Thanks a lot!