3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

CGrammar: Fix function call results and improve character constants

This commit is contained in:
Pragmatic Software 2014-06-10 08:50:19 +00:00
parent c4fd8a964f
commit 929d9368fe
2 changed files with 48 additions and 51 deletions

View File

@ -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 => 624, BUILD_REVISION => 625,
BUILD_DATE => "2014-06-09", BUILD_DATE => "2014-06-10",
}; };
1; 1;

View File

@ -288,7 +288,7 @@ statement:
iteration_statement: iteration_statement:
'for' '(' <commit> for_initialization(?) ';' for_expression(?) ';' for_increment(?) ')' 'for' '(' <commit> for_initialization(?) ';' for_expression(?) ';' for_increment(?) ')'
statement[context => 'statement'] statement[context => 'for loop']
{ {
my $initialization = join('', @{$item{'for_initialization(?)'}}); my $initialization = join('', @{$item{'for_initialization(?)'}});
my $item_expression = join('',@{$item{'for_expression(?)'}}); my $item_expression = join('',@{$item{'for_expression(?)'}});
@ -423,7 +423,6 @@ conditional_expression:
assignment_operator: assignment_operator:
'=' '='
{ {
print STDERR "arg1: [$arg{context}]\n";
if ($arg{context} eq 'statement') { if ($arg{context} eq 'statement') {
$return = ['Assign to', ' the value' ]; $return = ['Assign to', ' the value' ];
} elsif ($arg{context} eq 'for loop') { } elsif ($arg{context} eq 'for loop') {
@ -763,32 +762,14 @@ unary_expression:
{ $return = "the size of the datatype $item{type_name}"; } { $return = "the size of the datatype $item{type_name}"; }
postfix_expression: postfix_expression:
primary_expression[context => $arg{context}] primary_expression[context => $arg{context}] '(' argument_expression_list(?) ')' # function call
{ {
# must be global. use stack to prevent disasters.
# Todo: this is just a Bad Idea, TM. $return needs to be turned to an hash with the
# arguments doing the right thing and then the last action assembles the sucker.
push @basics, $basic; push @basics, $basic;
$basic = $item{primary_expression}; $basic = $item{primary_expression};
$return = $item{primary_expression};
1; if(not defined $arg{context}) {
} $return = "the result of ";
( # function call
'(' argument_expression_list(?) ')'
{
my $arg_exp_list = join('',@{$item{'argument_expression_list(?)'}});
if ($arg_exp_list) {
$return = " with argument$arg_exp_list";
} else { } else {
$return = "without any arguments";
}
}
)(?)
{
my $args = join('',@{$item[-1]});
if ($args) {
if ($arg{context} eq 'statement') {
$return = "Perform "; $return = "Perform ";
} }
@ -808,16 +789,21 @@ postfix_expression:
} }
} }
if ($args =~ /^ with arg/) { my $arg_exp_list = join('',@{$item{'argument_expression_list(?)'}});
$return .= $args; if ($arg_exp_list) {
} $return .= " with argument$arg_exp_list";
# if ($arg{context} eq 'statement') {
# $return .= ".\n";
# }
} }
1; 1;
} }
| primary_expression[context => $arg{context}]
{
# must be global. use stack to prevent disasters.
# Todo: this is just a Bad Idea, TM. $return needs to be turned to an hash with the
# arguments doing the right thing and then the last action assembles the sucker.
push @basics, $basic;
$basic = $item{primary_expression};
$return = $item{primary_expression};
}
# array reference and plain expression # array reference and plain expression
( '[' expression[context => 'array_address'] ']' ( '[' expression[context => 'array_address'] ']'
@ -1320,6 +1306,17 @@ constant:
$return =~ s/[Ll]$/(long)/; $return =~ s/[Ll]$/(long)/;
} }
| m{'.*?[^\']'} # character constant FIXME: doesn't handle escaped quotes | m{'.*?[^\']'} # character constant FIXME: doesn't handle escaped quotes
{
my $constant = $item[1];
if($constant eq q/'\n'/) {
$return = 'a newline';
} elsif($constant eq q/'\t'/) {
$return = 'a tab';
} else {
$return = $constant;
}
}
# | enumeration_constant # | enumeration_constant
# needs more. # needs more.