Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!spool.mu.edu!think.com!paperboy!hsdndev!spdcc!iecc!compilers-sender From: zvr@ntua.gr (Alexios Zavras) Newsgroups: comp.compilers Subject: Re: YACC, going the other way Keywords: yacc, parse, testing Message-ID: <1289@theseas.ntua.gr> Date: 25 Apr 91 08:54:58 GMT References: <1991Apr23.140427.5416@iecc.cambridge.ma.us> Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: zvr@ntua.gr (Alexios Zavras) Organization: National Technical University of Athens, Greece Lines: 52 Approved: compilers@iecc.cambridge.ma.us In article <1991Apr23.140427.5416@iecc.cambridge.ma.us>, elk@cblpn.att.com (Edwin Lewis King +1 614 860 3394) writes: > I'm interesting in generating strings that are described by a BNF (OK, > YACC) grammar. > Has anyone actually done this before? Is there a YACC-ish tool > available for such a thing? I've seen this question in the past and I replied by mail, but since people always ask, our moderator should keep an answer as well. Check out kafka, a tool that does exactly what you want ! The source was posted on the net (altough many years ago), so it must be archived somewhere. It is the base on which the games insult, babble and flame are based: each of them is just a grammar specification. >From the original README: > Copyright (c) 1985 Wayne A. Christopher > Contained herein is the source for kafka, which is a program that > translates BNF grammars into C programs to generate strings in the > grammar, and files for three useful kafka programs, insult, flame, > and babble. I don't have a manual page for kafka because I have > been too lazy to write one, but if you read the .k files you will > probably be able to figure out how things work. The program is *very* yacc-like (even has kkoutput() functions :-). Here are some sample lines from flame.k: = ; = "I can't believe how " " you are." { CH(1,100); } ; = "I firmly believe that" "." { CH(1,80); } ; = ignorant { CH(1, 100); } ; = as "as a" { CH(1, 60); } ; = { CH(1,30); } ; = dog { CH(1,60); } ; = most "people have" "#s" { CH(1, 60); } ; etc. etc. Oh, here's a sample output: :-) > zvr@phgasos> flame > I'll bet you think that dogs are nasty. I can't believe how hungry > like a wolf you are. Furthermore, you jerk, you make me sick. A very useful program !!! -- zvr -- Alexios Zavras (-zvr-) zvr@ntua.gr zvr@theseas.ntua.gr -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.