Avoid resolving a node more than once

For a complex grammar I was having very long parser construction times. This patch reduced this by a factor of >100x (13s to 95ms)

The problem I diagnosed (by adding a print id(expr) at the top of _resolve_refs) is that many expressions were being vesited many times, although (I *think*) once per expression is enough. so this reduced the number of calls to resolve_refs from 10 million to about 1000.