Monday, 8 October 2012

C# Lexical Structure: Keywords vs Contextual Keywords

How do you extend a language without changing its keywords? Contextual keywords go some way to providing an answer.

An example keyword in C# is "double". Double is a simple type that can store 64-bit floating point values. A contextual keyword only has meaning within a specific context e.g. get/set within a property declaration.

The ascending contextual keyword is used in LINQ queries and only has meaning in LINQ context, for example:

IEnumerable<string> sortAscendingQuery = from elephant in zoo orderby elephant ascending select elephant.

There is no specific word for non-contextual keywords. One might call them, "context-independent" keywords.

No comments: