Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.145.196.141
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/2/task/2/root/proc/2/root/usr/share/doc/libparse-recdescent-perl/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /proc/2/task/2/root/proc/2/root/usr/share/doc/libparse-recdescent-perl/examples/demo_NL2SQL.pl
#!/usr/bin/perl -ws

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?

Anon7 - 2022
AnonSec Team