3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

CGrammar: fix enumerations, improve for-loops and comma operators

This commit is contained in:
Pragmatic Software 2014-06-09 10:00:13 +00:00
parent ec1fd207a6
commit ffab2c6f3b
2 changed files with 23 additions and 27 deletions

View File

@ -13,8 +13,8 @@ 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 => 621, BUILD_REVISION => 622,
BUILD_DATE => "2014-06-08", BUILD_DATE => "2014-06-09",
}; };
1; 1;

View File

@ -63,11 +63,9 @@ macro_definition:
push @macros, $item[3]; push @macros, $item[3];
if ($#symbols > 0) { if ($#symbols > 0) {
$last = pop @symbols; $last = pop @symbols;
$return .= "with the symbols '" . join("', '",@symbols) . "' and '$last' "; $return .= "with the symbols " . join(", ",@symbols) . " and $last ";
} elsif ($#symbols > 0) {
$return .= "with the symbols '$symbols[0]' and '$symbols[1]' ";
} else { } else {
$return .= "with the symbol '$symbols[0]' "; $return .= "with the symbol $symbols[0] ";
} }
$return .= "to use the token sequence \'$item{token_sequence}\'.\n"; $return .= "to use the token sequence \'$item{token_sequence}\'.\n";
} }
@ -311,7 +309,7 @@ iteration_statement:
$return .= $item{statement} ; $return .= $item{statement} ;
if ($increment) { if ($increment) {
$return .= "Finally, ^L$increment.\n"; $return .= "After each iteration, ^L$increment.\n";
} }
} }
| 'while' '(' <commit> expression ')' statement[context => 'while loop'] | 'while' '(' <commit> expression ')' statement[context => 'while loop']
@ -395,7 +393,7 @@ labeled_statement:
expression: expression:
<leftop: assignment_expression[context => $arg{context}] ',' assignment_expression[context => $arg{context}]> <leftop: assignment_expression[context => $arg{context}] ',' assignment_expression[context => $arg{context}]>
{ {
$return = join(". We're not done yet. ",@{$item[-1]}); $return = join(", then ^L",@{$item[-1]});
} }
assignment_expression: assignment_expression:
@ -529,8 +527,8 @@ logical_OR_AND_expression:
} }
log_OR_AND_bit_or_and_eq: log_OR_AND_bit_or_and_eq:
'||' { $return = ' logically orred by '; } '||' { $return = ' or '; }
| '&&' { $return = ' logically anded by '; } | '&&' { $return = ' and '; }
| '|' { $return = ' bitwise orred by '; } | '|' { $return = ' bitwise orred by '; }
| '&' { $return = ' bitwise anded by '; } | '&' { $return = ' bitwise anded by '; }
| '^' { $return = ' bitwise xorred by ';} | '^' { $return = ' bitwise xorred by ';}
@ -1218,29 +1216,27 @@ struct_or_union:
enum_specifier: enum_specifier:
'enum' identifier(?) '{' enumerator_list '}' 'enum' identifier(?) '{' enumerator_list '}'
{ {
$return = 'enumeration ' ; $return .= 'an enumeration';
if (@{$item{'identifier(?)'}}){ my @enumerator_list = @{$item{enumerator_list}};
$return .= 'identified as ' . join('',@{$item{'identifier(?)'}}) . ' ';
if(@enumerator_list == 1) {
$return .= " of $enumerator_list[0]";
} else {
my $last = pop @enumerator_list;
$return .= ' of ' . join(', ', @enumerator_list) . " and $last";
} }
$return .= 'comprising of ' . $item{enumerator_list} ; if (@{$item{'identifier(?)'}}){
$return .= ' identified as ' . join('',@{$item{'identifier(?)'}});
}
} }
| 'enum' identifier | 'enum' identifier
{ $return = ($item{identifer} =~ m/^[aieouy]/ ? 'an ' : 'a ') . "$item{identifier} enumeration"; }
enumerator_list: enumerator_list:
(enumerator ',')(s?) enumerator <leftop:enumerator ',' enumerator>
{
my @enumerator_list = @{$item[1]};
if ($#enumerator_list > 1) {
$return = join(', ', @enumerator_list) . ', and ' . $item{enumerator};
} elsif ($#enumerator_list == 1) {
$return = $enumerator_list[1] . ' and ' . $item{enumerator};
} else {
$return = $item{enumerator_declaration};
}
}
enumerator: enumerator:
identifier ( '=' constant_expression )(?) identifier ( '=' constant_expression )(?)