2

I'm learning "Compiler Theory", it says most of languages used "deterministic context-free grammar". I wonder is there any language use "context-sensitive grammar"?


Update:

I asked someone, he said that c++ and ruby has some context-sensitive grammars.

For example, in c++, this code:

abc();

If there is a method called abc, then abc() means "the invocation of this method". If there is a class class abc{ }, then it means "create an instance of class abc".

And in ruby, since it has meta-programming, it has more context-sensitive grammars.

Is he right?

Freewind
  • 193,756
  • 157
  • 432
  • 708
  • That's not a particularly strong example because `abc` is an identifier and not actually part of the language. A better example would be C#'s 'using' keyword which means different things in different contexts. – Rik Nov 26 '12 at 15:07
  • The COBOL READ statement has context-sensitive syntax that depends on the ACCESS MODE of the file being read: if SEQUENTIAL, the AT END clause is a valid continuation, otherwise not; if RANDOM, ON INVALID KEY is a valid continuation, otherwise not. – user207421 Nov 26 '12 at 22:37
  • Question really belongs in Computer Science and should have been migrated there, rather than just closed. – user207421 Nov 26 '12 at 22:40
  • @EJP: Then you should flag it with a message saying so. Reopening it here will accomplish nothing. – C. A. McCann Nov 26 '12 at 22:59
  • @C.A.McCann I had already done exactly that. – user207421 Nov 27 '12 at 00:17

1 Answers1

2

Context-sensitive grammar has symbols that change their meaning in relation with various nonterminals they are used in their context. In computer world, they are pretty rare, because it quite complicates writing of the parser - decision if a string belongs to a certain context-sensitive grammar is PSPACE-complete.

Jakub Zaverka
  • 8,816
  • 3
  • 32
  • 48