Some time has passed since I worked out the theory of formal language, but I will bite.
“Context-free” means that the production rules needed in the corresponding grammar do not have a “context” . It does not mean that a certain character cannot be displayed in different rules.
Editing addressing: in other words (and more informally), the decision about whether a language is context-sensitive or context-sensitive comes down to not looking at the “meaning” of a particular “word” or “word”. Instead , it means looking at the set of all legal expressions in that language and looking at whether they can only be “encoded”, taking into account the positional relationship of the “words” component, with each other . This is essentially what Pumping Lemma is testing .
For instance:
S → Type"="Body Type → "Double" Type → "Double""=>""Double" Body → Lambda Body → NormalBody NormalBody → "x" Lambda -> "x""=>"NormalBody
Where S is, of course, the starting character, superscripts are non-terminals, and quoted strings are terminals. Obviously, this can generate a string like:
Double=>Double=x=>x
but the grammar is still context-free .
As simple as observing that the nonterminal "=>" may appear in two "places" of the program, the Scala context does not.
However, it does not mean that:
- the whole Scala language has no context,
- context sensitive - it can be even more complicated
- if you want to encode semantics from Scala to grammar, you get either context-sensitive or context-sensitive.
The latter is especially true since you mentioned “meaning” in the (nomen omen) context of formal languages.
source share