production grammars

2 views
Skip to first unread message

aufrank

unread,
May 27, 2005, 2:41:39 PM5/27/05
to
Hello!

I've got a question regarding a potential use of grammars and rules in
perl 6. Apocalypse, Exegesis, and Synopsis 5 all show how to use
grammars and rules for parsing. In human use of language, it seems
likely that the same grammars are used for parsing (comprehension) and
generation (production).

Will it be possible to generate strings from a perl 6 grammar, or are
they strictly for parsing? I suspect that a clever use of closures
within the rules would probably play some part in turning a parser into
a generator, but I guess I'm hoping that the capability's already there
in perl 6 and I just haven't heard about it yet.

I'm thinking specifically of whether perl 6 grammars could be used in
implementing Monte Carlo simulations, where a stochastic process is run
repeatedly to see what kinds of output it tends to produce. It seems
as if you could define a legal output string using a grammar, and that
the stochastic nature of the simulations would be implemented using the
different metacharacters that allow alternate or optional matches.
Setting a prior probability on each possible token in the string
(and/or transitional probabilities based on previous tokens) would
allow for repeated runs of the production grammar to produce
different-but-legal strings.

It may turn out that for this specific example, writing custom 'pick'
and 'any' -like operators that follow given probability distributions
may be a more appropriate approach. But even if using grammars for
stochastic generation isn't feasible or useful, I'd still like to hear
how (or whether) you all think a perl 6 grammar might be turned into a
string generator instead of a string parser.

Perhaps my question is ill-formed at it inception, but if there's
anything here worth discussing, what are your thoughts? Can a perl 6
parsing grammar be turned on its head and made into a generator?

Thanks for any response,
/au

Reply all
Reply to author
Forward
0 new messages