The scope created for while/do does NOT extend into the case/else part.
This is because it is a repeating scope and needs to close and re-open.
We *could* include case/else in the final instance of that scope, but
I'm not at all sure that I want to. Maybe later.
So close the scope properly and fix up the test code which depends on
the scope being extended.
Signed-off-by: NeilBrown <neil@brown.name>
else
hi = mid
if hi - lo < 1:
else
hi = mid
if hi - lo < 1:
use GiveUp
use True
do pass
case Found:
print "Yay, I found", target
case GiveUp:
use GiveUp
use True
do pass
case Found:
print "Yay, I found", target
case GiveUp:
- print "Closest I found was", mid
+ print "Closest I found was", lo
###### output: sayhello,55,33,hello,True
Hello World, what lovely oceans you have!
###### output: sayhello,55,33,hello,True
Hello World, what lovely oceans you have!
$0->condpart = $<SP;
$CP->next = $0->casepart;
$0->casepart = $<CP;
$0->condpart = $<SP;
$CP->next = $0->casepart;
$0->casepart = $<CP;
+ var_block_close(c, CloseSequential);
}$
| SwitchPart : IN OptNL CasePart CondSuffix OUT Newlines ${
$0 = $<CS;
$0->condpart = $<SP;
$CP->next = $0->casepart;
$0->casepart = $<CP;
}$
| SwitchPart : IN OptNL CasePart CondSuffix OUT Newlines ${
$0 = $<CS;
$0->condpart = $<SP;
$CP->next = $0->casepart;
$0->casepart = $<CP;
+ var_block_close(c, CloseSequential);
}$
| IfPart IfSuffix ${
$0 = $<IS;
}$
| IfPart IfSuffix ${
$0 = $<IS;
CondSuffix -> IfSuffix ${
$0 = $<1;
CondSuffix -> IfSuffix ${
$0 = $<1;
- // This is where we close scope of the whole
- // "for" or "while" statement
- var_block_close(c, CloseSequential);
}$
| Newlines CasePart CondSuffix ${
$0 = $<CS;
}$
| Newlines CasePart CondSuffix ${
$0 = $<CS;
- // These scopes are closed in CondSuffix
+ // These scopes are closed in CondStatement
ForPart -> for OpenBlock ${
$0 = $<Bl;
}$
ForPart -> for OpenBlock ${
$0 = $<Bl;
}$
- // This scope is closed in CondSuffix
+ // This scope is closed in CondStatement
WhilePart -> while UseBlock OptNL do Block ${
$0.condpart = $<UB;
$0.dopart = $<Bl;
WhilePart -> while UseBlock OptNL do Block ${
$0.condpart = $<UB;
$0.dopart = $<Bl;
+ var_block_close(c, CloseSequential);
}$
| while OpenScope Expression ColonBlock ${
$0.condpart = $<Exp;
$0.dopart = $<Bl;
}$
| while OpenScope Expression ColonBlock ${
$0.condpart = $<Exp;
$0.dopart = $<Bl;
+ var_block_close(c, CloseSequential);
}$
IfPart -> if UseBlock OptNL then OpenBlock ClosePara ${
}$
IfPart -> if UseBlock OptNL then OpenBlock ClosePara ${
- // This scope is closed in CondSuffix
+ // This scope is closed in CondStatement
SwitchPart -> switch OpenScope Expression ${
$0 = $<Ex;
}$
SwitchPart -> switch OpenScope Expression ${
$0 = $<Ex;
}$
else
hi = mid
if hi - lo < 1:
else
hi = mid
if hi - lo < 1:
use GiveUp
use True
do pass
case Found:
print "Yay, I found", target
case GiveUp:
use GiveUp
use True
do pass
case Found:
print "Yay, I found", target
case GiveUp:
- print "Closest I found was", mid
+ print "Closest I found was", lo
size::= 10
list:[size]number
size::= 10
list:[size]number