start: tree tree: '(' treestr(s) ')' treestr: tree | tagstr tagstr: TAG ( tree | word ) TAG: /[A-Z.]+ / word: /[\w?]+/ #### #!/usr/bin/perl use strict; use warnings; use Parse::RecDescent; use Data::Dumper; $::RD_AUTOACTION = q { [@item] }; # $::RD_HINT = 1; my $grammar= q { start: tree tree: '(' treestr(s) ')' treestr: tree | tagstr tagstr: TAG ( tree | word ) TAG: /[A-Z.]+ / word: /[\w?!.]+/ }; my $parser=Parse::RecDescent->new($grammar); my $text = "(SBARQ (WHNP (WP What))(SQ (VBZ is)(NP (NNP Head)(NNP Start)))(. ?))"; my $result = $parser->start( \$text ); print $text, "\n"; print Dumper($result);