implement emit-ast option ( see issue #10485 )

First try for #10485. Unit/regression tests are missing for now.

Any comments would be appreciated.