low stack fix

This commit is contained in:
jusax23 2024-11-09 20:55:28 +01:00
parent 3339bf8fb0
commit 4d42b5ee8e
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
3 changed files with 6 additions and 8 deletions

View file

@ -83,5 +83,5 @@ fn main() {
println!( println!(
"parsed: {:?}", "parsed: {:?}",
grammar.slr_parser(&mut m.iter_mut()).parse() grammar.slr_parser(&mut m.iter_mut()).parse()
) );
} }

View file

@ -110,13 +110,11 @@ where
childs: childs.into_iter().rev().map(|(a, _)| a.clone()).collect(), childs: childs.into_iter().rev().map(|(a, _)| a.clone()).collect(),
}); });
} }
let Some(state) = stack.last() else { let state = stack.last().map(|s| s.1).unwrap_or(self.parse_table.2);
return Err("Unexpected EOS 2".into()); let Some(next) = self.get_goto(&state, rule) else {
};
let Some(next) = self.get_goto(&state.1, rule) else {
return Err(format!( return Err(format!(
"Invalid reduction: state: {} rule: {:?}", "Invalid reduction: state: {} rule: {:?}",
state.1, rule state, rule
)); ));
}; };
stack.push(( stack.push((

View file

@ -197,7 +197,7 @@ fn main() {
//println!("follow: {:?}", grammar.follow); //println!("follow: {:?}", grammar.follow);
grammar.gen_lr1_automaton(); grammar.gen_lr1_automaton();
println!("conflict: {:?}", grammar.lr1_automaton); println!("conflict: {:?}", grammar.lr1_automaton);
/* let conflict = grammar.gen_ll_parse_table(); let conflict = grammar.gen_ll_parse_table();
println!("conflict: {conflict}"); println!("conflict: {conflict}");
println!("prase table: {:?}", grammar.ll_parse_table); println!("prase table: {:?}", grammar.ll_parse_table);
println!("parse\n\n"); println!("parse\n\n");
@ -207,5 +207,5 @@ fn main() {
.ll_parser(&mut m.iter_mut()) .ll_parser(&mut m.iter_mut())
.parse() .parse()
.map(|tree| tree.clean()) .map(|tree| tree.clean())
) */ )
} }