Let's assume I have the production:
Expression // These are my semantic actions
: Expression PLUS_TOKEN Expression ( create_node(Expression, Expression) )
| SimpleExpression ( SimpleExpression ) (* Returns a node of type expression *)
Notice how I can't tell which Expression is which in my top most production's semantic action. How do I refer to the left and right Expression? What if I have three or more 'Expression's appear in the same production?
Reference: http://www.smlnj.org/doc/ML-Yacc/mlyacc002.html
According to ML-Yacc documentation we refer to non-terminals with the following notation:
such that n is the number of occurrences of the non-terminal to the left of the symbol. If n equals one then we can just use the non-terminal name.
Hence, the above example would look like this: