Adding debug information about associated token(s) is necessary for printing pretty error/warning/info messages after parsing is done.
Currently pretty messages are printed in yyerror (the lexer is still running at this point) which assumes that the global state of yylloc and others is set correctly. This cannot be relied on when inspecting the AST after parsing (the lexer is done and won't update global variables).
Proposal
Since any AST node can represent more than a single token (such as declarations) a node should store the bounds of an entire group of token (which can consist of a single token).
Problem
Adding debug information about associated token(s) is necessary for printing pretty error/warning/info messages after parsing is done. Currently pretty messages are printed in
yyerror
(the lexer is still running at this point) which assumes that the global state ofyylloc
and others is set correctly. This cannot be relied on when inspecting the AST after parsing (the lexer is done and won't update global variables).Proposal
Since any AST node can represent more than a single token (such as declarations) a node should store the bounds of an entire group of token (which can consist of a single token).
Add debug information to each AST node about: