Предположим, у меня есть следующие правила в моей грамматике. Я хочу знать, из какого правила происходит сокращение.
iteration_statement : WHILE push_scope LPAREN expression RPAREN compound_statement pop_scope
| DO push_scope compound_statement WHILE LPAREN expression RPAREN SEMICOLON pop_scope
| FOR LPAREN push_scope for_init_statement expression SEMICOLON expression RPAREN compound_statement pop_scope
| FOR LPAREN push_scope for_init_statement SEMICOLON expression RPAREN compound_statement pop_scope
| FOR LPAREN push_scope for_init_statement expression SEMICOLON RPAREN compound_statement pop_scope
| FOR LPAREN push_scope for_init_statement SEMICOLON RPAREN compound_statement pop_scope
Я хочу сделать что-то подобное
if p.ruleno==1:
#action for while
elif p.ruleno==2:
# action for do while
elif p.ruleno==3:
# action for for in rule 3
elif p.ruleno==4:
# action for for in rule 4
elif p.ruleno==5:
# action for for in rule 5
elif p.ruleno==6:
# action for for in rule 6