Parse error

Anything that doesn't fit elsewhere.
Post Reply
ferron

Parse error

Post by ferron »

Hello everybody,

I'm getting a "parse error" with the following code and I don't understand why... I'm just confused about it...

Thanks for your help!


func didfire()
{
apcsum = 0

for i=0, nFascs-1
{//loops over all fascicles

for j=0, fasc.nAxons-1
{//loops over all axons in fascicle

for k=0, fasc.mye_axons[j].axonnodes-1
{//loop over all node in axon

fasc.mye_axons[j].node[k]
apcsum = apcsum + apc[k].n
}

if (apcsum >= ((fasc.mye_axons[j].axonnodes+1)/2))
{return 1}
else
{return 0}
}
}
}

Binary_output = didfire()
access fasc[0].mye_axons[0].node[0]
finitialize(v_init)
fcurrent()
ted
Site Admin
Posts: 6394
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

debugging code

Post by ted »

Following the "teach a man to fish . . . " principle, here's a suggested strategy for
debugging your code.

General comments about parse errors:
The error message generally points to the cause. The erroneous line is printed
with a carat ^ that points at the location where the parser failed.
Common causes include invalid syntax, use of undefined names,
and using a variable of the wrong type.

That alone may be enough to help you find the problem.

Human nature being what it is, it is quite possible to stare at erroneous code all
day long and never see the mistake. When you find this happening, it's time to
resort to iterative testing. In pseudocode:

Code: Select all

Comment out almost everything except for a tiny bit of code 
that should produce a visible (printed or graphical) result.
Verify that your tiny bit works and produces the expected result.
REPEAT
  uncomment a small part of that which was commented out
  REPEAT
    run a test (for parse errors, this just means have hoc parse it again)
    if the uncommented code doesn't work (parse) as expected, revise it
  UNTIL the revised stuff works properly
UNTIL EVERYTHING WORKS
As a first step in this iterative exercise, it is often helpful to comment out the guts
of procs or funcs, and insert a stub statement that prints a message or returns
a fixed value.
ferron

Post by ferron »

Hello there,

I did find the "parese error". It was coming from the fact that the "else" statement wasn't on the same line as the clocing brace of the "if" statement.

I found this by looking back at the documentation on the "if" statement.

Thanks!
ted
Site Admin
Posts: 6394
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Manual? We don't read no stinking manuals!

Post by ted »

ferron wrote:I found this by looking back at the documentation on the "if" statement.
Yeah, RTM also works. Forgot about that.
Post Reply