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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  ROM
. -> [Folder]  Running the server
. . -> [Subject]  Parse error on colour
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Parse error on colour

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Jaystar86   (4 posts)  [Biography] bio
Date Fri 12 Sep 2003 05:48 AM (UTC)  quote  ]
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  (606 posts)  [Biography] bio
Date Reply #1 on Fri 12 Sep 2003 11:29 PM (UTC)  quote  ]

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   Moderator
Date Reply #2 on Sat 13 Sep 2003 12:48 AM (UTC)  quote  ]
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  (606 posts)  [Biography] bio
Date Reply #3 on Sat 13 Sep 2003 03:06 AM (UTC)  quote  ]

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   Moderator
Date Reply #4 on Sat 13 Sep 2003 04:18 AM (UTC)  quote  ]

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   Moderator
Date Reply #5 on Sat 13 Sep 2003 04:33 AM (UTC)  quote  ]
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)  quote  ]
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.


2,526 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [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.

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]