Implement check_stack nonrecursively
This commit is contained in:
parent
0490e43422
commit
a37d272892
1 changed files with 10 additions and 9 deletions
|
@ -378,27 +378,28 @@ impl Printer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_stack(&mut self, k: usize) {
|
fn check_stack(&mut self, mut k: usize) {
|
||||||
if let Some(&x) = self.scan_stack.front() {
|
while let Some(&x) = self.scan_stack.front() {
|
||||||
match self.buf[x].token {
|
match self.buf[x].token {
|
||||||
Token::Begin(_) => {
|
Token::Begin(_) => {
|
||||||
if k > 0 {
|
if k == 0 {
|
||||||
self.scan_stack.pop_front().unwrap();
|
break;
|
||||||
self.buf[x].size += self.right_total;
|
|
||||||
self.check_stack(k - 1);
|
|
||||||
}
|
}
|
||||||
|
self.scan_stack.pop_front().unwrap();
|
||||||
|
self.buf[x].size += self.right_total;
|
||||||
|
k -= 1;
|
||||||
}
|
}
|
||||||
Token::End => {
|
Token::End => {
|
||||||
// paper says + not =, but that makes no sense.
|
// paper says + not =, but that makes no sense.
|
||||||
self.scan_stack.pop_front().unwrap();
|
self.scan_stack.pop_front().unwrap();
|
||||||
self.buf[x].size = 1;
|
self.buf[x].size = 1;
|
||||||
self.check_stack(k + 1);
|
k += 1;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.scan_stack.pop_front().unwrap();
|
self.scan_stack.pop_front().unwrap();
|
||||||
self.buf[x].size += self.right_total;
|
self.buf[x].size += self.right_total;
|
||||||
if k > 0 {
|
if k == 0 {
|
||||||
self.check_stack(k);
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue