|
|
|
|
|
by tom_mellior
2241 days ago
|
|
Pretty much every programming language has a nicely parseable context-free "rough syntax" (my term I just invented) that can be written down formally for the language documentation and a parsing tool. And then every language also has a notion of "well-formed programs", which introduces a whole bunch of additional constraints on what programs should actually be accepted by compiler frontend. Well-formedness includes type checking. But even without full type checking that can be done later, it also includes things like being aware, in C, of whether a given identifier is declared as a typedef in the current scope. So while C has a nice context-free "rough syntax" formally specified in the standard, its actual input language is context sensitive. As for Java, the first example that comes to mind is that constructors must have the same name as the class they belong to. This "choose whatever identifier you like, but at some later point repeat that exact same identifier" is a very typical example of something that is not context-free. You might disagree whether this constraint is part of what you consider Java's "grammar". So the answer to your question depends on what language level you are thinking of. But whichever level you apply to Java, you should apply the same to C++. C++ also has a context-free "rough syntax" in its standard. |
|