4

Do you know about any, which can specify context-sensitive grammar? For example * symbol pointer/multiplication ambiguity resolving. I am looking for formal language which will make it possible to resolve such ambiguities. The language, which I am looking for should be well specified.

Edit: I am looking for something like BNF, but should be context-sensitive, actually it should be able to solve Dangling else problem.

  • C++ certainly fits the bill (it is highly context-sensitive) – Basile Starynkevitch Apr 23 '14 at 18:17
  • Ironically, your question is itself ambiguous, or at least I completely fail at parsing it. Could you elaborate/rephrase what kind of thing you're after and what properties it should have? –  Apr 23 '14 at 18:21
  • I am looking for formal language, which can resolve differences in parsing between pointers and multiplications symbol, without supplying some external routines. Something like BNF, but should be context-sensitive. – user3313119 Apr 23 '14 at 19:15
  • I'm not sure whether context sensitive grammars are enough to tell pointer declarations from multiplications (people always say that's context sensitive, but I've built up the impression that most of them use an informal, possibly very wrong, definition of context sensitivity). In any case, the trivial solution would be any turing complete language; I assume you intended to rule that out by "without supplying some external routines"? If so, you'll have to make that more formal/specific, that wording can mean almost anything. –  Apr 23 '14 at 19:44

1 Answers1

4

BNF can resolve ambiguities of this sort by introducing additional rules. For example, in the Java language spec you find:

IfThenStatement:
  if ( Expression ) Statement
IfThenElseStatement:
  if ( Expression ) StatementNoShortIf else Statement
StatementNoShortIf:
  IfThenElseStatementNoShortIf
  ...
IfThenElseStatementNoShortIf:
  if ( Expression ) StatementNoShortIf else StatementNoShortIf

...where StatementNoShortIf is a Statement that can't end with an 'if' that has no 'else'. Thus, if I am parsing if(a) if(b) c(); else d();, then the only option is to have if(b) c(); else d(); bind to StatementNoShortIf.

Russell Zahniser
  • 16,188
  • 39
  • 30