HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/doc/libparse-recdescent-perl/examples/demo_implicit.pl
#!/usr/bin/perl -sw

# IMPLICIT SUB RULES, OKAY!

use strict;
use Parse::RecDescent;

my $grammar =
q{
	{ my $state = "happy"; }

	testimony	: declaration(s)
				{ print "Ended up $state\n"; }

	declaration	: 'I' ('like'|'loathe')(s) ('ice-cream'|'lawyers')
				{ print "$item[3]\n";
				  $state = 'happy/sad'; }
			| 'I' ("can't"|"can") ('fly'|'swim')
				{ print "$item[3]\n";
				  $state = 'able/unable'; }
			| <error>

};

my $parse = new Parse::RecDescent ($grammar);
my $input;

while (defined ($input = <>))
{
	$parse->testimony($input) or print "huh?\n";
}