ccompiler-constructiongrammarcontext-free-grammarformal-languages

The term "context" in programming languages and how context is affected by loading and updation?


What does the term context mean in context-free and context-sensitive languages? Can a variable have multiple contexts? If I need to store a particular value in a particular memory address how does does affect the context of the memory address? And if I want to update a variable how does the context of the variable change?


Solution

  • A context-sensitive grammar, productions have the general form

    aBc -> ab'c
    

    where upper-case symbols are non-terminals and lower-case symbols are sequences of terminals and non-terminals.

    In the above example, a and b would be the context of the non-terminal B and indicate that B may "expand" to b' only when surrounded by a and c.

    In a context free grammar, the production might look like

    B -> b'
    

    i.e. B "expands" to b' regardless of whatever is around it, in other words, regardless of context.