From 4583d85b508f568d756d7b1258c9d6e6c950778f Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 4 Jul 2014 23:41:54 +0000 Subject: [PATCH] CGrammar: Fix declarations without identifier --- PBot/VERSION.pm | 2 +- modules/c2english.pl | 4 ++-- modules/c2english/CGrammar.pm | 17 +++++++---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 4047beae..906c316d 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -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", }; diff --git a/modules/c2english.pl b/modules/c2english.pl index 9c8efdcd..7d24519e 100755 --- a/modules/c2english.pl +++ b/modules/c2english.pl @@ -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.$/./; } diff --git a/modules/c2english/CGrammar.pm b/modules/c2english/CGrammar.pm index 7c189e8f..03e0e5fa 100644 --- a/modules/c2english/CGrammar.pm +++ b/modules/c2english/CGrammar.pm @@ -66,9 +66,9 @@ undefinition: inclusion: 'include' '<' filename '>' "\n" - { $return = "\nInclude system file $item{filename}.\n"; } + { $return = "\nInclude the header $item{filename}.\n"; } | 'include' '"' filename '"' "\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) {