diff --git a/src/bin/g10.rs b/src/bin/g10.rs index 5b247b1..4d59d47 100644 --- a/src/bin/g10.rs +++ b/src/bin/g10.rs @@ -83,5 +83,5 @@ fn main() { println!( "parsed: {:?}", grammar.slr_parser(&mut m.iter_mut()).parse() - ) + ); } diff --git a/src/cfg/lr_parser.rs b/src/cfg/lr_parser.rs index c3b279b..d25bb24 100644 --- a/src/cfg/lr_parser.rs +++ b/src/cfg/lr_parser.rs @@ -110,13 +110,11 @@ where childs: childs.into_iter().rev().map(|(a, _)| a.clone()).collect(), }); } - let Some(state) = stack.last() else { - return Err("Unexpected EOS 2".into()); - }; - let Some(next) = self.get_goto(&state.1, rule) else { + let state = stack.last().map(|s| s.1).unwrap_or(self.parse_table.2); + let Some(next) = self.get_goto(&state, rule) else { return Err(format!( "Invalid reduction: state: {} rule: {:?}", - state.1, rule + state, rule )); }; stack.push((