Re: need help with using a grammar to construct a sentence from a group of words

kelley@iguana.ruralnet.net (Kevin Kelley)
18 Apr 1998 00:53:26 -0400

          From comp.compilers

Related articles
need help with using a grammar to construct a sentence from a group of plantz@fgm.com (Glen Plantz) (1998-04-13)
Re: need help with using a grammar to construct a sentence from a grou kelley@iguana.ruralnet.net (1998-04-18)
Re: need help with using a grammar to construct a sentence from a grou resslere@erols.com (resslere) (1998-04-21)
Re: need help with using a grammar to construct a sentence from a grou donham@linex.com (Jake Donham) (1998-04-27)
Re: need help with using a grammar to construct a sentence from a grou js10@doc.ic.ac.uk (1998-05-04)
Re: need help with using a grammar to construct a sentence from a grou schairer@dfki.de (Axel Schairer) (1998-05-04)
| List of all articles for this month |

From: kelley@iguana.ruralnet.net (Kevin Kelley)
Newsgroups: comp.compilers,comp.lang.java.programmer
Date: 18 Apr 1998 00:53:26 -0400
Organization: Starlight Software
References: 98-04-049
Keywords: parse, testing, comment

Glen Plantz <plantz@fgm.com> writes:


> Hello Folks,
>
> I have a problem where I need to do the opposite of parsing; given
>a grammar and a group of words, I need to use the grammar to construct
>a valid sentence. ...


This might be interesting. If you have a parser toolkit, so that the
tools are already present, it could be pretty easy, too.


Say that a language is a set of productions; a production is a mapping
from a nonterminal to a rule (vector of 0 or more term/nonterm).
Then, start with the top production, and repeat substituting rules for
nonterminals, randomly (or based on some preference criteria)
selecting the rule to use from the set of rules for a given lhs, until
you've got no nonterminals left.


What you have will be, by definition, a valid sentence in the
language. Sounds like a fun project!


Kevin Kelley
--
Starlight Software Co. Java Cannery: auto-package your projects!
kelley@iguana.ruralnet.net http://www.ruralnet.net/~kelley/index.html
[This came up a few years back; I believe there are sentence generators
available on the net. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.