|
|
|
|
|
by xg15
185 days ago
|
|
Is that so? Programming languages usually have a number of "higher-level semantic layers" on top of the syntax tree that impose further constrains - e.g. that identifiers must have consistency between usage and definition, that all expressions are valid according to the type system, etc. But all that stuff happens after an AST is created and so doesn't really affect the basic grammar. I think if you ignore those higher-level constraints, a number of languages have valid context-free grammars. |
|
One could argue that it is acceptable to produce an ambiguous parse and defer the decision, and in practice compilers do rely on semantic information to resolve such cases.
However, this is not what context-free means in the Chomsky sense: a context-free grammar must be able to determine the syntactic structure without reference to prior declarations or semantic state.