Parse error on colour

Posted by Jaystar86 on Fri 12 Sep 2003 05:48 AM — 7 posts, 23,865 views.

#0
Here's the error:
gcc -c -Wall -O -g -DNOCRYPT -DO
act_wiz.c: In function `obj_chec
act_wiz.c:2288: parse error befo
make: *** [act_wiz.o] Error 1

Here's the code:
bool obj_check (CHAR_DATA *ch, OBJ_DATA *obj)
{
if (IS_TRUSTED(ch,(MAX_LEVEL-1))
|| (IS_TRUSTED(ch,IMMORTAL) && obj->level <= 20 && obj->cost <= 1000)
|| (IS_TRUSTED(ch,(DEITY) && obj->level <= 10 && obj->cost <= 500)
|| (IS_TRUSTED(ch,ANGEL) && obj->level <= 5 && obj->cost <= 250)
|| (IS_TRUSTED(ch,AVATAR) && obj->level == 0 && obj->cost <= 100))
return TRUE;
else
return FALSE;

Any ideas? (ROM24b6, compiling with cygwin)
USA #1
You never closed your brackets if thats the actual section of code thats causing the error. You also don't have the parentheses setup for a compound check.

if (IS_TRUSTED(ch,(MAX_LEVEL-1))
|| (IS_TRUSTED(ch,IMMORTAL) && obj->level <= 20 && obj->cost <= 1000)
|| (IS_TRUSTED(ch,(DEITY) && obj->level <= 10 && obj->cost <= 500)
|| (IS_TRUSTED(ch,ANGEL) && obj->level <= 5 && obj->cost <= 250)
|| (IS_TRUSTED(ch,AVATAR) && obj->level == 0 && obj->cost <= 100))

should be

if (
   ^opens compound check
(IS_TRUSTED(ch,(MAX_LEVEL-1)))
^opens trust
           ^opens char info
               ^opens level check
                           ^closes level
                            ^closes char info
                             ^closes trust
|| (IS_TRUSTED(ch,IMMORTAL) && obj->level <= 20 && obj->cost <= 1000)
|| (IS_TRUSTED(ch,(DEITY) && obj->level <= 10 && obj->cost <= 500)
|| (IS_TRUSTED(ch,ANGEL) && obj->level <= 5 && obj->cost <= 250)
|| (IS_TRUSTED(ch,AVATAR) && obj->level == 0 && obj->cost <= 100))
Amended on Sat 13 Sep 2003 03:15 AM by Meerclar
USA #2
Actually adding those parentheses won't change anything at all due to the way the or operator works.

A || B || C
==
(A || B) || C

etc. It basically works the same way as the plus operator. (e.g. a + b + c == (a + b) + c) Other operators however do care about parentheses... the minus operator for example. A - B is obviously not the same as B - A ... and A - B + C is not the same as A - (B + C).
But if you only use or operators in your main expression, everything is fine.

E.g. A || B && C is exactly the same as A || (B && C) and is exactly the same as (A) || (B && C) because the logical and has precedence over the logical or.

However, generally, people use parentheses to indicate exactly what they meant to "say", even if you don't need them in some cases. In fact excessive "parenthesizing" can make things very complicated to read because you have to sort out the parenthesis matching, whereas (for those who have the knowledge) it's quite easy to sort it out by looking at the operators used.


Jaystar, your error message got cut off. Could you post the full text of the error, and also mark in your code which line is the one it reports? (by making it bold for instance.)
USA #3
Actually, the original parentheses never closed the first check before it moved to the second, thus the correction. Count the parentheses on each line, first line opens 3 but only closes 2 in the original code - leaving the parenthetes around the actual check open to run into the next argument and cause a parse error. Above is edited to demonstrate my point clearly.
Amended on Sat 13 Sep 2003 03:11 AM by Meerclar
USA #4
Actually, my point was that the original statement IS correct, and doesn't even open the compound check because it doesn't need to (because of the way or checks work.)

Count again... as you can see each line of code opens and closes all the parentheses it needs to remain a proper term in the if-check expression. I'm just saying that the parentheses you're adding around the first IS_TRUSTED, while correct, are unnecessary and are not correcting a parse error.


if (
(term1)     IS_TRUSTED(ch,(MAX_LEVEL-1))
(term2)     || (IS_TRUSTED(ch,IMMORTAL) && obj->level <= 20 && obj->cost <= 1000)
(term3)     || (IS_TRUSTED(ch,(DEITY) && obj->level <= 10 && obj->cost <= 500)
(term4)     || (IS_TRUSTED(ch,ANGEL) && obj->level <= 5 && obj->cost <= 250)
(term5)     || (IS_TRUSTED(ch,AVATAR) && obj->level == 0 && obj->cost <= 100)
   )
{
    return TRUE;
}
else
{
    return FALSE;
}


Therefore I strongly suspect that the parse error is elsewhere, which is why I asked for the complete error text and an indication of which line is the offending line.


Edited to add the following:
What you're doing is just surrounding the first term in extra parentheses. However it's all equivalent:

a <=> (a) <=> ((a)) <=> (((a))) <=> etc.

The first term remains unchanged, just has an extra set of parentheses around it which affect in no way its truth value.
Amended on Sat 13 Sep 2003 04:21 AM by David Haley
USA #5
I believe I spotted the error.

Look at the line:

|| (IS_TRUSTED(ch,(DEITY) && obj->level <= 10 && obj->cost <= 500)


This should be:

|| (IS_TRUSTED(ch, DEITY) && obj->level <= 10 && obj->cost <= 500)


There was a parenthesis before DEITY that didn't want to be there. That's your parse error...
#6
Thanks guys, once i got over the initial confusion i was fine. It worked which is good...