in reply to generator_generator: generate a C++ string generator from a grammar
This is a fun and interesting text analysis project. On a side note, for those who want to expiriment with this type of project straight from perl, the functionality can also be implemented relatively well with array references and a function that chooses random elements therefrom.
This is an alternative route for those who are unable to install a module like yours or Inline::Spew.
### INIT script use strict; use warnings; use SpewUtils qw(Rc1 RcN RoD ScrubST) ; ### script for my $item (0..5){ print GenSaying000(); print ("\n-----------------------------------\n"); } sub GenSaying000 { my $strOut = Sentence(); $strOut = ScrubST($strOut); return $strOut; }###end_sub sub Sentence { Rc1([qw( The A )])." @{[adjective()]} @{[animal()]} sat on the + @{[object()]} @{[adjacency()]}"; }###end_sub sub animal { Rc1([qw( cat dog rat mouse cheetah elephant )]) }###end_sub sub object { Rc1([qw( fence mat shovel car roof )]) ; }###end_sub sub adjacency { Rc1([ 'near', 'behind', 'next to', 'underneath', ]) ." the " .Rc1([ 'doorway', 'outhouse', 'patio', 'fence', 'corner', 'b +order' ]) ; }###end_sub sub adjective{(0)?"" :(RoD(6) > 5)? 'fluffy' :(RoD(6) > 5)? 'furry' :(RoD(6) > 5)? 'lazy' :(RoD(6) > 1)? 'very ' . "@{[adjective()]}" :(1)? @{RcN([qw(shiny happy clammy yummy silly happy jolly)], +rand(4))} :'' } 1; __END__
|
|---|