CGrammar: Fix declarations without identifier

This commit is contained in:
Pragmatic Software 2014-07-04 23:41:54 +00:00
parent 9c5b307bef
commit 4583d85b50
3 changed files with 10 additions and 13 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 704,
BUILD_REVISION => 705,
BUILD_DATE => "2014-07-04",
};

View File

@ -389,7 +389,7 @@ close $fh;
$output = `./c2eng.pl code2eng.c` if not defined $output;
if(not $has_function and not $has_main) {
$output =~ s/Let .main. be a function taking no arguments and returning int.\s*When called, the function will.\s*(return 0.)?//i;
$output =~ s/Let .main. be a function taking no arguments and returning int.\s*When called, the function will.\s*(do nothing.)?//i;
$output =~ s/\s*Return 0.\s*End of function .main..\s*//;
$output =~ s/\s*Finally, return 0.$//;
$output =~ s/\s*and then return 0.$/./;
@ -397,7 +397,7 @@ if(not $has_function and not $has_main) {
$output =~ s/^\s*(.)/\U$1/;
$output =~ s/\.\s+(\S)/. \U$1/g;
} elsif($has_function and not $has_main) {
$output =~ s/\s*Let `main` be a function taking no arguments and returning int.\s*When called, the function will return 0.//;
$output =~ s/\s*Let `main` be a function taking no arguments and returning int.\s*When called, the function will do nothing.//;
$output =~ s/\s*Finally, return 0.$//;
$output =~ s/\s*and then return 0.$/./;
}

View File

@ -66,9 +66,9 @@ undefinition:
inclusion:
'include' '<' filename '>' <skip: '[ \t]*'> "\n"
{ $return = "\nInclude system file $item{filename}.\n"; }
{ $return = "\nInclude the header $item{filename}.\n"; }
| 'include' '"' filename '"' <skip: '[ \t]*'> "\n"
{ $return = "\nInclude user file $item{filename}.\n"; }
{ $return = "\nInclude the source file $item{filename}.\n"; }
| 'include' token
{ $return = "\nImport code noted by the token $item{token}.\n"; }
@ -669,11 +669,7 @@ declaration:
my ($first_qualifier, $first_initializer);
my $first_identifier = shift @args;
if (not length $first_identifier) {
$first_identifier = 'there';
}
my @identifiers = ($first_identifier);
my @identifiers = ($first_identifier) unless not length $first_identifier;
my $next_arg = shift @args;
if ($next_arg =~ m/initialized/) {
@ -739,7 +735,7 @@ declaration:
}
}
$return .= ' as ';
$return .= ' as ' unless not @identifiers;
if ($first_qualifier) {
if ($first_qualifier =~ /bit\-field/) {
@ -753,7 +749,8 @@ declaration:
$first_qualifier =~ s/pointer/pointers/;
$first_qualifier =~ s/an array/arrays/;
}
$return .= "$first_qualifier $item{declaration_specifiers}";
$return .= "$first_qualifier";
$return .= $item{declaration_specifiers} if $item{declaration_specifiers};
} else {
if (@identifiers == 1 and $item{declaration_specifiers} !~ /^(a|an)\s+/) {
$return .= $item{declaration_specifiers} =~ m/^[aeiouy]/ ? 'an ' : 'a ';
@ -777,7 +774,7 @@ declaration:
$return .= ' as another name for ';
push @typedefs, @identifiers;
} else {
$return .= ' as ';
$return .= ' as ' unless not @identifiers;
}
if ($first_qualifier) {