It seems that some syntax errors are not detected by the parser. For example, a break statement outside of a loop/switch statement, or with an invalid label does not generate a syntax error. I would suggest that the parser should have an AST validation pass added to it, so that these kinds of errors can be detected, and adequately reported, before any transformations are applied to the AST.
Right now, I'm in a position where the parser can produce an AST that doesn't translate into valid IR. I would rather avoid having to clutter the AST->IR translation with validation and syntax error reporting code, and simply be able to assume that the AST I get as input is syntactically valid.
- Maxime