[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  ROM
. -> [Folder]  Running the server
. . -> [Subject]  Parse error on colour

Parse error on colour

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Jaystar86   (4 posts)  [Biography] bio
Date Fri 12 Sep 2003 05:48 AM (UTC)
Message
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)
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #1 on Fri 12 Sep 2003 11:29 PM (UTC)

Amended on Sat 13 Sep 2003 03:15 AM (UTC) by Meerclar

Message
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))

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #2 on Sat 13 Sep 2003 12:48 AM (UTC)
Message
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.)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] bio
Date Reply #3 on Sat 13 Sep 2003 03:06 AM (UTC)

Amended on Sat 13 Sep 2003 03:11 AM (UTC) by Meerclar

Message
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.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Sat 13 Sep 2003 04:18 AM (UTC)

Amended on Sat 13 Sep 2003 04:21 AM (UTC) by David Haley

Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #5 on Sat 13 Sep 2003 04:33 AM (UTC)
Message
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...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Jaystar86   (4 posts)  [Biography] bio
Date Reply #6 on Sun 14 Sep 2003 07:23 AM (UTC)
Message
Thanks guys, once i got over the initial confusion i was fine. It worked which is good...
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


15,246 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]