CGrammar: Put space after if/while/for keywords

This commit is contained in:
Pragmatic Software 2014-07-01 16:21:52 +00:00
parent b66e9502d7
commit d6c20bc051
2 changed files with 110 additions and 110 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 => 687, BUILD_REVISION => 688,
BUILD_DATE => "2014-07-01", BUILD_DATE => "2014-07-01",
}; };

View File

@ -145,13 +145,13 @@ function_definition:
my $parameter_list = $item{declarator}->[1]; my $parameter_list = $item{declarator}->[1];
my $return_type; my $return_type;
if(@{$item{declarator}} > 2) { if (@{$item{declarator}} > 2) {
$return_type = "$item{declarator}->[2] $declaration_specifiers"; $return_type = "$item{declarator}->[2] $declaration_specifiers";
} else { } else {
$return_type = $declaration_specifiers; $return_type = $declaration_specifiers;
} }
if($return_type =~ s/( with.*)$//) { if ($return_type =~ s/( with.*)$//) {
my $storage_class_specifier = $1; my $storage_class_specifier = $1;
$parameter_list =~ s/function/function$storage_class_specifier/; $parameter_list =~ s/function/function$storage_class_specifier/;
} }
@ -242,8 +242,8 @@ iteration_statement:
} }
| 'while' '(' <commit> expression[context => 'while conditional'] ')' statement[context => 'while loop'] | 'while' '(' <commit> expression[context => 'while conditional'] ')' statement[context => 'while loop']
{ {
if($item{expression} =~ /(^\d+$)/) { if ($item{expression} =~ /(^\d+$)/) {
if($1 == 0) { if ($1 == 0) {
$return = "Never ^L"; $return = "Never ^L";
} else { } else {
$return = "Repeatedly ^L"; $return = "Repeatedly ^L";
@ -253,7 +253,7 @@ iteration_statement:
$return = "While ^L$expression, ^L"; $return = "While ^L$expression, ^L";
} }
if($item{statement}) { if ($item{statement}) {
$return .= $item{statement} . "\n"; $return .= $item{statement} . "\n";
} else { } else {
$return .= "do nothing.\n"; $return .= "do nothing.\n";
@ -263,8 +263,8 @@ iteration_statement:
{ {
$item{statement} =~ s/^do nothing/nothing/i; $item{statement} =~ s/^do nothing/nothing/i;
$return = "Do the following:^L $item{statement}"; $return = "Do the following:^L $item{statement}";
if($item{expression} =~ /(^\d+$)/) { if ($item{expression} =~ /(^\d+$)/) {
if($1 == 0) { if ($1 == 0) {
$return .= "Do this once.\n"; $return .= "Do this once.\n";
} else { } else {
$return .= "Do this repeatedly.\n"; $return .= "Do this repeatedly.\n";
@ -288,8 +288,8 @@ for_increment:
selection_statement: selection_statement:
'if' <commit> '(' expression[context => 'if conditional'] ')' statement[context => 'if statement'] 'if' <commit> '(' expression[context => 'if conditional'] ')' statement[context => 'if statement']
{ {
if($item{expression} =~ /^(\d+)$/) { if ($item{expression} =~ /^(\d+)$/) {
if($1 == 0) { if ($1 == 0) {
$return = "Never "; $return = "Never ";
} else { } else {
$return = "Always "; $return = "Always ";
@ -312,9 +312,9 @@ selection_statement:
jump_statement: jump_statement:
'break' ';' 'break' ';'
{ {
if($arg{context} eq 'switch' or $arg{context} eq 'case') { if ($arg{context} eq 'switch' or $arg{context} eq 'case') {
$return = "Break case.\n"; $return = "Break case.\n";
} elsif(length $arg{context}) { } elsif (length $arg{context}) {
$return = "Break from the $arg{context}.\n"; $return = "Break from the $arg{context}.\n";
} else { } else {
$return = "Break from the current block.\n"; $return = "Break from the current block.\n";
@ -343,7 +343,7 @@ expression_statement:
{ {
my $expression = join('',@{$item[1]}); my $expression = join('',@{$item[1]});
if (!$expression) { if (!$expression) {
if($arg{context} eq 'label' if ($arg{context} eq 'label'
or $arg{context} eq 'for init' or $arg{context} eq 'for init'
or $arg{context} eq 'for conditional') { or $arg{context} eq 'for conditional') {
$return = ""; $return = "";
@ -367,10 +367,10 @@ labeled_statement:
expression: expression:
<leftop: assignment_expression ',' assignment_expression> <leftop: assignment_expression ',' assignment_expression>
{ {
if($arg{context} eq 'for increment statement' if ($arg{context} eq 'for increment statement'
or $arg{context} eq 'for init') { or $arg{context} eq 'for init') {
$return = join(', then ', @{$item[-1]}); $return = join(', then ', @{$item[-1]});
} elsif( $arg{context} =~ /conditional/) { } elsif ( $arg{context} =~ /conditional/) {
$return = join(' and the result discarded and ', @{$item[-1]}); $return = join(' and the result discarded and ', @{$item[-1]});
} else { } else {
$return .= "Evaluate " if @{$item[-1]} > 1; $return .= "Evaluate " if @{$item[-1]} > 1;
@ -399,14 +399,14 @@ assignment_expression:
conditional_expression: conditional_expression:
logical_OR_AND_expression conditional_ternary_expression logical_OR_AND_expression conditional_ternary_expression
{ {
if($item{conditional_ternary_expression}) { if ($item{conditional_ternary_expression}) {
my $op1 = $item{conditional_ternary_expression}->[0]; my $op1 = $item{conditional_ternary_expression}->[0];
my $op2 = $item{conditional_ternary_expression}->[1]; my $op2 = $item{conditional_ternary_expression}->[1];
my $expression = ::istrue $item{logical_OR_AND_expression}; my $expression = ::istrue $item{logical_OR_AND_expression};
if($arg{context} =~ /statement$/) { if ($arg{context} =~ /statement$/) {
$return = "$op1 if $expression otherwise to $op2"; $return = "$op1 if $expression otherwise to $op2";
} elsif($arg{context} =~ /assignment expression$/) { } elsif ($arg{context} =~ /assignment expression$/) {
$return = "$op1 if $expression otherwise to be $op2"; $return = "$op1 if $expression otherwise to be $op2";
} else { } else {
$return = "$op1 if $expression otherwise $op2"; $return = "$op1 if $expression otherwise $op2";
@ -543,7 +543,7 @@ logical_OR_AND_expression:
rel_add_mul_shift_expression[context => '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"; } 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: log_OR_AND_bit_or_and_eq:
@ -578,7 +578,7 @@ unary_operator:
| '!' '!' { $return = 'the normalized boolean value of ^L'; } | '!' '!' { $return = 'the normalized boolean value of ^L'; }
| '!' | '!'
{ {
if($arg{context} =~ /conditional/) { if ($arg{context} =~ /conditional/) {
$return = ['', ' is false']; $return = ['', ' is false'];
} else { } else {
$return = 'the logical negation of ^L'; $return = 'the logical negation of ^L';
@ -589,7 +589,7 @@ rel_add_mul_shift_expression:
cast_expression ...';' cast_expression ...';'
{ $return = $item{cast_expression}; } { $return = $item{cast_expression}; }
| <leftop: cast_expression rel_mul_add_ex_op cast_expression> | <leftop: cast_expression rel_mul_add_ex_op cast_expression>
{ $return = join ('' , @{$item[1]}); } { $return = join('' , @{$item[1]}); }
closure: closure:
',' | ';' | ')' ',' | ';' | ')'
@ -611,10 +611,10 @@ declaration:
my $typedef = $item{declaration_specifiers} =~ s/^type definition of //; my $typedef = $item{declaration_specifiers} =~ s/^type definition of //;
my $inits = 0; my $inits = 0;
while(@init_list) { while (@init_list) {
$inits++; $inits++;
if(not $arg{context} eq 'struct member') { if (not $arg{context} eq 'struct member') {
if($arg{context} eq 'for init') { if ($arg{context} eq 'for init') {
$return .= "letting "; $return .= "letting ";
} else { } else {
$return .= "Let "; $return .= "Let ";
@ -626,14 +626,14 @@ declaration:
my ($first_qualifier, $first_initializer); my ($first_qualifier, $first_initializer);
my $first_identifier = shift @args; my $first_identifier = shift @args;
if(not length $first_identifier) { if (not length $first_identifier) {
$first_identifier = 'there'; $first_identifier = 'there';
} }
my @identifiers = ($first_identifier); my @identifiers = ($first_identifier);
my $next_arg = shift @args; my $next_arg = shift @args;
if($next_arg =~ m/initialized/) { if ($next_arg =~ m/initialized/) {
$first_initializer = $next_arg; $first_initializer = $next_arg;
$first_qualifier = shift @args // ''; $first_qualifier = shift @args // '';
} else { } else {
@ -641,7 +641,7 @@ declaration:
$first_initializer = shift @args // ''; $first_initializer = shift @args // '';
} }
if($first_initializer !~ /^initialized/) { if ($first_initializer !~ /^initialized/) {
$first_qualifier .= " $first_initializer" if $first_initializer; $first_qualifier .= " $first_initializer" if $first_initializer;
$first_initializer = ''; $first_initializer = '';
} }
@ -649,18 +649,18 @@ declaration:
my $remaining_args = join(' ', @args); my $remaining_args = join(' ', @args);
my @initializers; my @initializers;
if($first_initializer) { if ($first_initializer) {
push @initializers, [ $first_identifier, $first_initializer ]; push @initializers, [ $first_identifier, $first_initializer ];
} }
for(my $i = 0; $i < @init_list; $i++) { for (my $i = 0; $i < @init_list; $i++) {
@args = ::flatten $init_list[$i]; @args = ::flatten $init_list[$i];
my ($qualifier, $initializer); my ($qualifier, $initializer);
my $identifier = shift @args; my $identifier = shift @args;
$next_arg = shift @args; $next_arg = shift @args;
if($next_arg =~ m/initialized/) { if ($next_arg =~ m/initialized/) {
$initializer = $next_arg; $initializer = $next_arg;
$qualifier = shift @args // ''; $qualifier = shift @args // '';
} else { } else {
@ -671,35 +671,35 @@ declaration:
next unless $qualifier eq $first_qualifier; next unless $qualifier eq $first_qualifier;
push @identifiers, $identifier; push @identifiers, $identifier;
if($initializer) { if ($initializer) {
push @initializers, [ $identifier, $initializer ]; push @initializers, [ $identifier, $initializer ];
} }
splice @init_list, $i--, 1; splice @init_list, $i--, 1;
} }
if($arg{context} eq 'struct member') { if ($arg{context} eq 'struct member') {
if($inits > 1 and not @init_list) { if ($inits > 1 and not @init_list) {
$return .= ' and '; $return .= ' and ';
} elsif($inits > 1) { } elsif ($inits > 1) {
$return .= ', '; $return .= ', ';
} }
if($first_qualifier) { if ($first_qualifier) {
if($first_qualifier =~ /bit\-field/) { if ($first_qualifier =~ /bit\-field/) {
$first_qualifier = "$item{declaration_specifiers} $first_qualifier"; $first_qualifier = "$item{declaration_specifiers} $first_qualifier";
$item{declaration_specifiers} = ''; $item{declaration_specifiers} = '';
} }
if(@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) { if (@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) {
$return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a '; $return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a ';
} elsif(@identifiers > 1 and not $typedef) { } elsif (@identifiers > 1 and not $typedef) {
$first_qualifier =~ s/pointer/pointers/; $first_qualifier =~ s/pointer/pointers/;
$first_qualifier =~ s/an array/arrays/; $first_qualifier =~ s/an array/arrays/;
} }
$return .= "$first_qualifier $item{declaration_specifiers} "; $return .= "$first_qualifier $item{declaration_specifiers} ";
} else { } else {
if(@identifiers == 1 and $item{declaration_specifiers} !~ /^(a|an)\s+/) { if (@identifiers == 1 and $item{declaration_specifiers} !~ /^(a|an)\s+/) {
$return .= $item{declaration_specifiers} =~ m/^[aeiouy]/ ? 'an ' : 'a '; $return .= $item{declaration_specifiers} =~ m/^[aeiouy]/ ? 'an ' : 'a ';
} }
$return .= "$item{declaration_specifiers} "; $return .= "$item{declaration_specifiers} ";
@ -707,8 +707,8 @@ declaration:
my $and = @identifiers > 1 ? ' and ' : ''; my $and = @identifiers > 1 ? ' and ' : '';
my $comma = ''; my $comma = '';
for(my $i = 0; $i < @identifiers; $i++) { for (my $i = 0; $i < @identifiers; $i++) {
if($i == @identifiers - 1) { if ($i == @identifiers - 1) {
$return .= "$and$identifiers[$i]"; $return .= "$and$identifiers[$i]";
} else { } else {
$return .= "$comma$identifiers[$i]"; $return .= "$comma$identifiers[$i]";
@ -718,8 +718,8 @@ declaration:
} else { } else {
my $and = @identifiers > 1 ? ' and ' : ''; my $and = @identifiers > 1 ? ' and ' : '';
my $comma = ''; my $comma = '';
for(my $i = 0; $i < @identifiers; $i++) { for (my $i = 0; $i < @identifiers; $i++) {
if($i == @identifiers - 1) { if ($i == @identifiers - 1) {
$return .= "$and$identifiers[$i]"; $return .= "$and$identifiers[$i]";
} else { } else {
$return .= "$comma$identifiers[$i]"; $return .= "$comma$identifiers[$i]";
@ -727,7 +727,7 @@ declaration:
} }
} }
if($typedef) { if ($typedef) {
$return .= ' each' if @identifiers > 1; $return .= ' each' if @identifiers > 1;
$return .= ' be another name for '; $return .= ' be another name for ';
push @typedefs, @identifiers; push @typedefs, @identifiers;
@ -735,10 +735,10 @@ declaration:
$return .= ' be '; $return .= ' be ';
} }
if($first_qualifier) { if ($first_qualifier) {
if(@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) { if (@identifiers == 1 and $first_qualifier !~ /^(a|an)\s+/) {
$return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a '; $return .= $first_qualifier =~ m/^[aeiouy]/ ? 'an ' : 'a ';
} elsif(@identifiers > 1 and not $typedef) { } elsif (@identifiers > 1 and not $typedef) {
$first_qualifier =~ s/pointer/pointers/; $first_qualifier =~ s/pointer/pointers/;
$first_qualifier =~ s/an array/arrays/; $first_qualifier =~ s/an array/arrays/;
} }
@ -746,31 +746,31 @@ declaration:
$return .= "$remaining_args " if $remaining_args; $return .= "$remaining_args " if $remaining_args;
$return .= $item{declaration_specifiers}; $return .= $item{declaration_specifiers};
} else { } else {
if(@identifiers == 1 and $item{declaration_specifiers} !~ /^(a|an)\s+/) { if (@identifiers == 1 and $item{declaration_specifiers} !~ /^(a|an)\s+/) {
$return .= $item{declaration_specifiers} =~ m/^[aeiouy]/ ? 'an ' : 'a '; $return .= $item{declaration_specifiers} =~ m/^[aeiouy]/ ? 'an ' : 'a ';
} }
$return .= "$remaining_args " if $remaining_args; $return .= "$remaining_args " if $remaining_args;
$return .= $item{declaration_specifiers}; $return .= $item{declaration_specifiers};
} }
if(@initializers) { if (@initializers) {
if(@identifiers > 1) { if (@identifiers > 1) {
$return .= ".\nInitialize "; $return .= ".\nInitialize ";
@initializers = sort { $a->[1] cmp $b->[1] } @initializers; @initializers = sort { $a->[1] cmp $b->[1] } @initializers;
my ($and, $comma); my ($and, $comma);
for(my $i = 0; $i < @initializers; $i++) { for (my $i = 0; $i < @initializers; $i++) {
my ($identifier, $initializer) = @{$initializers[$i]}; my ($identifier, $initializer) = @{$initializers[$i]};
if($i < @initializers - 1 and $initializer eq $initializers[$i + 1]->[1]) { if ($i < @initializers - 1 and $initializer eq $initializers[$i + 1]->[1]) {
$return .= "$comma$identifier"; $return .= "$comma$identifier";
$comma = ', '; $comma = ', ';
$and = ' and '; $and = ' and ';
} else { } else {
$initializer =~ s/^initialized to \^L//; $initializer =~ s/^initialized to \^L//;
$return .= "$and$identifier to $initializer"; $return .= "$and$identifier to $initializer";
if($i < @initializers - 2) { if ($i < @initializers - 2) {
$and = $comma = ', '; $and = $comma = ', ';
} else { } else {
$and = ' and '; $and = ' and ';
@ -842,7 +842,7 @@ unary_expression:
if ($arg{context} =~ /statement$/ ) { if ($arg{context} =~ /statement$/ ) {
$return = "pre-increment $item{unary_expression}"; $return = "pre-increment $item{unary_expression}";
} else { } else {
if($item{unary_expression} =~ s/^the member//) { if ($item{unary_expression} =~ s/^the member//) {
$return = "the pre-incremented member $item{unary_expression}"; $return = "the pre-incremented member $item{unary_expression}";
} else { } else {
$return = "pre-incremented $item{unary_expression}"; $return = "pre-incremented $item{unary_expression}";
@ -854,7 +854,7 @@ unary_expression:
if ($arg{context} =~ /statement$/ ) { if ($arg{context} =~ /statement$/ ) {
$return = "Pre-decrement $item{unary_expression}"; $return = "Pre-decrement $item{unary_expression}";
} else { } else {
if($item{unary_expression} =~ s/^the member//) { if ($item{unary_expression} =~ s/^the member//) {
$return = "the pre-decremented member $item{unary_expression}"; $return = "the pre-decremented member $item{unary_expression}";
} else { } else {
$return = "pre-decremented $item{unary_expression}"; $return = "pre-decremented $item{unary_expression}";
@ -863,7 +863,7 @@ unary_expression:
} }
| unary_operator cast_expression | unary_operator cast_expression
{ {
if(ref $item{unary_operator} eq 'ARRAY') { if (ref $item{unary_operator} eq 'ARRAY') {
$return = $item{unary_operator}->[0] . $item{cast_expression} . $item{unary_operator}->[1]; $return = $item{unary_operator}->[0] . $item{cast_expression} . $item{unary_operator}->[1];
} else { } else {
$return = $item{unary_operator} . $item{cast_expression}; $return = $item{unary_operator} . $item{cast_expression};
@ -883,7 +883,7 @@ postfix_productions:
$arg{primary_expression} =~ s/^Evaluate the expression/resulting from the expression/; $arg{primary_expression} =~ s/^Evaluate the expression/resulting from the expression/;
if(not defined $arg{context} or $arg{context} ne 'statement') { if (not defined $arg{context} or $arg{context} ne 'statement') {
$return = "the result of the function $arg{primary_expression}"; $return = "the result of the function $arg{primary_expression}";
} else { } else {
$return = "Call the function $arg{primary_expression} "; $return = "Call the function $arg{primary_expression} ";
@ -902,7 +902,7 @@ postfix_productions:
$return .= " with argument$arg_exp_list"; $return .= " with argument$arg_exp_list";
} }
if($postfix) { if ($postfix) {
$return =~ s/^(Call|Insert)/the result of/; $return =~ s/^(Call|Insert)/the result of/;
$return = "$postfix $return"; $return = "$postfix $return";
} }
@ -920,29 +920,29 @@ postfix_productions:
my $postfix = $item[-1]->[0]; my $postfix = $item[-1]->[0];
if (length $expression) { if (length $expression) {
if($expression =~ /^\d+$/) { if ($expression =~ /^\d+$/) {
$expression++; $expression++;
my ($last_digit) = $expression =~ /(\d)$/; my ($last_digit) = $expression =~ /(\d)$/;
if($last_digit == 1) { if ($last_digit == 1) {
if($expression =~ /11$/) { if ($expression =~ /11$/) {
$expression .= 'th'; $expression .= 'th';
} else { } else {
$expression .= 'st'; $expression .= 'st';
} }
} elsif($last_digit == 2) { } elsif ($last_digit == 2) {
$expression .= 'nd'; $expression .= 'nd';
} elsif($last_digit == 3) { } elsif ($last_digit == 3) {
$expression .= 'rd'; $expression .= 'rd';
} else { } else {
$expression .= 'th'; $expression .= 'th';
} }
if($arg{context} eq 'function call') { if ($arg{context} eq 'function call') {
$return = "the $expression element of^L"; $return = "the $expression element of^L";
} else { } else {
$return = "the $expression element of^L"; $return = "the $expression element of^L";
$return .= " $arg{primary_expression}" if $arg{primary_expression}; $return .= " $arg{primary_expression}" if $arg{primary_expression};
} }
} elsif($expression =~ /^-\s*\d+$/) { } elsif ($expression =~ /^-\s*\d+$/) {
$expression *= -1; $expression *= -1;
my $plural = $expression == 1 ? '' : 's'; my $plural = $expression == 1 ? '' : 's';
$return = "the location $expression element$plural backwards from where ^L$arg{primary_expression} points^L"; $return = "the location $expression element$plural backwards from where ^L$arg{primary_expression} points^L";
@ -951,7 +951,7 @@ postfix_productions:
} }
} }
if($postfix) { if ($postfix) {
$return = "$postfix $return"; $return = "$postfix $return";
} }
} }
@ -960,11 +960,11 @@ postfix_productions:
my $identifier = $item[-2]; my $identifier = $item[-2];
my $postfix = $item[-1]->[0]; my $postfix = $item[-1]->[0];
if($postfix) { if ($postfix) {
if(ref $postfix eq 'ARRAY') { if (ref $postfix eq 'ARRAY') {
$return = "$postfix->[0] the member $identifier $postfix->[1] of"; $return = "$postfix->[0] the member $identifier $postfix->[1] of";
} else { } else {
if($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) { if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
$return = "$postfix member $identifier of"; $return = "$postfix member $identifier of";
$return .= " the" unless $arg{context} =~ /array_address/; $return .= " the" unless $arg{context} =~ /array_address/;
} else { } else {
@ -972,17 +972,17 @@ postfix_productions:
$return = "$postfix the member $identifier of"; $return = "$postfix the member $identifier of";
$return .= " the" unless $arg{context} =~ /array_address/; $return .= " the" unless $arg{context} =~ /array_address/;
} }
if($arg{primary_expression}) { if ($arg{primary_expression}) {
$return =~ s/ the(\^L)?$/$1/; $return =~ s/ the(\^L)?$/$1/;
$return .= " ^L$arg{primary_expression}" $return .= " ^L$arg{primary_expression}"
} }
} }
} else { } else {
if($arg{context} =~ /array_address/) { if ($arg{context} =~ /array_address/) {
$return = "the member $identifier of^L"; $return = "the member $identifier of^L";
} else { } else {
$return = "the member $identifier of the^L"; $return = "the member $identifier of the^L";
if($arg{primary_expression}) { if ($arg{primary_expression}) {
$return =~ s/ the(\^L)?$/$1/; $return =~ s/ the(\^L)?$/$1/;
$return .= " $arg{primary_expression}"; $return .= " $arg{primary_expression}";
} }
@ -995,11 +995,11 @@ postfix_productions:
my $identifier = $item[-2]; my $identifier = $item[-2];
my $postfix = $item[-1]->[0]; my $postfix = $item[-1]->[0];
if($postfix) { if ($postfix) {
if(ref $postfix eq 'ARRAY') { if (ref $postfix eq 'ARRAY') {
$return = "$postfix->[0] the member $identifier $postfix->[1] of the structure pointed to by^L"; $return = "$postfix->[0] the member $identifier $postfix->[1] of the structure pointed to by^L";
} else { } else {
if($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) { if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
$return = "$postfix member $identifier of the structure pointed to by the^L"; $return = "$postfix member $identifier of the structure pointed to by the^L";
} else { } else {
$postfix =~ s/ the(\^L)?$/$1/; $postfix =~ s/ the(\^L)?$/$1/;
@ -1009,7 +1009,7 @@ postfix_productions:
} else { } else {
$return = "the member $identifier of the structure pointed to by the^L"; $return = "the member $identifier of the structure pointed to by the^L";
} }
if($arg{primary_expression}) { if ($arg{primary_expression}) {
$return =~ s/ the(\^L)?$/$1/; $return =~ s/ the(\^L)?$/$1/;
$return .= " $arg{primary_expression}"; $return .= " $arg{primary_expression}";
} }
@ -1019,13 +1019,13 @@ postfix_productions:
{ {
my $increment = join('',@{$item[-1]}); my $increment = join('',@{$item[-1]});
if ($increment) { if ($increment) {
if($arg{context} =~ /struct access/) { if ($arg{context} =~ /struct access/) {
if($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) { if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
$return = "the post-incremented"; $return = "the post-incremented";
} else { } else {
$return = "post-increment"; $return = "post-increment";
} }
} elsif($arg{context} =~ /statement/) { } elsif ($arg{context} =~ /statement/) {
$return = ['increment', 'by one']; $return = ['increment', 'by one'];
} else { } else {
$return = "post-incremented $arg{primary_expression}"; $return = "post-incremented $arg{primary_expression}";
@ -1036,13 +1036,13 @@ postfix_productions:
{ {
my $increment = join('',@{$item[-1]}); my $increment = join('',@{$item[-1]});
if ($increment) { if ($increment) {
if($arg{context} =~ /struct access/) { if ($arg{context} =~ /struct access/) {
if($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) { if ($arg{context} =~ /conditional/ or $arg{context} =~ /assignment expression/) {
$return = "the post-decremented"; $return = "the post-decremented";
} else { } else {
$return = "post-decrement"; $return = "post-decrement";
} }
} elsif($arg{context} =~ /statement/) { } elsif ($arg{context} =~ /statement/) {
$return = ['decrement', 'by one']; $return = ['decrement', 'by one'];
} else { } else {
$return = "post-decremented $arg{primary_expression}"; $return = "post-decremented $arg{primary_expression}";
@ -1062,11 +1062,11 @@ postfix_expression:
{ {
my $postfix_productions = $item{'postfix_productions'}; my $postfix_productions = $item{'postfix_productions'};
if(ref $postfix_productions eq 'ARRAY') { if (ref $postfix_productions eq 'ARRAY') {
$return = "$postfix_productions->[0] $item{primary_expression} $postfix_productions->[1]"; $return = "$postfix_productions->[0] $item{primary_expression} $postfix_productions->[1]";
} elsif(length $postfix_productions) { } elsif (length $postfix_productions) {
$return = $postfix_productions; $return = $postfix_productions;
} elsif(length $item{primary_expression}) { } elsif (length $item{primary_expression}) {
$return = $item{primary_expression}; $return = $item{primary_expression};
} else { } else {
$return = undef; $return = undef;
@ -1114,7 +1114,7 @@ primary_expression:
} }
$expression .= ')'; $expression .= ')';
if($arg{context} =~ /statement$/) { if ($arg{context} =~ /statement$/) {
$return = "Evaluate the expression "; $return = "Evaluate the expression ";
} else { } else {
$return = "The result of the expression "; $return = "The result of the expression ";
@ -1131,7 +1131,7 @@ declarator:
direct_declarator(s) direct_declarator(s)
{ {
my @direct_declarator = @{$item{'direct_declarator(s)'}}; my @direct_declarator = @{$item{'direct_declarator(s)'}};
if(@direct_declarator == 1) { if (@direct_declarator == 1) {
$return = $direct_declarator[0]; $return = $direct_declarator[0];
} else { } else {
$return = $item{'direct_declarator(s)'}; $return = $item{'direct_declarator(s)'};
@ -1151,7 +1151,7 @@ direct_declarator:
} }
| identifier[context => 'direct_declarator'] array_declarator(s?) | identifier[context => 'direct_declarator'] array_declarator(s?)
{ {
if(@{$item{'array_declarator(s?)'}}) { if (@{$item{'array_declarator(s?)'}}) {
$return = [$item{identifier}, join('', @{$item{'array_declarator(s?)'}})]; $return = [$item{identifier}, join('', @{$item{'array_declarator(s?)'}})];
} else { } else {
$return = $item{identifier}; $return = $item{identifier};
@ -1174,7 +1174,7 @@ array_declarator:
{ {
if (@{$item{'assignment_expression(?)'}}) { if (@{$item{'assignment_expression(?)'}}) {
my $size = join('', @{$item{'assignment_expression(?)'}}); my $size = join('', @{$item{'assignment_expression(?)'}});
if($size =~ /^(unsigned|long)*\s*1$/) { if ($size =~ /^(unsigned|long)*\s*1$/) {
$return = "$size element "; $return = "$size element ";
} else { } else {
$return = "$size elements "; $return = "$size elements ";
@ -1214,21 +1214,21 @@ parameter_list:
{ {
my @parameter_list = @{$item[1]}; my @parameter_list = @{$item[1]};
my $comma = ''; my $comma = '';
for(my $i = 0; $i < @parameter_list; $i++) { for (my $i = 0; $i < @parameter_list; $i++) {
$return .= $comma; $return .= $comma;
if(ref $parameter_list[$i] eq 'ARRAY') { if (ref $parameter_list[$i] eq 'ARRAY') {
my @list = ::flatten @{$parameter_list[$i]}; my @list = ::flatten @{$parameter_list[$i]};
if(@list == 0) { if (@list == 0) {
$return = "no parameters"; $return = "no parameters";
} elsif (@list == 1) { } elsif (@list == 1) {
if($list[0] eq 'void') { if ($list[0] eq 'void') {
$return = "no parameters"; $return = "no parameters";
} else { } else {
$return .= $list[0]; $return .= $list[0];
} }
} else { } else {
push @list, shift @list; push @list, shift @list;
if($list[0] =~ /^`.*`$/) { if ($list[0] =~ /^`.*`$/) {
my $identifier = shift @list; my $identifier = shift @list;
$return .= "$identifier as "; $return .= "$identifier as ";
$return .= join(' ', @list); $return .= join(' ', @list);
@ -1240,7 +1240,7 @@ parameter_list:
$return .= $parameter_list[$i]; $return .= $parameter_list[$i];
} }
if($i == $#parameter_list - 1) { if ($i == $#parameter_list - 1) {
$comma = ' and '; $comma = ' and ';
} else { } else {
$comma = ', '; $comma = ', ';
@ -1271,7 +1271,7 @@ direct_abstract_declarator:
| '[' constant_expression ']' | '[' constant_expression ']'
{ {
my $size = $item{constant_expression}; my $size = $item{constant_expression};
if($size =~ /^(unsigned|long)*\s*1$/) { if ($size =~ /^(unsigned|long)*\s*1$/) {
$return = "array of $size element of"; $return = "array of $size element of";
} else { } else {
$return = "array of $size elements of"; $return = "array of $size elements of";
@ -1296,7 +1296,7 @@ DAD: # macro for direct_abstract_declarator
identifier: identifier:
...!reserved identifier_word ...!reserved identifier_word
{ {
if(not grep { $_ eq $item{identifier_word} } @identifiers) { if (not grep { $_ eq $item{identifier_word} } @identifiers) {
push @identifiers, $item{identifier_word}; push @identifiers, $item{identifier_word};
} }
$return = $item{identifier_word}; $return = $item{identifier_word};
@ -1328,7 +1328,7 @@ declaration_specifiers:
my $decl_spec = join(' ', @{$item{'declaration_specifiers(?)'}}); my $decl_spec = join(' ', @{$item{'declaration_specifiers(?)'}});
$return = join('',@{$item{'comment(?)'}}); $return = join('',@{$item{'comment(?)'}});
if($item{storage_class_specifier} =~ m/^with/) { if ($item{storage_class_specifier} =~ m/^with/) {
if ($decl_spec) { $return .= "$decl_spec "; } if ($decl_spec) { $return .= "$decl_spec "; }
$return .= $item{storage_class_specifier}; $return .= $item{storage_class_specifier};
} else { } else {
@ -1355,7 +1355,7 @@ storage_class_specifier:
{ $return = "with automatic storage-duration"; } { $return = "with automatic storage-duration"; }
| 'extern' | 'extern'
{ {
if($arg{context} eq 'function definition') { if ($arg{context} eq 'function definition') {
$return = "with external linkage"; $return = "with external linkage";
} else { } else {
$return = "with external linkage, possibly defined elsewhere"; $return = "with external linkage, possibly defined elsewhere";
@ -1363,9 +1363,9 @@ storage_class_specifier:
} }
| 'static' | 'static'
{ {
if($arg{context} eq 'function definition') { if ($arg{context} eq 'function definition') {
$return = "with internal linkage"; $return = "with internal linkage";
} elsif($arg{context} eq 'function definition statement') { } elsif ($arg{context} eq 'function definition statement') {
$return = "with life-time duration"; $return = "with life-time duration";
} else { } else {
$return = "with internal linkage and life-time duration"; $return = "with internal linkage and life-time duration";
@ -1498,7 +1498,7 @@ enum_specifier:
my @enumerator_list = @{$item{enumerator_list}}; my @enumerator_list = @{$item{enumerator_list}};
if(@enumerator_list == 1) { if (@enumerator_list == 1) {
$return .= " comprising $enumerator_list[0]"; $return .= " comprising $enumerator_list[0]";
} else { } else {
my $last = pop @enumerator_list; my $last = pop @enumerator_list;
@ -1580,21 +1580,21 @@ constant:
{ {
my $constant = $item[1]; my $constant = $item[1];
if($constant eq q('\n')) { if ($constant eq q('\n')) {
$return = 'a newline'; $return = 'a newline';
} elsif($constant eq q('\f')) { } elsif ($constant eq q('\f')) {
$return = 'a form-feed character'; $return = 'a form-feed character';
} elsif($constant eq q('\t')) { } elsif ($constant eq q('\t')) {
$return = 'a tab'; $return = 'a tab';
} elsif($constant eq q('\v')) { } elsif ($constant eq q('\v')) {
$return = 'a vertical tab'; $return = 'a vertical tab';
} elsif($constant eq q('\b')) { } elsif ($constant eq q('\b')) {
$return = 'an alert character'; $return = 'an alert character';
} elsif($constant eq q('\r')) { } elsif ($constant eq q('\r')) {
$return = 'a carriage-return'; $return = 'a carriage-return';
} elsif($constant eq q('\b')) { } elsif ($constant eq q('\b')) {
$return = 'a backspace character'; $return = 'a backspace character';
} elsif($constant eq q('\'')) { } elsif ($constant eq q('\'')) {
$return = 'a single-quote'; $return = 'a single-quote';
} else { } else {
$return = $constant; $return = $constant;