mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 19:22:40 +01:00
CGrammar: Improve structures and constant literals
This commit is contained in:
parent
c205d348e7
commit
b0ce2d422e
@ -13,8 +13,8 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 645,
|
||||
BUILD_DATE => "2014-06-15",
|
||||
BUILD_REVISION => 646,
|
||||
BUILD_DATE => "2014-06-16",
|
||||
};
|
||||
|
||||
1;
|
||||
|
@ -386,7 +386,7 @@ open $fh, '>', 'code2eng.c' or die "Could not write code: $!";
|
||||
print $fh $code;
|
||||
close $fh;
|
||||
|
||||
$output = `./c2eng.pl code2eng.c` if not defined $output;
|
||||
$output = `./c2eng.pl -P code2eng.c` if not defined $output;
|
||||
|
||||
if(not $has_function and not $has_main) {
|
||||
$output =~ s/Let .main. be a function taking no parameters and returning int.\s*To perform the function.\s*(return 0.)?//i;
|
||||
@ -401,9 +401,13 @@ if(not $has_function and not $has_main) {
|
||||
|
||||
$output =~ s/\s+/ /;
|
||||
if(not $output) {
|
||||
$output = "Does not compute. I only know about C89 and valid code.\n";
|
||||
$output = "Does not compute; I only know about C89 and valid code -- though I am still under construction.\n";
|
||||
}
|
||||
|
||||
# beautification
|
||||
$output =~ s/the value the expression/the value of the expression/g;
|
||||
$output =~ s/the value the address/the address/g;
|
||||
|
||||
print "[Work-in-progress; there will be issues!] $output\n";
|
||||
|
||||
sub execute {
|
||||
|
@ -861,6 +861,7 @@ postfix_productions:
|
||||
}
|
||||
|
||||
if($postfix) {
|
||||
$return =~ s/^(Call|Insert)/the result of/;
|
||||
$return = "$postfix $return";
|
||||
}
|
||||
1;
|
||||
@ -1246,12 +1247,14 @@ struct_or_union_specifier:
|
||||
my $identifier = join('',@{$item{'identifier(?)'}});
|
||||
$return = join('',@{$item{'comment(?)'}}) . $item{struct_or_union};
|
||||
if ($identifier) { $return .= " tagged $identifier"; }
|
||||
$return .= " with members $item{struct_declaration_list}";
|
||||
my $plural = $item{struct_declaration_list} =~ / and / ? 's' : '';
|
||||
$return .= " with member$plural $item{struct_declaration_list}";
|
||||
}
|
||||
| struct_or_union identifier
|
||||
{
|
||||
$item{struct_or_union} =~ s/^(a|an)/the/;
|
||||
$return = "$item{struct_or_union} $item{identifier}";
|
||||
$item{struct_or_union} =~ s/^(a|an)//;
|
||||
$return = $item{identifier} =~ m/^`[aeiouy]/ ? 'an' : 'a';
|
||||
$return .= " $item{identifier} $item{struct_or_union}";
|
||||
}
|
||||
|
||||
struct_declaration_list:
|
||||
@ -1372,29 +1375,33 @@ comment_cxx:
|
||||
}
|
||||
|
||||
constant:
|
||||
/-?[0-9]*\.[0-9]+f?/
|
||||
/-?[0-9]*\.[0-9]*[lf]{0,2}/i
|
||||
{
|
||||
if ($item[1] =~ /\D/) {
|
||||
if ($item[1] =~ s/f$//i) {
|
||||
$return = "the floating point number $item[1]";
|
||||
} else {
|
||||
} elsif ($item[1] =~ s/l$//i) {
|
||||
$return = "long double $item[1]";
|
||||
} else {
|
||||
$return = $item[1];
|
||||
}
|
||||
}
|
||||
| /0x[0-9a-fA-F]+/ ('L')(?)
|
||||
| /0x[0-9a-f]+[lu]{0,2}/i
|
||||
{
|
||||
if ($item[-1]) {
|
||||
$return = 'the long ' ."hexadecimal number $item[1]";
|
||||
} else {
|
||||
$return = 'the ' . "hexadecimal number $item[1]";
|
||||
}
|
||||
$return .= 'unsigned ' if $item[1] =~ s/[Uu]//;
|
||||
$return .= 'long ' if $item[1] =~ s/[Ll]//;
|
||||
$return = "the $return" . "hexadecimal number $item[1]";
|
||||
}
|
||||
| /0\d+/
|
||||
{ $return = "the octal number $item[1]"; }
|
||||
|/-?[0-9]+[lu]?/i # integer constant
|
||||
| /0\d+[lu]{0,2}/i
|
||||
{
|
||||
$return .= 'unsigned ' if $item[1] =~ s/[Uu]//;
|
||||
$return .= 'long ' if $item[1] =~ s/[Ll]//;
|
||||
$return = "the $return" . "octal number $item[1]";
|
||||
}
|
||||
|/-?[0-9]+[lu]{0,2}/i # integer constant
|
||||
{
|
||||
$return = $item[-1];
|
||||
$return =~ s/[Uu]$/(unsigned)/;
|
||||
$return =~ s/[Ll]$/(long)/;
|
||||
$return = "long $return" if $return =~ s/[Ll]//;
|
||||
$return = "unsigned $return" if $return =~ s/[Uu]//;
|
||||
}
|
||||
| /(?:\'((?:\\\'|(?!\').)*)\')/ # character constant
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user