mirror of
https://github.com/pragma-/pbot.git
synced 2025-06-03 05:17:48 +02:00
CGrammar: Improve casting, for/do loops and assignment from function result
This commit is contained in:
parent
df1fa14b2a
commit
e29bd99b42
@ -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 => 632,
|
BUILD_REVISION => 633,
|
||||||
BUILD_DATE => "2014-06-11",
|
BUILD_DATE => "2014-06-12",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -289,6 +289,7 @@ iteration_statement:
|
|||||||
$return .= $item{statement} ;
|
$return .= $item{statement} ;
|
||||||
|
|
||||||
if ($increment) {
|
if ($increment) {
|
||||||
|
$return =~ s/End for loop.$//;
|
||||||
$return .= "After each iteration, ^L$increment.\n";
|
$return .= "After each iteration, ^L$increment.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,7 +325,16 @@ for_increment:
|
|||||||
|
|
||||||
selection_statement:
|
selection_statement:
|
||||||
'if' <commit> '(' expression[context => 'if block'] ')' statement[context => 'if block']
|
'if' <commit> '(' expression[context => 'if block'] ')' statement[context => 'if block']
|
||||||
{ $return = "If $item{expression}, then ^L$item{statement}"; }
|
{
|
||||||
|
if($item{expression} =~ /^(\d+)$/) {
|
||||||
|
if($1 == 0) {
|
||||||
|
$item{expression} = "never";
|
||||||
|
} else {
|
||||||
|
$item{expression} = "always";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$return = "If $item{expression} then ^L$item{statement}";
|
||||||
|
}
|
||||||
('else' statement[context => 'else block']
|
('else' statement[context => 'else block']
|
||||||
{ $return = "Otherwise, ^L$item{statement}"; }
|
{ $return = "Otherwise, ^L$item{statement}"; }
|
||||||
)(?)
|
)(?)
|
||||||
@ -390,7 +400,9 @@ assignment_expression:
|
|||||||
my $assignment_operator = $item{assignment_operator};
|
my $assignment_operator = $item{assignment_operator};
|
||||||
|
|
||||||
if ($arg{context} eq 'statement' or $arg{context} eq 'for loop') {
|
if ($arg{context} eq 'statement' or $arg{context} eq 'for loop') {
|
||||||
$return .= "${$item{assignment_operator}}[0] $item{unary_expression}${$item{assignment_operator}}[1] $assignment_expression";
|
$return .= "${$item{assignment_operator}}[0] $item{unary_expression} ";
|
||||||
|
$return .= "${$item{assignment_operator}}[1] " if $assignment_expression !~ /the result of/;
|
||||||
|
$return .= $assignment_expression;
|
||||||
} else {
|
} else {
|
||||||
$return = "$item{unary_expression}, $assignment_operator $assignment_expression";
|
$return = "$item{unary_expression}, $assignment_operator $assignment_expression";
|
||||||
}
|
}
|
||||||
@ -582,7 +594,7 @@ closure:
|
|||||||
|
|
||||||
cast_expression:
|
cast_expression:
|
||||||
'(' type_name ')' cast_expression[context => 'recast']
|
'(' type_name ')' cast_expression[context => 'recast']
|
||||||
{ $return = "a casting into the type \'$item{type_name}\' of $item{cast_expression}"; }
|
{ $return = "$item{cast_expression} type-casted as $item{type_name}"; }
|
||||||
| unary_expression[context => $arg{context}]
|
| unary_expression[context => $arg{context}]
|
||||||
{ $return = $item{unary_expression}; }
|
{ $return = $item{unary_expression}; }
|
||||||
#( ...closure )(?)
|
#( ...closure )(?)
|
||||||
@ -604,7 +616,6 @@ declaration_list:
|
|||||||
declaration:
|
declaration:
|
||||||
declaration_specifiers init_declarator_list(?) ';'
|
declaration_specifiers init_declarator_list(?) ';'
|
||||||
{
|
{
|
||||||
print STDERR "wtf\n"; print STDERR ::Dumper \%item;
|
|
||||||
# This whole thing needs to be re-written to parse declarations inside-out.
|
# This whole thing needs to be re-written to parse declarations inside-out.
|
||||||
my @init_list = defined $item{'init_declarator_list(?)'}->[0] ? @{$item{'init_declarator_list(?)'}->[0]} : ('');
|
my @init_list = defined $item{'init_declarator_list(?)'}->[0] ? @{$item{'init_declarator_list(?)'}->[0]} : ('');
|
||||||
my $init_declaration_list;
|
my $init_declaration_list;
|
||||||
@ -814,7 +825,7 @@ postfix_expression:
|
|||||||
push @basics, $basic;
|
push @basics, $basic;
|
||||||
$basic = $item{primary_expression};
|
$basic = $item{primary_expression};
|
||||||
|
|
||||||
if(not defined $arg{context}) {
|
if(not defined $arg{context} or $arg{context} eq 'assignment_expression') {
|
||||||
$return = "the result of ";
|
$return = "the result of ";
|
||||||
} else {
|
} else {
|
||||||
$return = "Perform ";
|
$return = "Perform ";
|
||||||
@ -1234,7 +1245,10 @@ type_name:
|
|||||||
|
|
||||||
specifier_qualifier_list:
|
specifier_qualifier_list:
|
||||||
type_specifier specifier_qualifier_list(?)
|
type_specifier specifier_qualifier_list(?)
|
||||||
{ $return = $item{type_specifier} . join('', @{$item{'specifier_qualifier_list(?)'}}); }
|
{
|
||||||
|
$return = $item{type_specifier};
|
||||||
|
$return .= ' ' . join('', @{$item{'specifier_qualifier_list(?)'}}) if @{$item{'specifier_qualifier_list(?)'}};
|
||||||
|
}
|
||||||
|
|
||||||
struct_declarator_list:
|
struct_declarator_list:
|
||||||
struct_declarator
|
struct_declarator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user