mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-24 11:42:35 +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
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 645,
|
BUILD_REVISION => 646,
|
||||||
BUILD_DATE => "2014-06-15",
|
BUILD_DATE => "2014-06-16",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -386,7 +386,7 @@ open $fh, '>', 'code2eng.c' or die "Could not write code: $!";
|
|||||||
print $fh $code;
|
print $fh $code;
|
||||||
close $fh;
|
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) {
|
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;
|
$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+/ /;
|
$output =~ s/\s+/ /;
|
||||||
if(not $output) {
|
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";
|
print "[Work-in-progress; there will be issues!] $output\n";
|
||||||
|
|
||||||
sub execute {
|
sub execute {
|
||||||
|
@ -861,6 +861,7 @@ postfix_productions:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($postfix) {
|
if($postfix) {
|
||||||
|
$return =~ s/^(Call|Insert)/the result of/;
|
||||||
$return = "$postfix $return";
|
$return = "$postfix $return";
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
@ -1246,12 +1247,14 @@ struct_or_union_specifier:
|
|||||||
my $identifier = join('',@{$item{'identifier(?)'}});
|
my $identifier = join('',@{$item{'identifier(?)'}});
|
||||||
$return = join('',@{$item{'comment(?)'}}) . $item{struct_or_union};
|
$return = join('',@{$item{'comment(?)'}}) . $item{struct_or_union};
|
||||||
if ($identifier) { $return .= " tagged $identifier"; }
|
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
|
| struct_or_union identifier
|
||||||
{
|
{
|
||||||
$item{struct_or_union} =~ s/^(a|an)/the/;
|
$item{struct_or_union} =~ s/^(a|an)//;
|
||||||
$return = "$item{struct_or_union} $item{identifier}";
|
$return = $item{identifier} =~ m/^`[aeiouy]/ ? 'an' : 'a';
|
||||||
|
$return .= " $item{identifier} $item{struct_or_union}";
|
||||||
}
|
}
|
||||||
|
|
||||||
struct_declaration_list:
|
struct_declaration_list:
|
||||||
@ -1372,29 +1375,33 @@ comment_cxx:
|
|||||||
}
|
}
|
||||||
|
|
||||||
constant:
|
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]";
|
$return = "the floating point number $item[1]";
|
||||||
|
} elsif ($item[1] =~ s/l$//i) {
|
||||||
|
$return = "long double $item[1]";
|
||||||
} else {
|
} else {
|
||||||
$return = $item[1];
|
$return = $item[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| /0x[0-9a-fA-F]+/ ('L')(?)
|
| /0x[0-9a-f]+[lu]{0,2}/i
|
||||||
{
|
{
|
||||||
if ($item[-1]) {
|
$return .= 'unsigned ' if $item[1] =~ s/[Uu]//;
|
||||||
$return = 'the long ' ."hexadecimal number $item[1]";
|
$return .= 'long ' if $item[1] =~ s/[Ll]//;
|
||||||
} else {
|
$return = "the $return" . "hexadecimal number $item[1]";
|
||||||
$return = 'the ' . "hexadecimal number $item[1]";
|
|
||||||
}
|
}
|
||||||
|
| /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\d+/
|
|/-?[0-9]+[lu]{0,2}/i # integer constant
|
||||||
{ $return = "the octal number $item[1]"; }
|
|
||||||
|/-?[0-9]+[lu]?/i # integer constant
|
|
||||||
{
|
{
|
||||||
$return = $item[-1];
|
$return = $item[-1];
|
||||||
$return =~ s/[Uu]$/(unsigned)/;
|
$return = "long $return" if $return =~ s/[Ll]//;
|
||||||
$return =~ s/[Ll]$/(long)/;
|
$return = "unsigned $return" if $return =~ s/[Uu]//;
|
||||||
}
|
}
|
||||||
| /(?:\'((?:\\\'|(?!\').)*)\')/ # character constant
|
| /(?:\'((?:\\\'|(?!\').)*)\')/ # character constant
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user