fb39ca4 / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

Indexed access to char array does not work #132

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run the interpreter ./picoc test.c

What is the expected output? What do you see instead?
The expected output should be:
4
But instead I get:        
if(a[i]=='A'||a[i]=='D'||a[i]=='O'||a[i]=='P'||a[i]=='Q'||a[i]=='R') cnt++;
                         ^
test.c:10: this int is not an array

What version of the product are you using? On what operating system?
URL: http://picoc.googlecode.com/svn/trunk
Repository Root: http://picoc.googlecode.com/svn
Repository UUID: 21eae674-98b7-11dd-bd71-f92a316d2d60
Revision: 569
Node Kind: directory
Schedule: normal
Last Changed Author: zik.saleeba
Last Changed Rev: 564
Last Changed Date: 2011-02-22 21:28:08 +0200 (Tue, 22 Feb 2011)

Please provide any additional information below.

Original issue reported on code.google.com by zahari.z...@gmail.com on 5 Mar 2011 at 1:06

Attachments:

GoogleCodeExporter commented 8 years ago
I have got more or less the same problem:

This is c source code:
...
char  status[3];
...
if (status[0] != 0 && status[0] != 3 && status[0] != 4)
{
    ...
}
...

output is: "this is not an array", generated in funtion: 
ExpressionInfixOperator ln 618 of PicoC Expression.c

If i change source in this form it seems to work correctly:
if ( (status[0] != 0) && (status[0] != 3) && (status[0] != 4) )
{
}

has anyone tried?

Original comment by daniele....@gmail.com on 16 Dec 2011 at 9:52

GoogleCodeExporter commented 8 years ago
Brackets ... if not sure always use them :)

Original comment by zahari.z...@gmail.com on 16 Dec 2011 at 2:32

GoogleCodeExporter commented 8 years ago
Sorry, have you tried using brackets in test.c file? For me it works...

Original comment by daniele....@gmail.com on 19 Dec 2011 at 10:01

GoogleCodeExporter commented 8 years ago
It's related to this optimization:

expression.c:1129:
/* if it's a && or || operator we may not need to evaluate the right hand side 
of the expression */

Original comment by broscuta...@gmail.com on 5 Mar 2013 at 8:34

GoogleCodeExporter commented 8 years ago
If you comment out this, it seems to work:

             /* if we've successfully ignored the RHS turn ignoring off */
            if (Precedence <= IgnorePrecedence)
                IgnorePrecedence = DEEP_PRECEDENCE;

I'm not sure what this does, and what side effects this change might have. The 
built-in tests run fine regardless of those two lines.

Original comment by broscuta...@gmail.com on 5 Mar 2013 at 9:50

GoogleCodeExporter commented 8 years ago
Nope, this fix is not good. Disabling the boolean optimization seems better.

Another test case:

struct point {
   double x;
   double y;
};

int isInBetween (struct point p1, struct point p2, struct point t) {
   int valid = FALSE;
   if ((t.x >= p1.x && t.x <= p2.x) || (t.x >= p2.x && t.x <= p1.x)) {
      if ((t.y >= p1.y && t.y <= p2.y) || (t.y >= p2.y && t.y <= p1.y)) {
         valid = TRUE;
      }
   }
   return valid;
}

from http://www.go-hero.net/jam/12/name/dahlukeh , Hall of Mirrors

Original comment by broscuta...@gmail.com on 6 Mar 2013 at 8:17

GoogleCodeExporter commented 8 years ago
There is some truth in the "fix" from #5. Here's a better version, that passed 
everything I've thrown at it so far.

https://bitbucket.org/a1ex/picoc-fork/commits/f4b78691c054b7b7b8d63e41dbbe6646d0
37fb77

I'd like you to review this one, because I still don't fully understand how 
IgnorePrecedence works.

Original comment by broscuta...@gmail.com on 16 Mar 2013 at 3:03