mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-23 19:22:40 +01:00
CGrammar: Improve and optimize conditional_expression rule; improve translation of parenthetical expressions
This commit is contained in:
parent
bf9586b6a8
commit
632a9582d5
@ -13,7 +13,7 @@ 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 => 639,
|
BUILD_REVISION => 640,
|
||||||
BUILD_DATE => "2014-06-14",
|
BUILD_DATE => "2014-06-14",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -419,14 +419,19 @@ assignment_expression:
|
|||||||
| conditional_expression[context => $arg{context}]
|
| conditional_expression[context => $arg{context}]
|
||||||
|
|
||||||
conditional_expression:
|
conditional_expression:
|
||||||
logical_OR_AND_expression[context => $arg{context}]
|
logical_OR_AND_expression[context => $arg{context}] conditional_ternary_expression
|
||||||
'?' expression[context => 'conditional_expression1']
|
|
||||||
':' conditional_expression[context => 'conditional_expression2']
|
|
||||||
{
|
{
|
||||||
$return = "the value depending on if $item{logical_OR_AND_expression} is true" .
|
if($item{conditional_ternary_expression}) {
|
||||||
" then $item{expression} otherwise $item{conditional_expression}";
|
$return = "depending on if $item{logical_OR_AND_expression} is true then $item{conditional_ternary_expression}";
|
||||||
}
|
} else {
|
||||||
| logical_OR_AND_expression[context => $arg{context}]
|
$return = $item{logical_OR_AND_expression};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
conditional_ternary_expression:
|
||||||
|
'?' expression ':' conditional_expression
|
||||||
|
{ $return = "$item{expression} otherwise $item{conditional_expression}"; }
|
||||||
|
| { "" } # nothing
|
||||||
|
|
||||||
assignment_operator:
|
assignment_operator:
|
||||||
'='
|
'='
|
||||||
@ -547,7 +552,7 @@ logical_OR_AND_expression:
|
|||||||
<leftop:
|
<leftop:
|
||||||
rel_add_mul_shift_expression[context => $arg{context}]
|
rel_add_mul_shift_expression[context => $arg{context}]
|
||||||
log_OR_AND_bit_or_and_eq
|
log_OR_AND_bit_or_and_eq
|
||||||
rel_add_mul_shift_expression[context => 'logical_OR_AND_expression'] >
|
rel_add_mul_shift_expression[context => 'logical_OR_AND_expression']>
|
||||||
{
|
{
|
||||||
if (defined $arg{context} and $arg{context} eq 'for_expression') { print STDERR "hmm2\n"; }
|
if (defined $arg{context} and $arg{context} eq 'for_expression') { print STDERR "hmm2\n"; }
|
||||||
my @ands = @{$item[1]};
|
my @ands = @{$item[1]};
|
||||||
@ -606,19 +611,8 @@ cast_expression:
|
|||||||
{ $return = "$item{cast_expression} type-casted as $item{type_name}"; }
|
{ $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 )(?)
|
|
||||||
# {
|
|
||||||
# if ($arg{context} eq 'statement' #&& !($return =~ /^Perform/)
|
|
||||||
# )
|
|
||||||
# {
|
|
||||||
# if (${$item[-1]}[0]) {
|
|
||||||
# $return .= ".\n";
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
#}
|
|
||||||
|
|
||||||
declaration_list:
|
declaration_list:
|
||||||
# <skip: '\s*'>
|
|
||||||
preproc[context => 'statement'](?) declaration(s)
|
preproc[context => 'statement'](?) declaration(s)
|
||||||
{ $return = join('', @{$item{'preproc(?)'}}) . join('', @{$item{'declaration(s)'}}); }
|
{ $return = join('', @{$item{'preproc(?)'}}) . join('', @{$item{'declaration(s)'}}); }
|
||||||
|
|
||||||
@ -1000,39 +994,28 @@ narrow_closure:
|
|||||||
primary_expression:
|
primary_expression:
|
||||||
'(' expression ')' (...narrow_closure)(?)
|
'(' expression ')' (...narrow_closure)(?)
|
||||||
{
|
{
|
||||||
|
print STDERR "wtf\n";
|
||||||
|
print STDERR "expression: [$item{expression}]; text: [$text]\n";
|
||||||
my $expression = $item{expression} ;
|
my $expression = $item{expression} ;
|
||||||
my $repeats = 1;
|
my $repeats = 1;
|
||||||
my $ending = 1;
|
|
||||||
|
|
||||||
if ($expression =~ /^the (\d+)-layered parenthetical expression/) {
|
if ($expression =~ /^the expression (\(+)/) {
|
||||||
$repeats = $1 + 1;
|
$repeats = (length $1) + 1;
|
||||||
$expression =~ s/^the \d+-layered parenthetical expression //;
|
print STDERR "Got repeats: $repeats from matching [$1]\n";
|
||||||
} elsif ($expression =~ /^the parenthetical expression/) {
|
$expression =~ s/^the expression \(+//;
|
||||||
$repeats = 2;
|
|
||||||
$expression =~ s/^the parenthetical expression //;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($expression =~ / now$/) {
|
|
||||||
$ending++;
|
|
||||||
$expression =~ s/ now$//;
|
|
||||||
$expression .= " (now drop $ending layers of context)" ;
|
|
||||||
} elsif ($expression =~ /now drop (\d+) layers of context\)$/ ) {
|
|
||||||
$ending = $1 + 1;
|
|
||||||
$expression =~ s/\d+ layers of context\)$/$ending layers of context \)/;
|
|
||||||
} else { $expression .= ' now'; }
|
|
||||||
if ($repeats > 1) {
|
|
||||||
$return = "the $repeats-layered parenthetical expression $expression";
|
|
||||||
} else {
|
|
||||||
$return = "the parenthetical expression $expression";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (@{$item[-1]}) {
|
|
||||||
$return =~ s/ now$//;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print STDERR "repeats: $repeats\n";
|
||||||
|
|
||||||
|
$expression .= ')';
|
||||||
|
$return = "the expression ";
|
||||||
|
$return .= '(' x $repeats;
|
||||||
|
$return .= $expression;
|
||||||
|
}
|
||||||
| constant
|
| constant
|
||||||
| string
|
| string
|
||||||
| identifier
|
| identifier
|
||||||
|
| { "" } # nothing
|
||||||
|
|
||||||
declarator:
|
declarator:
|
||||||
direct_declarator
|
direct_declarator
|
||||||
|
Loading…
Reference in New Issue
Block a user