parsingcontext-free-grammarcontext-sensitive-grammar

is this grammar context free


is the following grammar context free? My impression was that a grammar was context free when the parser did not need to interpret what was parsed already. With the following grammar, that is not necessary, however, my colleague is sure that it is context sensitive non the less.

The issue is that you cannot determine which alternative of X needs to be matched without knowing if X is inside Y or Z

X: ( "a" | "a" "b" )
Y: X "b" "c"
Z: X "d"

Solution

  • The term "context sensitive" occasionally arises when discussing grammars that work with LL parsers but not with Strong LL (SLL) parsers. In these cases, decisions that require an LL parser may be called "context sensitive" because they require information about the top-down parsing context to make accurate decisions. However, both SLL and LL grammars would be considered context-free grammars.