3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

CGrammar: Improve arrays and fix array initialization

This commit is contained in:
Pragmatic Software 2014-06-12 13:13:45 +00:00
parent e29bd99b42
commit c6e893a4fa
2 changed files with 25 additions and 8 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 633, BUILD_REVISION => 634,
BUILD_DATE => "2014-06-12", BUILD_DATE => "2014-06-12",
}; };

View File

@ -570,7 +570,7 @@ rel_mul_add_ex_op:
unary_operator: unary_operator:
'&' { $return = 'the address of '; } '&' { $return = 'the address of '; }
| '*' { $return = 'the contents of '; } | '*' { $return = 'the contents of '; }
| '+' { $return = 'the value of '; } | '+' { $return = ''; }
| '-' ...constant { $return = 'negative '; } | '-' ...constant { $return = 'negative '; }
| '-' { $return = 'minus '; } | '-' { $return = 'minus '; }
| '~' { $return = "the one's complement of "; } | '~' { $return = "the one's complement of "; }
@ -776,7 +776,7 @@ initializer:
} }
} }
| '{' comment(?) initializer_list (',' )(?) '}' | '{' comment(?) initializer_list (',' )(?) '}'
{ $return = 'the set ' . join('', @{$item{'initializer_list(?)'}}); } { $return = 'the set ' . $item{'initializer_list'}; }
initializer_list: initializer_list:
<leftop: initializer ',' initializer > <leftop: initializer ',' initializer >
@ -870,13 +870,30 @@ postfix_expression:
{ {
my $item_expression = ''; my $item_expression = '';
if (@{$item[-1]}) { if (@{$item[-1]}) {
$item_expression=join(',',@{$item[-1]}); $item_expression = join(' and ', @{$item[-1]});
$basic =~ s/^'//;
$basic =~ s/\'$//;
} }
if ( length $item_expression) { if (length $item_expression) {
$return = "array $basic\'s element at address ($item_expression)"; if($item_expression =~ /^\d+$/) {
$item_expression++;
my ($last_digit) = $item_expression =~ /(\d)$/;
if($last_digit == 1) {
$item_expression .= 'st';
} elsif($last_digit == 2) {
$item_expression .= 'nd';
} elsif($last_digit == 3) {
$item_expression .= 'rd';
} else {
$item_expression .= 'th';
}
$return = "the $item_expression element of array $basic";
} elsif($item_expression =~ /^-\s*\d+$/) {
$item_expression *= -1;
my $plural = $item_expression == 1 ? '' : 's';
$return = "the location $item_expression element$plural backwards from where $basic points";
} else {
$return = "the element of $basic at location $item_expression";
}
} }
} }