Membership for a context sensitive grammar

A

Alex

I have to write a java program to test if a word w ¤ L(G) for a context
sensitive grammar G.

Can anybody help me?

Thx in advance!
 
O

Oliver Wong

Alex said:
I have to write a java program to test if a word w ¤ L(G) for a context
sensitive grammar G.

Can anybody help me?

http://en.wikipedia.org/wiki/Context-sensitive_grammar
<quote>
The decision problem that asks whether a certain string s belongs to the
language of a certain context-sensitive grammar G, is PSPACE-complete.
Indeed, there are even some context-sensitive grammars whose fixed grammar
recognition problem is PSPACE-complete.
[...]
That makes them totally unworkable for practical use, as the general
algorithm would take exponential time. Ongoing research on computational
linguistics has focused on formulating other classes of languages that are
"mildly context-sensitive" whose decision problems are feasible, such as
tree-adjoining grammars, coupled context-free languages, and linear
context-free rewriting systems. The languages generated by these formalisms
properly lie between the context-free and context-sensitive languages.
</quote>


- Oliver
 
A

Alex

I knew that this was a great decidability problem....but isn't there any
algorithm to do it ?
 
P

Patricia Shanahan

Oliver said:
Alex said:
I have to write a java program to test if a word w ¤ L(G) for a
context sensitive grammar G.

Can anybody help me?

http://en.wikipedia.org/wiki/Context-sensitive_grammar
<quote>
The decision problem that asks whether a certain string s belongs to the
language of a certain context-sensitive grammar G, is PSPACE-complete.
Indeed, there are even some context-sensitive grammars whose fixed
grammar recognition problem is PSPACE-complete.
[...]
That makes them totally unworkable for practical use, as the general
algorithm would take exponential time. Ongoing research on computational
linguistics has focused on formulating other classes of languages that
are "mildly context-sensitive" whose decision problems are feasible,
such as tree-adjoining grammars, coupled context-free languages, and
linear context-free rewriting systems. The languages generated by these
formalisms properly lie between the context-free and context-sensitive
languages.
</quote>

Most programming languages, including Java, are really context
sensitive. Whether:

a = b+c;

is a valid Java statement depends on whether a, b, and c have been
declared, and if so, their declared types.

The usual solution is to separate the rules into a very tractable
grammar, always context free, and a set of additional rules about
declarations etc.

Is there any possibility of doing that sort of translation on your
grammar? It is almost essential if this is a real problem, requiring a
practical solution.

If not, if it is e.g. homework, consider treating it in two pieces, and
algorithm question and a Java coding question. First look for an
algorithm, in any language. Once you understand the algorithm, code it
in Java.

Patricia
 
O

Oliver Wong

Alex said:
I knew that this was a great decidability problem....but isn't there any
algorithm to do it ?

Yes, such an algorithm exists. Tiny at
http://www.gittens.nl/grammar.html is a proof of concept parser generator
for context-sensitive grammars. It generates C++ code. If you can (or won't)
read the source code, you could try reading the articles posted on that
site, or contacting the author directly.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top