more tolerant parsing of misplaced toplevel declarations, and stricter
reporting of errors from typechecker