user3313119
user3313119

Reputation: 49

Context-sensitive and turing-complete formal languages

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.

Upvotes: 4

Views: 286

Answers (1)

Russell Zahniser
Russell Zahniser

Reputation: 16354

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.

Upvotes: 4

Related Questions