#! /usr/local/bin/perl -ws I am trying to get some output from a grammar I built with Parse::RecDescent, but I cant seem to get it to give me any output. Any help is appreciated:
use lib '/cygwin/usr/local/lib/perl5/site_perl/5.6.0'; use Parse::RecDescent; my $grammar = <<'EOGRAMMAR'; translate: select | sum | identify | { "Could you rephase that?\n" } select: ask_select qualifier(?) field /of/ qualifier(?) table { "SELECT DISTINCT $item[3]\nFROM $item[6]\n" } | ask_select qualifier(?) table /'?/ qualifier(?) field { "SELECT DISTINCT $item[6]\nFROM $item[3]\n" } | ask_select qualifier(?) table { "SELECT *\nFROM $item[3]\n" } sum: ask_count table prep qualifier field prep(?) value { "SELECT COUNT(*)\nFROM $item[2]\n" . "WHERE $item[5] = $item[7]\n" } | ask_count table { "SELECT COUNT(*)\nFROM $item[2]\n" } identify: ask_select(?) /who supplies/ qualifier value { "SELECT supplier\nFROM merchandise\n" . "WHERE name = $item[4]\n" } | whats qualifier field /of/ qualifier /suppliers? of/ value { "SELECT suppliers.$item[3]\n" . "FROM suppliers, products\n" . "WHERE products.name = $item[-1]\n" . "AND suppliers.name = products.supplier \n" } field: /(name)s?/ { $1 } | /(product)s?/ { $1 } | /(id)(entit(y|ies))?/ { $1 } | /(quantit(y|ies))/ { $1 } | /(received)s?/ { $1 } | /(supplier)s?/ { $1 } | /(cost)s?/ { $1 } | /(address)(es)?/ { $1 } table: /suppliers?/ { 'suppliers' } | 'merchandise' | /orders?/ { 'orders' } qualifier: /the|every|all( the)?|any|our/ ask_select: reply to_me ask_count: ask_select(?) /how (many|much)/ reply: /tell|show|list/ value: /\w+/ { qq{'$item[1]'} } to_me: /((to )?(me|us))?/ whats: /what's|what (is|are)/ prep: /for|of|with|by/ EOGRAMMAR my $parser = Parse::RecDescent->new($grammar) or die "Bad grammar"; $| = 1; while (<DATA>) { print "> "; sleep 1; print; <>; my $SQL = $parser->translate($_); print $SQL, "\n"; } __DATA__ how many orders for the product spam are there? tell me how many suppliers by the name of Jones we have what are the names of our suppliers of trinitrotoluene? tell me our suppliers' names list our merchandise show us the suppliers of the mechanise list all supplier names how many orders are there? how much merchandise do we carry? who supplies our nitrocelluose? tell me who supplies our ethylacetate? what are the addresses of our suppliers of trinitrotoluene?

In reply to need help with Parse::RecDescent by princepawn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.