Tedd Parsile
Tedd Parsile

Reputation: 65

Examples of practical context sensitive programming structures

So, I am implementing a context sensitive syntactical analyzator. It's kind of experimantal thing and one of the things I need are usable and practical syntactical contructs to test it on.

For example the following example isn't possible to parse using standard CFG (context free grammar). Basically it allows to declare multiple variables of unrelated data types and simultaneously initialize them.

int bool string number flag str = 1 true "Hello";

If I omit a few details, it can be formally described like this:

L = {anbncn | n >= 1}

So, I would appreciate as much of similar examples as you can think of, however, they really should be practical. Something that actual programmers would appreciate.

Upvotes: 0

Views: 176

Answers (1)

Davislor
Davislor

Reputation: 15134

Just about all binary formats have some context-sensitivity, one of the simplest examples being a number of elements followed by an undelimited array of that length. (Technically, this could be parsed by a CFG if the possible array lengths are a finite set, but only with billions and billions of production rules.) Pascal and other languages traditionally represented strings this way. Another context-sensitive grammar that programmers often use is two-dimensional source-code layout, which right now gets translated into an intermediate CFG during preprocessing. References to another part of the document, such as looking up a label. Turing-complete macro languages. Not sure exactly what kind of language your parser is supposed to recognize.

Upvotes: 2

Related Questions