mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 02:49:49 +01:00
CGrammar: fix conditional statement, improve structures and do-while loop
This commit is contained in:
parent
6641bc3cf2
commit
ec1fd207a6
@ -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 => 620,
|
BUILD_REVISION => 621,
|
||||||
BUILD_DATE => "2014-06-08",
|
BUILD_DATE => "2014-06-08",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ compound_statement:
|
|||||||
$return .= "End block.\n" if not $arg{context};
|
$return .= "End block.\n" if not $arg{context};
|
||||||
|
|
||||||
if ($arg{context}) {
|
if ($arg{context}) {
|
||||||
$return .= "End $arg{context}.\n";
|
$return .= "End $arg{context}.\n" unless $arg{context} eq 'do loop';
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
}
|
}
|
||||||
@ -328,7 +328,7 @@ iteration_statement:
|
|||||||
$return .= $item{statement} . "\n";
|
$return .= $item{statement} . "\n";
|
||||||
}
|
}
|
||||||
| 'do' statement[context => 'do loop'] 'while' '(' expression ')' ';'
|
| 'do' statement[context => 'do loop'] 'while' '(' expression ')' ';'
|
||||||
{ $return = "Do the following:\n$item{statement}\nDo this as long as '$item{expression}' evaluates to a positive number.\n"; }
|
{ $return = "Do the following:^L $item{statement}\nDo this as long as $item{expression}.\n"; }
|
||||||
|
|
||||||
for_initialization:
|
for_initialization:
|
||||||
expression[context => 'statement']
|
expression[context => 'statement']
|
||||||
@ -416,13 +416,13 @@ assignment_expression:
|
|||||||
|
|
||||||
conditional_expression:
|
conditional_expression:
|
||||||
logical_OR_AND_expression[context => $arg{context}]
|
logical_OR_AND_expression[context => $arg{context}]
|
||||||
| logical_OR_AND_expression[context => $arg{context}]
|
|
||||||
'?' expression[context => 'conditional_expression1']
|
'?' expression[context => 'conditional_expression1']
|
||||||
':' conditional_expression[context => 'conditional_expression2']
|
':' conditional_expression[context => 'conditional_expression2']
|
||||||
{
|
{
|
||||||
$return = "the choice dependent on the value of $item{logical_OR_expression}" .
|
$return = "the value depending on if $item{logical_OR_AND_expression} is true" .
|
||||||
" comprising of $item{expression} or $item{conditional_expression}";
|
" then $item{expression} otherwise $item{conditional_expression}";
|
||||||
}
|
}
|
||||||
|
| logical_OR_AND_expression[context => $arg{context}]
|
||||||
|
|
||||||
assignment_operator:
|
assignment_operator:
|
||||||
'='
|
'='
|
||||||
@ -817,32 +817,21 @@ postfix_expression:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# struct dereferences:
|
# struct accesses:
|
||||||
( '.' identifier )(?)
|
( '.' identifier )(?)
|
||||||
{
|
{
|
||||||
# capitalize when necessary!
|
# capitalize when necessary!
|
||||||
my $identifier = join('',@{$item[-1]});
|
my $identifier = join('',@{$item[-1]});
|
||||||
if ($identifier) {
|
if ($identifier) {
|
||||||
if ($arg{context} eq 'statement') {
|
$return = "the member $identifier of structure $basic";
|
||||||
$return = 'S';
|
|
||||||
} else {
|
|
||||||
$return = 's';
|
|
||||||
}
|
|
||||||
$return .= "tructure $basic" . "'s member $identifier";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
( '->' identifier )(?)
|
( '->' identifier )(?)
|
||||||
{
|
{
|
||||||
# capitalize when necessary!
|
# capitalize when necessary!
|
||||||
my $identifier2 = join('',@{$item[-1]});
|
my $identifier = join('',@{$item[-1]});
|
||||||
if (length $identifier2) {
|
if ($identifier) {
|
||||||
if ($arg{context} eq 'statement') {
|
$return = "the member $identifier of the structure pointed to by $basic";
|
||||||
$return = 'The ';
|
|
||||||
} else {
|
|
||||||
$return = 'the ';
|
|
||||||
}
|
|
||||||
# todo: apply same approach one rank above....
|
|
||||||
$return .= "member $identifier2 of the structure pointed to by $basic";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
( '++' )(?)
|
( '++' )(?)
|
||||||
@ -892,11 +881,11 @@ argument_expression_list:
|
|||||||
my $last = '';
|
my $last = '';
|
||||||
if ($#arg_exp_list > 1) {
|
if ($#arg_exp_list > 1) {
|
||||||
$last = pop @arg_exp_list;
|
$last = pop @arg_exp_list;
|
||||||
$return = 's \'' . join('\', \'', @arg_exp_list) . '\', and \'' . $last . '\'';
|
$return = 's ' . join(', ', @arg_exp_list) . ", and $last";
|
||||||
} elsif ( $#arg_exp_list == 1 ) {
|
} elsif ( $#arg_exp_list == 1 ) {
|
||||||
$return = 's \'' . $arg_exp_list[0] . '\' and ' . "'$arg_exp_list[1]'";
|
$return = "s $arg_exp_list[0] and $arg_exp_list[1]";
|
||||||
} else {
|
} else {
|
||||||
$return = ' ' . "\'$arg_exp_list[0]\'";
|
$return = " $arg_exp_list[0]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1198,8 +1187,6 @@ 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} . join('', @{$item{'specifier_qualifier_list(?)'}}); }
|
||||||
| type_specifier
|
|
||||||
{ $return = $item{type_specifier}; }
|
|
||||||
|
|
||||||
struct_declarator_list:
|
struct_declarator_list:
|
||||||
struct_declarator
|
struct_declarator
|
||||||
|
Loading…
Reference in New Issue
Block a user