From 5730d56d542fc520589905711f72ff792095e535 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 28 Jun 2014 10:18:28 +0000 Subject: [PATCH] CGrammar: Improvements to translation of comma operator --- PBot/VERSION.pm | 4 ++-- modules/c2english/CGrammar.pm | 9 +++++---- modules/c2english/c2eng.pl | 4 +++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 6d8b8f3e..35f7e000 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 682, - BUILD_DATE => "2014-06-27", + BUILD_REVISION => 683, + BUILD_DATE => "2014-06-28", }; 1; diff --git a/modules/c2english/CGrammar.pm b/modules/c2english/CGrammar.pm index 1c480946..0983b97c 100644 --- a/modules/c2english/CGrammar.pm +++ b/modules/c2english/CGrammar.pm @@ -365,10 +365,11 @@ expression: { if($arg{context} eq 'for increment statement') { $return = join(', then ', @{$item[-1]}); + } elsif( $arg{context} =~ /conditional/) { + $return = join(' and the result discarded and ', @{$item[-1]}); } else { - my $that = $arg{context} =~ /conditional/ ? ' that' : ''; - $return .= "Evaluate$that " if @{$item[-1]} > 1; - $return .= join(" and then discard the result and then evaluate$that ^L", @{$item[-1]}); + $return .= "Evaluate " if @{$item[-1]} > 1; + $return .= join(" and discard the result and then evaluate ^L", @{$item[-1]}); } } @@ -530,7 +531,7 @@ logical_OR_AND_expression: rel_add_mul_shift_expression[context => 'logical_OR_AND_expression']> { if (defined $arg{context} and $arg{context} eq 'for conditional') { print STDERR "hmm2\n"; } - $return = join ('' , @{$item[1]}); + $return = join ('', @{$item[1]}); } log_OR_AND_bit_or_and_eq: diff --git a/modules/c2english/c2eng.pl b/modules/c2english/c2eng.pl index 50fa3fe6..8a7280cc 100755 --- a/modules/c2english/c2eng.pl +++ b/modules/c2english/c2eng.pl @@ -93,12 +93,14 @@ sub istrue { my ($result, $and) = ('', ''); foreach my $part (@parts) { $result .= $and; - if($part !~ /(discard the result|greater|less|equal|false$)/) { + if($part !~ /(discard the result|result discarded|greater|less|equal|false$)/) { $result .= "$part is nonzero"; } else { $result .= $part; } $and = ' and '; } + $result =~ s/is nonzero and the result discarded/is evaluated and the result discarded/g; + $result =~ s/is ((?:(?!evaluated).)+) and the result discarded/is evaluated to be $1 and the result discarded/g; return $result; }