Dwood has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; my %hash_glob; my %hash_scrip; my @value_types = qw(boolean real short long string trigger_volume cut +scene_flag cutscene_camera_point cutscene_title cutscene_recording de +vice_group ai ai_command_list starting_profile conversation hud_message object_list sound effect damage looping_soun +d animation_graph actor_variant damage_effect object_definition game_difficulty team ai_default_state actor_type hud +_corner object unit vehicle weapon device scenery object_name unit_name vehicle_name weapon_name d +evice_name scenery_name); my @script_types = qw(startup dormant continuous static stub); my $glob_count = 0; my $pre_decl = " "; sub empty { my $FILTER = 'a-zA-Z0-9'; my $string = shift (@_); my $test = $string; $test =~ s/[^$FILTER]//go; if($test){ print "\n"; return 0; } else { print "\nlast line is empty!\n"; return 1; } } sub parenth_count { my $string = shift (@_); my $l_count = () = ($string =~ /\(/g); my $r_count = () = ($string =~ /\)/g); if ($l_count != $r_count) { print "There is no balance on this line ($l_count vs $ +r_count)! Did you format it correctly??? \n"; return 0; } else { print "There is balance, but is the logic correct?\n"; return 1; } } sub remove_all_but { my @tempArray = split( " ", shift (@_)); my $i = shift (@_); if (exists $tempArray[$i]) { my $string = $tempArray[$i]; print "\n $string \n"; return $string; } else { return " ";} } sub check_value_assigned { my $string = shift (@_); if ($string eq " "){ print "\n There is no value assigned!!!!\n"; return "undef"; } else { print "$string\n"; return $string; } } sub get_type_nohash { my $string = shift (@_); $string = remove_all_but($string, 0); print "Getting type!\n"; $string = check_value_assigned ($string); return $string; } sub get_value_type_nohash { my $string = shift(@_); $string = remove_all_but($string, 1); print "Getting value type!\n"; $string = check_value_assigned ($string); return $string; } sub get_name_nohash { my $string = shift (@_); $string = remove_all_but ($string, 2); print "Getting Name!\n"; $string = check_value_assigned ($string); return $string; } sub get_val_nohash { my $string = shift (@_); $string = remove_all_but ($string, 3); print "Getting value! \n"; $string = check_value_assigned ($string); return $string; } sub global_check { my $string = shift (@_); my $indices = index ($string, "global"); my $declarator = substr $string, $indices, 7; if ( $pre_decl ne $declarator ){ print "Global found!\n"; $pre_decl = $declarator; return 1; } else { print "No global found on this line!"; return 0; } } sub global_operations { my $string = shift (@_); my $name = get_name_nohash($string); if ((exists $hash_glob->{$name}) == 0) { print "\nMade it to the globs!\n"; $hash_glob -> { $name} = { NAME => "e\n", TYPE => "BOOLEAN", VALUE => "value" }; $hash_glob->{$name}{NAME}; } else { print "The global $name already exists!\n" ; } } sub basic_operations { my $testString = shift (@_); if (empty ($testString) == 0) { print "There is stuff in string!\n"; if (parenth_count($testString) == 1) { if (global_check($testString) == 1){ print "Global check made it through alive!\n"; global_operations($testString); } } } } my $placeholder = " "; my $baseString = "(global boolean dwood_is_leet true)"; basic_operations($baseString);
(global short rounds_completed 0) (script static unit player (unit (list_get (players) 0))) (script static void music_ambercladremix (sound_looping_start "sound\moooseguy\sound_looping\ambercladremi +x" none 1) ) (script dormant death_cutscene (enable_hud_help_flash false) (show_hud_help_text false) (sleep 30) (camera_set death7 100) (sleep 50) (camera_set death8 110) (cinematic_set_title gameover) (sleep 150) (fade_out 0 0 0 30) (sleep 50) (cinematic_stop) (wake credits_cutscene) )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing SExpressions (lisp)
by GrandFather (Saint) on Nov 21, 2010 at 01:01 UTC | |
by Dwood (Acolyte) on Nov 21, 2010 at 08:04 UTC | |
|
Re: Parsing SExpressions (lisp)
by ELISHEVA (Prior) on Nov 21, 2010 at 08:09 UTC | |
by Dwood (Acolyte) on Nov 22, 2010 at 00:20 UTC | |
|
Re: Parsing SExpressions (lisp)
by LanX (Saint) on Nov 21, 2010 at 14:50 UTC |