Hallo,
recent days, rudi form german Forum (
http://www.wirklemms.de/chdk/forum/viewtopic.php?t=1437) has created a patch, which works fine.
I have wrote an entry (
http://chdk.kernreaktor.org/mantis/view.php?id=317) in the Bugtracker, but I can't upload anything.
Please update trunk.
Bug description:
It is a Bug in extended (nested) multiline IF-THEN-statement and ELSE-statement. The singleline IF-THEN-ELSE-statement is not affected.
If the interpreter have to skip script-lines between THEN and ELSE or ESLE and ENDIF, the following points are not considered:
1. the next TOKEN after THEN/ELSE don't process, it means: If a child multiline-IF-Statement direct after THEN/ELSE, the parent IF were closed by childs ENDIF
2. singleline-IF-Statements inside a IF are not identified, only multiline-IF-Statements
current Implementation
- fault processed multiline IF-THEN-ELSE-ENDIF statements for The next statement after THEN or ELSE
- fault processed multiline IF-THEN-[ELSE]-ENDIF statements for singleline IF-statements
- deficient handling for parse errors
- no handling for stackoverflow errors
proposed Implementation
- using singleline IF-statements in multiline IF-statements are possible
- handling of all skipped script-lines are correct
- better handle for parse errors
- add handle stackoverflow errors, stacksize is unchanged
corect IF-syntax:
- singleline statement IF-THEN-ELSE; no ENDIF expected
- multiline statement IF-THEN-[ELSE]-ENDIF; IF-THEN, ELSE, and ENDIF needs an own line
Important note for both implementations:
Don't use GOTO-statement in multiline IF-statements, which jump inside/outside of IF-ENDIF-block (get a stackoverflow).
examples for tests:
@title IF-bug test1
rem the valid output in this simple test is only "n<>1"
rem but in current implementation output: "n<>0", "n=1", "n<>1"
n=2
if n=1 then
if n=0 then
print "n=0"
else
print "n<>0"
endif
print "n=1"
else
print "n<>1"
endif
print "test1 finished"
print "press a key to end"
wait_click
end
-----------------------------------------------------
@title IF-bug test2
rem singleline IF in multiline IF-statement
rem in current implementation
rem the ELSE-ENDIF-section in multiline IF isn't found
rem and the script ends in the first run from "tryif"-section
rem without any error
a=0
b=0
gosub "tryif"
a=0
b=1
gosub "tryif"
a=1
b=0
gosub "tryif"
a=1
b=1
gosub "tryif"
print "test2 finished"
print "press a key to end"
wait_click
end
:tryif
print "tryif: a=", a ,"b=", b
if a=0 then
print "[IF]"
if b=0 then print "a=0; b=0" else print "a=0; b=1"
else
print "[ELSE]"
if b=0 then print "a=1; b=0" else print "a=1; b=1"
endif
print "gosub end"
print "press a key to continue"
wait_click
return
-----------------------------------------------------
Thanks, CHDKLover