Cookbook for Coco/R

Last update: May 28, 2008

Coco/R primary strives for simplicity, therefore some potentially useful features are not incorporated. This section gives an overview on aspects not implemented in Coco/R, which are of possible interest for practical projects. Every aspect consists of a short description of the problem and the sketch of a posible solution.

Discussed Aspects

Handling Multiple Language Contexts by Subtractive Context Switching


What if we have a language where some tokens (e.g. keywords) are only valid in certain contexts? In C# 3.0, for example, tokens such as select or from should be recognized as Linq keywords (Language Integrated Query keywords) in query expressions; in all other contexts they should be recognized as identifiers.


Possible solutions are

  1. Write a context-aware scanner
  2. Write multiple scanners and switch between them
  3. Let Coco/R generate the full scanner and replace tokens by others in certain contexts
For the proposed solution we base the selection of the best approach on the least influence on Coco/R. Our solution therefore is based on approach 3. To keep the complexity of the filtering low it works with multiple wrappers (filter) around the full scanner. The adequate filter is selected by the parser, the whole implementation is enclosed in the attributed grammar file.
Detailed information on the approach is given in: HowToMultiContextSensitiveTokens.pdf