The Java grammar defines ModifiersOpt: { Modifier }. Modifier is defined as one of public, protected, private, static etc .... {x} denotes zero or more occurrences of x.
We know that public public is not a valid identifier. Does it mean that any element of the Modifier list (e.g. public) appears only once in {Modifier} ? Is there any "standard" parser combinator for { Modifier } ?
The modifiers can appear zero or more times. As aioobe said, while syntactically acceptable, public private for example is semantically invalid. There are lots of little situations that are fine strictly according to the grammar but are not allowed by the compiler.
The grammar below uses the following BNF-style conventions:
{x} denotes zero or more occurrences of x.
Not all errors in a Java program are syntactical errors. An error like public private for instance may (as you have discovered) be considered as a semantical error.
As another example, I bet the grammar also allows, for instance
int i = "type error";
Still though, it is not a valid snippet of Java code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With