Formalized, your question is: given a grammar G that parses a language L(G) and an extended grammar G' that parses an extended language L(G') where L(G) is a subset of L(G'), how can it be shown that any program in the language L(G) produces the same parse tree with the grammar G and G'?
This is the language inclusion problem and is undecidable for context free grammars. It is also undecidable whether a CFG is ambiguous, e.g. whether the same program could be parsed in two different ways under the G' grammar.
However, these problems may be decidable for the CFG subsets actually used by most programming languages, such as LALR. It may also be decidable if the difference between G and G' has a specific structure. Unfortunately I'm not familiar with the necessary theory.
Instead, there are two practical ways two check the compatibility of such syntax changes.
First, there might be a corpus of existing programs including lots of edge cases. Using a grammar-driven parser that can parse all CFGs (such as GLR or Earley parsers), these parsers can report whether the programs in that corpus had an ambiguous parse.
The more common approach is to ask other people whether they can spot any problems.
In this particular case there is a clear argument that such syntax would not be ambiguous. (public
is a keyword, ergo there can be no method or constructor called public()
. Introducing such syntax would therefore not introduce ambiguities.) A tool may or may not be able to make that connection. An experienced human certainly us.
Of course syntactic compatibility is the easy problem. Much more difficult is retaining compatible semantics, which is a much harder problem even for humans and definitively can't be checked automatically by tools. For starters, most programming languages don't even have any formal semantics that could be the subject of a proof. Again, asking many experienced humans is the only viable approach. If a problem is overlooked (happens quite often), then that's a bug that needs to be addressed afterwards.