Question

From my understanding, parser generators accept as input some form of context-free grammar description. The context-sensitive features are handled during semantic rather than syntactic analysis (please correct me if this is wrong).

Since shell languages inherently have a lot of context-sensitive features, is it worthwhile using a parser generator? If not, what techniques could be used for a precise definition and parsing of a shell language?

EDIT:
In conclusion: my understanding of what context-sensitive grammar means was wrong.

Was it helpful?

Solution

Context-free grammars are grammars where the left side of every production rule is a non terminal term (aka an abstract grammar construct) whereas the right side can be a mix of terminals (aka tokens that you find in the language) and non-terminals.

Context-sensitive grammars are more tricky, since both the left and the right side of production rules can be a mix of terminals and non terminals. To express it simply, the meaning of a term depends on its surroundings (aka “context”).

Command shells usually have a straightforward grammar that can be expressed with context-free grammars. I’d really wonder if you’d really need a context sensitive one.

I’d tempted to say that command shells are easily implemented using simple top down interpreter (see also the interpreter pattern) and that parser generators seem to me somewhat an overkill. But I have not seen your language so I cannot tell for sure that it makes sense in your case.

Licensed under: CC-BY-SA with attribution
scroll top