HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, 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_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/share/doc/libparse-recdescent-perl/examples/demo_metaRD.pm
# Changes! /usr/local/bin/perl -w

use Parse::RecDescent;

local $/;
my $parse = Parse::RecDescent->new(<DATA>);

my $grammar = <>;

$tree = parse->grammar($grammar) or die "Bad grammar! No biscuit!";

print Data::Dumper->Dump([$tree]);



__DATA__

<autotree>

grammar    : prerule(s?) components(s?) /\Z/

component  : rule
	   | comment

rule       : <skip:""> "\n" <skip: '[ \t]'> identifier ":"
	     <skip: $item[1]> production(s? /|/)

production : items(s)

item       : lookahead(s?) simpleitem
           | directive
           | comment

lookahead  : '...' | '...!'                   # +'ve or -'ve lookahead

simpleitem : subrule args(?) rep(?)           # match another rule
           | terminal                         # match the next input
           | bracket args(?)                  # match alternative items
           | action                           # do something

subrule    : identifier                       # the name of the rule

args       : {extract_codeblock($_[0],'[]')}  # just like a [...] array ref

rep	   : '(' repspec ')'

repspec	   : '?'                              # 0 or 1 times
           | 's?'                             # 0 or more times
           | 's'                              # 1 or more times
           | /(\d+)[.][.](/\d+)/              # $1 to $2 times
           | /[.][.](/\d*)/                   # at most $1 times
           | /(\d*)[.][.])/                   # at least $1 times

terminal   : /[/]([\][/]|[^/])*[/]/           # interpolated pattern
           | /"([\]"|[^"])*"/                 # interpolated literal
           | /'([\]'|[^'])*'/                 # uninterpolated literal

action     : <perl_codeblock>		      # embedded Perl code

bracket    : '(' production(s? /|/) ')'       # alternative subrules

directive  : '<commit>'                       # commit to production
           | '<uncommit>'                     # cancel commitment
           | '<resync>'                       # skip to newline
           | '<resync:' pattern '>'           # skip <pattern>
           | '<reject>'                       # fail this production
           | '<reject:' condition '>'         # fail if <condition>
           | '<error>'                        # report an error
           | '<error:' string '>'             # report error as "<string>"
           | '<error?>'                       # error only if committed
           | '<error?:' string '>'            #   "    "    "    "
           | '<rulevar:' /[^>]+/ '>'          # define rule-local variable
           | '<matchrule:' string '>'         # invoke rule named in string

identifier : /[a-z]\w*/i                      # must start with alpha

comment    : /#[^\n]*/                        # same as Perl

pattern    : {extract_bracketed($text,'<')}   # allow embedded "<..>"

condition  : {extract_codeblock($text,'{<')}  # full Perl expression

string     : {extract_variable($text)}        # any Perl variable
           | {extract_quotelike($text)}       #   or quotelike string
           | {extract_bracketed($text,'<')}   #   or balanced brackets