sbsv1_os/e32toolp/e32util/armasm2as.pl
branchRCL_3
changeset 73 22bdd8a90cc4
parent 18 99082257a271
--- a/sbsv1_os/e32toolp/e32util/armasm2as.pl	Mon Jun 21 16:57:06 2010 +0300
+++ b/sbsv1_os/e32toolp/e32util/armasm2as.pl	Thu Sep 30 14:38:30 2010 +0800
@@ -288,12 +288,14 @@
 	$val =~ s/\{TRUE\}/(1)/g;
 	$val =~ s/\{FALSE\}/(0)/g;
 
-	my @lops = split( /(\s*\:LAND\:\s*|\s*\:LOR\:\s*|\s*\:LNOT\:\s*|\s*\:DEF\:\s*)/, $val );
+	my @lops = split( /(\s*\:LAND\:\s*|\s*\:LOR\:\s*|\s*\:LNOT\:\s*|\s*\:DEF\:\s*|\s*\(\s*|\s*\)\s*)/, $val );
 	foreach (@lops) {
 		s/\s*\:LAND\:\s*/\:LAND\:/go;
 		s/\s*\:LOR\:\s*/\:LOR\:/go;
 		s/\s*\:LNOT\:\s*/\:LNOT\:/go;
 		s/\s*\:DEF\:\s*/\:DEF\:/go;
+		s/\s*\(\s*/\(/go;
+		s/\s*\)\s*/\)/go;
 	}
 	my @lops2;
 	while (scalar (@lops)) {
@@ -320,12 +322,28 @@
 	while (scalar (@lops2)) {
 		my $x = shift @lops2;
 		if ($x eq ':LNOT:') {
-			my $operand;
-			while (1) {
+			my $operand= shift @lops2;
+			while( @lops2 && $operand =~ /^\s*$/) {
 				$operand = shift @lops2;
-				last if ($operand !~ /^\s*$/);
 			}
-			push @lops3, "(0==($operand))";
+			if($operand eq '(') {
+				my $balance = 1;
+				my $compound = $operand;
+				while($balance > 0 && @lops2) {
+					$operand = shift @lops2;
+					if($operand eq '(') {
+						++$balance;
+					}
+					elsif ($operand eq ')') {
+						--$balance;
+					}
+					$compound .= $operand;
+				}
+				push @lops3, "(0==$compound)";
+			}
+			else {
+				push @lops3, "(0==($operand))";
+			}
 		} else {
 			push @lops3, $x;
 		}