in reply to Need a start point for resolving {[()]}

This piece of code could be a starting point. Also look at Re: Convert Tcl Keyed List to Perl where I use the same technique in a different context.

# node 1030367 use strict; use warnings; my $expr = '(A&(B&C)|((C&D)|\((A EQ 1)))'; my $level = 0; my $tab = "| "; my %action = ( '(' => sub { print "\n", $tab x ++$level, shift }, ')' => sub { print "\n", $tab x $level--, shift }, 'default' => sub { print shift }, ); ( $action{$_} // $action{'default'} )->($_) for $expr =~ /./g;

Replies are listed 'Best First'.
Re^2: Need a start point for resolving {[()]}
by exilepanda (Friar) on Jun 13, 2013 at 11:39 UTC
    Wow! This inspires a lot, by level shifting and tabbing! A very nice start point! Looks much more neat and firm. Thanks for the lead!