From 1102b26390a39c6700c233e9752d79cc447b896c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 12 Jul 2015 09:04:24 -0400 Subject: [PATCH] Fix expr.lalropo --- lalrpop-test/src/expr.lalrpop | 2 +- lalrpop-test/src/expr.rs | 1782 ++++++++++++++++----------------- lalrpop-test/src/sub.rs | 732 +++++++------- 3 files changed, 1258 insertions(+), 1258 deletions(-) diff --git a/lalrpop-test/src/expr.lalrpop b/lalrpop-test/src/expr.lalrpop index 2f438d4..7c64ee7 100644 --- a/lalrpop-test/src/expr.lalrpop +++ b/lalrpop-test/src/expr.lalrpop @@ -26,7 +26,7 @@ grammar { }; Term = { - ; + <"Num">; "(" ")"; }; } diff --git a/lalrpop-test/src/expr.rs b/lalrpop-test/src/expr.rs index 8d05e3d..fb424e6 100644 --- a/lalrpop-test/src/expr.rs +++ b/lalrpop-test/src/expr.rs @@ -19,10 +19,10 @@ mod __parse__Expr { use util::tok::Tok; pub enum __Nonterminal { - Expr(i32), - Term(i32), - Factor(i32), __Expr(i32), + Term(i32), + Expr(i32), + Factor(i32), } // State 0 @@ -63,11 +63,11 @@ mod __parse__Expr { // __Expr = (*) Expr [EOF] // // "Num" -> Shift(S2) - // "(" -> Shift(S1) + // "(" -> Shift(S4) // - // Expr -> S3 - // Term -> S5 - // Factor -> S4 + // Expr -> S1 + // Term -> S3 + // Factor -> S5 pub fn __state0>( mut lookahead: Option, tokens: &mut TOKENS, @@ -82,7 +82,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym0 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state1(lookahead, tokens, sym0)); + result = try!(__state4(lookahead, tokens, sym0)); } _ => { return Err(lookahead); @@ -93,15 +93,15 @@ mod __parse__Expr { match nt { __Nonterminal::Expr(nt) => { let sym0 = &mut Some(nt); - result = try!(__state3(lookahead, tokens, sym0)); + result = try!(__state1(lookahead, tokens, sym0)); } __Nonterminal::Term(nt) => { let sym0 = &mut Some(nt); - result = try!(__state5(lookahead, tokens, sym0)); + result = try!(__state3(lookahead, tokens, sym0)); } __Nonterminal::Factor(nt) => { let sym0 = &mut Some(nt); - result = try!(__state4(lookahead, tokens, sym0)); + result = try!(__state5(lookahead, tokens, sym0)); } _ => { return Ok((lookahead, nt)); @@ -111,6 +111,150 @@ mod __parse__Expr { } // State 1 + // Expr = Expr (*) "+" Factor [EOF] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [EOF] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // __Expr = Expr (*) [EOF] + // + // EOF -> Reduce(__Expr = Expr => ActionFn(0);) + // "-" -> Shift(S7) + // "+" -> Shift(S6) + // + pub fn __state1>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(lookahead, tokens, sym0, sym1)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state6(lookahead, tokens, sym0, sym1)); + } + None => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action0(sym0); + return Ok((lookahead, __Nonterminal::__Expr(nt))); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 2 + // Term = "Num" (*) [EOF] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] + // + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) + // EOF -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // + pub fn __state2>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + _ => { + return Err(lookahead); + } + } + } + + // State 3 + // Factor = Term (*) [EOF] + // Factor = Term (*) ["*"] + // Factor = Term (*) ["+"] + // Factor = Term (*) ["-"] + // Factor = Term (*) ["/"] + // + // "+" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // "-" -> Reduce(Factor = Term => ActionFn(6);) + // "/" -> Reduce(Factor = Term => ActionFn(6);) + // EOF -> Reduce(Factor = Term => ActionFn(6);) + // + pub fn __state3>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + _ => { + return Err(lookahead); + } + } + } + + // State 4 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -151,28 +295,28 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S10) - // "Num" -> Shift(S6) + // "Num" -> Shift(S11) + // "(" -> Shift(S12) // - // Factor -> S7 - // Term -> S8 - // Expr -> S9 - pub fn __state1>( + // Factor -> S10 + // Term -> S9 + // Expr -> S8 + pub fn __state4>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym1)); - } Some(Tok::Num(__tok0)) => { let mut sym1 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym1)); + result = try!(__state11(lookahead, tokens, sym1)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state12(lookahead, tokens, sym1)); } _ => { return Err(lookahead); @@ -183,15 +327,15 @@ mod __parse__Expr { match nt { __Nonterminal::Factor(nt) => { let sym1 = &mut Some(nt); - result = try!(__state7(lookahead, tokens, sym1)); + result = try!(__state10(lookahead, tokens, sym1)); } __Nonterminal::Term(nt) => { let sym1 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym1)); + result = try!(__state9(lookahead, tokens, sym1)); } __Nonterminal::Expr(nt) => { let sym1 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym0, sym1)); + result = try!(__state8(lookahead, tokens, sym0, sym1)); } _ => { return Ok((lookahead, nt)); @@ -201,100 +345,7 @@ mod __parse__Expr { return Ok(result); } - // State 2 - // Term = "Num" (*) [EOF] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // "+" -> Reduce(Term = "Num" => ActionFn(7);) - // "*" -> Reduce(Term = "Num" => ActionFn(7);) - // EOF -> Reduce(Term = "Num" => ActionFn(7);) - // - pub fn __state2>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - None => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 3 - // Expr = Expr (*) "+" Factor [EOF] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [EOF] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // __Expr = Expr (*) [EOF] - // - // "+" -> Shift(S11) - // "-" -> Shift(S12) - // EOF -> Reduce(__Expr = Expr => ActionFn(0);) - // - pub fn __state3>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::Plus(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state11(lookahead, tokens, sym0, sym1)); - } - Some(__tok @ Tok::Minus(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state12(lookahead, tokens, sym0, sym1)); - } - None => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action0(sym0); - return Ok((lookahead, __Nonterminal::__Expr(nt))); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 4 + // State 5 // Expr = Factor (*) [EOF] // Expr = Factor (*) ["+"] // Expr = Factor (*) ["-"] @@ -309,13 +360,13 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "+" -> Reduce(Expr = Factor => ActionFn(3);) // "/" -> Shift(S13) - // "*" -> Shift(S14) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) // "-" -> Reduce(Expr = Factor => ActionFn(3);) // EOF -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S14) // - pub fn __state4>( + pub fn __state5>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -354,101 +405,249 @@ mod __parse__Expr { return Ok(result); } - // State 5 - // Factor = Term (*) [EOF] + // State 6 + // Expr = Expr "+" (*) Factor [EOF] + // Expr = Expr "+" (*) Factor ["+"] + // Expr = Expr "+" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S2) + // "(" -> Shift(S4) + // + // Term -> S3 + // Factor -> S15 + pub fn __state6>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state2(lookahead, tokens, sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state4(lookahead, tokens, sym2)); + } + _ => { + return Err(lookahead); + } + } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::Term(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state3(lookahead, tokens, sym2)); + } + __Nonterminal::Factor(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state15(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 7 + // Expr = Expr "-" (*) Factor [EOF] + // Expr = Expr "-" (*) Factor ["+"] + // Expr = Expr "-" (*) Factor ["-"] + // Factor = (*) Factor "*" Term [EOF] + // Factor = (*) Factor "*" Term ["*"] + // Factor = (*) Factor "*" Term ["+"] + // Factor = (*) Factor "*" Term ["-"] + // Factor = (*) Factor "*" Term ["/"] + // Factor = (*) Factor "/" Term [EOF] + // Factor = (*) Factor "/" Term ["*"] + // Factor = (*) Factor "/" Term ["+"] + // Factor = (*) Factor "/" Term ["-"] + // Factor = (*) Factor "/" Term ["/"] + // Factor = (*) Term [EOF] + // Factor = (*) Term ["*"] + // Factor = (*) Term ["+"] + // Factor = (*) Term ["-"] + // Factor = (*) Term ["/"] + // Term = (*) "(" Expr ")" [EOF] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [EOF] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S4) + // "Num" -> Shift(S2) + // + // Term -> S3 + // Factor -> S16 + pub fn __state7>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state4(lookahead, tokens, sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state2(lookahead, tokens, sym2)); + } + _ => { + return Err(lookahead); + } + } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::Term(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state3(lookahead, tokens, sym2)); + } + __Nonterminal::Factor(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state16(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 8 + // Expr = Expr (*) "+" Factor [")"] + // Expr = Expr (*) "+" Factor ["+"] + // Expr = Expr (*) "+" Factor ["-"] + // Expr = Expr (*) "-" Factor [")"] + // Expr = Expr (*) "-" Factor ["+"] + // Expr = Expr (*) "-" Factor ["-"] + // Term = "(" Expr (*) ")" [EOF] + // Term = "(" Expr (*) ")" ["*"] + // Term = "(" Expr (*) ")" ["+"] + // Term = "(" Expr (*) ")" ["-"] + // Term = "(" Expr (*) ")" ["/"] + // + // ")" -> Shift(S18) + // "+" -> Shift(S19) + // "-" -> Shift(S17) + // + pub fn __state8>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::RParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state18(lookahead, tokens, sym0, sym1, sym2)); + } + Some(__tok @ Tok::Plus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state19(lookahead, tokens, sym1, sym2)); + } + Some(__tok @ Tok::Minus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state17(lookahead, tokens, sym1, sym2)); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 9 + // Factor = Term (*) [")"] // Factor = Term (*) ["*"] // Factor = Term (*) ["+"] // Factor = Term (*) ["-"] // Factor = Term (*) ["/"] // - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // EOF -> Reduce(Factor = Term => ActionFn(6);) - // "/" -> Reduce(Factor = Term => ActionFn(6);) + // ")" -> Reduce(Factor = Term => ActionFn(6);) // "+" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Factor = Term => ActionFn(6);) + // "/" -> Reduce(Factor = Term => ActionFn(6);) // "-" -> Reduce(Factor = Term => ActionFn(6);) // - pub fn __state5>( + pub fn __state9>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - None => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 6 - // Term = "Num" (*) [")"] - // Term = "Num" (*) ["*"] - // Term = "Num" (*) ["+"] - // Term = "Num" (*) ["-"] - // Term = "Num" (*) ["/"] - // - // "-" -> Reduce(Term = "Num" => ActionFn(7);) - // ")" -> Reduce(Term = "Num" => ActionFn(7);) - // "*" -> Reduce(Term = "Num" => ActionFn(7);) - // "+" -> Reduce(Term = "Num" => ActionFn(7);) - // "/" -> Reduce(Term = "Num" => ActionFn(7);) - // - pub fn __state6>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); } Some(Tok::Plus(..)) => { let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); } Some(Tok::Div(..)) => { let sym0 = sym0.take().unwrap(); - let nt = super::__action7(sym0); - return Ok((lookahead, __Nonterminal::Term(nt))); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action6(sym0); + return Ok((lookahead, __Nonterminal::Factor(nt))); } _ => { return Err(lookahead); @@ -456,7 +655,7 @@ mod __parse__Expr { } } - // State 7 + // State 10 // Expr = Factor (*) [")"] // Expr = Factor (*) ["+"] // Expr = Factor (*) ["-"] @@ -471,28 +670,33 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "*" -> Shift(S16) + // "/" -> Shift(S20) + // "+" -> Reduce(Expr = Factor => ActionFn(3);) // "-" -> Reduce(Expr = Factor => ActionFn(3);) // ")" -> Reduce(Expr = Factor => ActionFn(3);) - // "/" -> Shift(S15) - // "+" -> Reduce(Expr = Factor => ActionFn(3);) + // "*" -> Shift(S21) // - pub fn __state7>( + pub fn __state10>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state16(lookahead, tokens, sym0, sym1)); - } Some(__tok @ Tok::Div(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state15(lookahead, tokens, sym0, sym1)); + result = try!(__state20(lookahead, tokens, sym0, sym1)); + } + Some(__tok @ Tok::Times(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state21(lookahead, tokens, sym0, sym1)); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::Expr(nt))); } Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); @@ -504,11 +708,6 @@ mod __parse__Expr { let nt = super::__action3(sym0); return Ok((lookahead, __Nonterminal::Expr(nt))); } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action3(sym0); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } _ => { return Err(lookahead); } @@ -516,50 +715,50 @@ mod __parse__Expr { return Ok(result); } - // State 8 - // Factor = Term (*) [")"] - // Factor = Term (*) ["*"] - // Factor = Term (*) ["+"] - // Factor = Term (*) ["-"] - // Factor = Term (*) ["/"] + // State 11 + // Term = "Num" (*) [")"] + // Term = "Num" (*) ["*"] + // Term = "Num" (*) ["+"] + // Term = "Num" (*) ["-"] + // Term = "Num" (*) ["/"] // - // "/" -> Reduce(Factor = Term => ActionFn(6);) - // "+" -> Reduce(Factor = Term => ActionFn(6);) - // "*" -> Reduce(Factor = Term => ActionFn(6);) - // "-" -> Reduce(Factor = Term => ActionFn(6);) - // ")" -> Reduce(Factor = Term => ActionFn(6);) + // "*" -> Reduce(Term = "Num" => ActionFn(7);) + // "-" -> Reduce(Term = "Num" => ActionFn(7);) + // "/" -> Reduce(Term = "Num" => ActionFn(7);) + // ")" -> Reduce(Term = "Num" => ActionFn(7);) + // "+" -> Reduce(Term = "Num" => ActionFn(7);) // - pub fn __state8>( + pub fn __state11>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } Some(Tok::Times(..)) => { let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); } Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); } Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); - let nt = super::__action6(sym0); - return Ok((lookahead, __Nonterminal::Factor(nt))); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action7(sym0); + return Ok((lookahead, __Nonterminal::Term(nt))); } _ => { return Err(lookahead); @@ -567,54 +766,7 @@ mod __parse__Expr { } } - // State 9 - // Expr = Expr (*) "+" Factor [")"] - // Expr = Expr (*) "+" Factor ["+"] - // Expr = Expr (*) "+" Factor ["-"] - // Expr = Expr (*) "-" Factor [")"] - // Expr = Expr (*) "-" Factor ["+"] - // Expr = Expr (*) "-" Factor ["-"] - // Term = "(" Expr (*) ")" [EOF] - // Term = "(" Expr (*) ")" ["*"] - // Term = "(" Expr (*) ")" ["+"] - // Term = "(" Expr (*) ")" ["-"] - // Term = "(" Expr (*) ")" ["/"] - // - // ")" -> Shift(S18) - // "-" -> Shift(S17) - // "+" -> Shift(S19) - // - pub fn __state9>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::RParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state18(lookahead, tokens, sym0, sym1, sym2)); - } - Some(__tok @ Tok::Minus(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state17(lookahead, tokens, sym1, sym2)); - } - Some(__tok @ Tok::Plus(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state19(lookahead, tokens, sym1, sym2)); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 10 + // State 12 // Expr = (*) Expr "+" Factor [")"] // Expr = (*) Expr "+" Factor ["+"] // Expr = (*) Expr "+" Factor ["-"] @@ -655,13 +807,13 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S10) - // "Num" -> Shift(S6) + // "(" -> Shift(S12) + // "Num" -> Shift(S11) // - // Factor -> S7 - // Term -> S8 - // Expr -> S20 - pub fn __state10>( + // Term -> S9 + // Factor -> S10 + // Expr -> S22 + pub fn __state12>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -671,12 +823,12 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym1)); + result = try!(__state12(lookahead, tokens, sym1)); } Some(Tok::Num(__tok0)) => { let mut sym1 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym1)); + result = try!(__state11(lookahead, tokens, sym1)); } _ => { return Err(lookahead); @@ -685,169 +837,17 @@ mod __parse__Expr { while sym0.is_some() { let (lookahead, nt) = result; match nt { - __Nonterminal::Factor(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state7(lookahead, tokens, sym1)); - } __Nonterminal::Term(nt) => { let sym1 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym1)); + result = try!(__state9(lookahead, tokens, sym1)); + } + __Nonterminal::Factor(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state10(lookahead, tokens, sym1)); } __Nonterminal::Expr(nt) => { let sym1 = &mut Some(nt); - result = try!(__state20(lookahead, tokens, sym0, sym1)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 11 - // Expr = Expr "+" (*) Factor [EOF] - // Expr = Expr "+" (*) Factor ["+"] - // Expr = Expr "+" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "Num" -> Shift(S2) - // "(" -> Shift(S1) - // - // Term -> S5 - // Factor -> S21 - pub fn __state11>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state2(lookahead, tokens, sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state1(lookahead, tokens, sym2)); - } - _ => { - return Err(lookahead); - } - } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::Term(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state5(lookahead, tokens, sym2)); - } - __Nonterminal::Factor(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state21(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 12 - // Expr = Expr "-" (*) Factor [EOF] - // Expr = Expr "-" (*) Factor ["+"] - // Expr = Expr "-" (*) Factor ["-"] - // Factor = (*) Factor "*" Term [EOF] - // Factor = (*) Factor "*" Term ["*"] - // Factor = (*) Factor "*" Term ["+"] - // Factor = (*) Factor "*" Term ["-"] - // Factor = (*) Factor "*" Term ["/"] - // Factor = (*) Factor "/" Term [EOF] - // Factor = (*) Factor "/" Term ["*"] - // Factor = (*) Factor "/" Term ["+"] - // Factor = (*) Factor "/" Term ["-"] - // Factor = (*) Factor "/" Term ["/"] - // Factor = (*) Term [EOF] - // Factor = (*) Term ["*"] - // Factor = (*) Term ["+"] - // Factor = (*) Term ["-"] - // Factor = (*) Term ["/"] - // Term = (*) "(" Expr ")" [EOF] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [EOF] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] - // - // "(" -> Shift(S1) - // "Num" -> Shift(S2) - // - // Factor -> S22 - // Term -> S5 - pub fn __state12>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state1(lookahead, tokens, sym2)); - } - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state2(lookahead, tokens, sym2)); - } - _ => { - return Err(lookahead); - } - } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::Factor(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state22(lookahead, tokens, sym0, sym1, sym2)); - } - __Nonterminal::Term(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state5(lookahead, tokens, sym2)); + result = try!(__state22(lookahead, tokens, sym0, sym1)); } _ => { return Ok((lookahead, nt)); @@ -875,7 +875,7 @@ mod __parse__Expr { // Term = (*) "Num" ["/"] // // "Num" -> Shift(S2) - // "(" -> Shift(S1) + // "(" -> Shift(S4) // // Term -> S23 pub fn __state13>( @@ -894,7 +894,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state1(lookahead, tokens, sym2)); + result = try!(__state4(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -932,7 +932,7 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S1) + // "(" -> Shift(S4) // "Num" -> Shift(S2) // // Term -> S24 @@ -947,7 +947,7 @@ mod __parse__Expr { Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state1(lookahead, tokens, sym2)); + result = try!(__state4(lookahead, tokens, sym2)); } Some(Tok::Num(__tok0)) => { let mut sym2 = &mut Some((__tok0)); @@ -974,118 +974,138 @@ mod __parse__Expr { } // State 15 - // Factor = Factor "/" (*) Term [")"] - // Factor = Factor "/" (*) Term ["*"] - // Factor = Factor "/" (*) Term ["+"] - // Factor = Factor "/" (*) Term ["-"] - // Factor = Factor "/" (*) Term ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] + // Expr = Expr "+" Factor (*) [EOF] + // Expr = Expr "+" Factor (*) ["+"] + // Expr = Expr "+" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "Num" -> Shift(S6) - // "(" -> Shift(S10) + // "*" -> Shift(S14) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S13) + // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // - // Term -> S25 pub fn __state15>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, sym1: &mut Option, + sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); + Some(__tok @ Tok::Times(..)) => { + let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym2)); + result = try!(__state14(lookahead, tokens, sym2, sym3)); } - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); + Some(__tok @ Tok::Div(..)) => { + let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym2)); + result = try!(__state13(lookahead, tokens, sym2, sym3)); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); } _ => { return Err(lookahead); } } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::Term(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state25(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } return Ok(result); } // State 16 - // Factor = Factor "*" (*) Term [")"] - // Factor = Factor "*" (*) Term ["*"] - // Factor = Factor "*" (*) Term ["+"] - // Factor = Factor "*" (*) Term ["-"] - // Factor = Factor "*" (*) Term ["/"] - // Term = (*) "(" Expr ")" [")"] - // Term = (*) "(" Expr ")" ["*"] - // Term = (*) "(" Expr ")" ["+"] - // Term = (*) "(" Expr ")" ["-"] - // Term = (*) "(" Expr ")" ["/"] - // Term = (*) "Num" [")"] - // Term = (*) "Num" ["*"] - // Term = (*) "Num" ["+"] - // Term = (*) "Num" ["-"] - // Term = (*) "Num" ["/"] + // Expr = Expr "-" Factor (*) [EOF] + // Expr = Expr "-" Factor (*) ["+"] + // Expr = Expr "-" Factor (*) ["-"] + // Factor = Factor (*) "*" Term [EOF] + // Factor = Factor (*) "*" Term ["*"] + // Factor = Factor (*) "*" Term ["+"] + // Factor = Factor (*) "*" Term ["-"] + // Factor = Factor (*) "*" Term ["/"] + // Factor = Factor (*) "/" Term [EOF] + // Factor = Factor (*) "/" Term ["*"] + // Factor = Factor (*) "/" Term ["+"] + // Factor = Factor (*) "/" Term ["-"] + // Factor = Factor (*) "/" Term ["/"] // - // "(" -> Shift(S10) - // "Num" -> Shift(S6) + // "/" -> Shift(S13) + // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "*" -> Shift(S14) + // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // - // Term -> S26 pub fn __state16>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, sym1: &mut Option, + sym2: &mut Option, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); + Some(__tok @ Tok::Div(..)) => { + let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym2)); + result = try!(__state13(lookahead, tokens, sym2, sym3)); } - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); + Some(__tok @ Tok::Times(..)) => { + let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym2)); + result = try!(__state14(lookahead, tokens, sym2, sym3)); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); } _ => { return Err(lookahead); } } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::Term(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state26(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } return Ok(result); } @@ -1119,11 +1139,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "Num" -> Shift(S6) - // "(" -> Shift(S10) + // "(" -> Shift(S12) + // "Num" -> Shift(S11) // - // Factor -> S27 - // Term -> S8 + // Factor -> S25 + // Term -> S9 pub fn __state17>( mut lookahead: Option, tokens: &mut TOKENS, @@ -1132,15 +1152,15 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym2)); - } Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym2)); + result = try!(__state12(lookahead, tokens, sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state11(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -1151,11 +1171,11 @@ mod __parse__Expr { match nt { __Nonterminal::Factor(nt) => { let sym2 = &mut Some(nt); - result = try!(__state27(lookahead, tokens, sym0, sym1, sym2)); + result = try!(__state25(lookahead, tokens, sym0, sym1, sym2)); } __Nonterminal::Term(nt) => { let sym2 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym2)); + result = try!(__state9(lookahead, tokens, sym2)); } _ => { return Ok((lookahead, nt)); @@ -1172,11 +1192,11 @@ mod __parse__Expr { // Term = "(" Expr ")" (*) ["-"] // Term = "(" Expr ")" (*) ["/"] // - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // EOF -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // pub fn __state18>( mut lookahead: Option, @@ -1187,14 +1207,7 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action8(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::Plus(..)) => { + None => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); @@ -1215,7 +1228,14 @@ mod __parse__Expr { let nt = super::__action8(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Term(nt))); } - None => { + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action8(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Term(nt))); + } + Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); @@ -1258,11 +1278,11 @@ mod __parse__Expr { // Term = (*) "Num" ["-"] // Term = (*) "Num" ["/"] // - // "(" -> Shift(S10) - // "Num" -> Shift(S6) + // "Num" -> Shift(S11) + // "(" -> Shift(S12) // - // Term -> S8 - // Factor -> S28 + // Term -> S9 + // Factor -> S26 pub fn __state19>( mut lookahead: Option, tokens: &mut TOKENS, @@ -1271,15 +1291,15 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym2)); - } Some(Tok::Num(__tok0)) => { let mut sym2 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym2)); + result = try!(__state11(lookahead, tokens, sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state12(lookahead, tokens, sym2)); } _ => { return Err(lookahead); @@ -1290,9 +1310,125 @@ mod __parse__Expr { match nt { __Nonterminal::Term(nt) => { let sym2 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym2)); + result = try!(__state9(lookahead, tokens, sym2)); } __Nonterminal::Factor(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state26(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 20 + // Factor = Factor "/" (*) Term [")"] + // Factor = Factor "/" (*) Term ["*"] + // Factor = Factor "/" (*) Term ["+"] + // Factor = Factor "/" (*) Term ["-"] + // Factor = Factor "/" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "Num" -> Shift(S11) + // "(" -> Shift(S12) + // + // Term -> S27 + pub fn __state20>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state11(lookahead, tokens, sym2)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state12(lookahead, tokens, sym2)); + } + _ => { + return Err(lookahead); + } + } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::Term(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state27(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 21 + // Factor = Factor "*" (*) Term [")"] + // Factor = Factor "*" (*) Term ["*"] + // Factor = Factor "*" (*) Term ["+"] + // Factor = Factor "*" (*) Term ["-"] + // Factor = Factor "*" (*) Term ["/"] + // Term = (*) "(" Expr ")" [")"] + // Term = (*) "(" Expr ")" ["*"] + // Term = (*) "(" Expr ")" ["+"] + // Term = (*) "(" Expr ")" ["-"] + // Term = (*) "(" Expr ")" ["/"] + // Term = (*) "Num" [")"] + // Term = (*) "Num" ["*"] + // Term = (*) "Num" ["+"] + // Term = (*) "Num" ["-"] + // Term = (*) "Num" ["/"] + // + // "(" -> Shift(S12) + // "Num" -> Shift(S11) + // + // Term -> S28 + pub fn __state21>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state12(lookahead, tokens, sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state11(lookahead, tokens, sym2)); + } + _ => { + return Err(lookahead); + } + } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::Term(nt) => { let sym2 = &mut Some(nt); result = try!(__state28(lookahead, tokens, sym0, sym1, sym2)); } @@ -1304,7 +1440,7 @@ mod __parse__Expr { return Ok(result); } - // State 20 + // State 22 // Expr = Expr (*) "+" Factor [")"] // Expr = Expr (*) "+" Factor ["+"] // Expr = Expr (*) "+" Factor ["-"] @@ -1321,7 +1457,7 @@ mod __parse__Expr { // "-" -> Shift(S17) // ")" -> Shift(S29) // - pub fn __state20>( + pub fn __state22>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -1351,142 +1487,6 @@ mod __parse__Expr { return Ok(result); } - // State 21 - // Expr = Expr "+" Factor (*) [EOF] - // Expr = Expr "+" Factor (*) ["+"] - // Expr = Expr "+" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // "/" -> Shift(S13) - // EOF -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) - // "*" -> Shift(S14) - // - pub fn __state21>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::Div(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state13(lookahead, tokens, sym2, sym3)); - } - Some(__tok @ Tok::Times(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state14(lookahead, tokens, sym2, sym3)); - } - None => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 22 - // Expr = Expr "-" Factor (*) [EOF] - // Expr = Expr "-" Factor (*) ["+"] - // Expr = Expr "-" Factor (*) ["-"] - // Factor = Factor (*) "*" Term [EOF] - // Factor = Factor (*) "*" Term ["*"] - // Factor = Factor (*) "*" Term ["+"] - // Factor = Factor (*) "*" Term ["-"] - // Factor = Factor (*) "*" Term ["/"] - // Factor = Factor (*) "/" Term [EOF] - // Factor = Factor (*) "/" Term ["*"] - // Factor = Factor (*) "/" Term ["+"] - // Factor = Factor (*) "/" Term ["-"] - // Factor = Factor (*) "/" Term ["/"] - // - // "*" -> Shift(S14) - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // EOF -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "/" -> Shift(S13) - // - pub fn __state22>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state14(lookahead, tokens, sym2, sym3)); - } - Some(__tok @ Tok::Div(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state13(lookahead, tokens, sym2, sym3)); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - None => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - // State 23 // Factor = Factor "/" Term (*) [EOF] // Factor = Factor "/" Term (*) ["*"] @@ -1494,11 +1494,11 @@ mod __parse__Expr { // Factor = Factor "/" Term (*) ["-"] // Factor = Factor "/" Term (*) ["/"] // - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) // EOF -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) // pub fn __state23>( mut lookahead: Option, @@ -1509,7 +1509,7 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Div(..)) => { + Some(Tok::Times(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); @@ -1523,6 +1523,13 @@ mod __parse__Expr { let nt = super::__action5(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Factor(nt))); } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } Some(Tok::Plus(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); @@ -1537,13 +1544,6 @@ mod __parse__Expr { let nt = super::__action5(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Factor(nt))); } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } _ => { return Err(lookahead); } @@ -1557,11 +1557,11 @@ mod __parse__Expr { // Factor = Factor "*" Term (*) ["-"] // Factor = Factor "*" Term (*) ["/"] // - // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // EOF -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) // pub fn __state24>( mut lookahead: Option, @@ -1572,7 +1572,7 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Times(..)) => { + Some(Tok::Div(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); @@ -1586,6 +1586,13 @@ mod __parse__Expr { let nt = super::__action4(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Factor(nt))); } + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action4(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } None => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); @@ -1600,13 +1607,6 @@ mod __parse__Expr { let nt = super::__action4(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Factor(nt))); } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } _ => { return Err(lookahead); } @@ -1614,132 +1614,6 @@ mod __parse__Expr { } // State 25 - // Factor = Factor "/" Term (*) [")"] - // Factor = Factor "/" Term (*) ["*"] - // Factor = Factor "/" Term (*) ["+"] - // Factor = Factor "/" Term (*) ["-"] - // Factor = Factor "/" Term (*) ["/"] - // - // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) - // - pub fn __state25>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 26 - // Factor = Factor "*" Term (*) [")"] - // Factor = Factor "*" Term (*) ["*"] - // Factor = Factor "*" Term (*) ["+"] - // Factor = Factor "*" Term (*) ["-"] - // Factor = Factor "*" Term (*) ["/"] - // - // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) - // - pub fn __state26>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Times(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - Some(Tok::Div(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action4(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Factor(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 27 // Expr = Expr "-" Factor (*) [")"] // Expr = Expr "-" Factor (*) ["+"] // Expr = Expr "-" Factor (*) ["-"] @@ -1754,13 +1628,13 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // ")" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) + // "/" -> Shift(S20) // "+" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) - // "*" -> Shift(S16) - // "/" -> Shift(S15) + // "*" -> Shift(S21) + // "-" -> Reduce(Expr = Expr, "-", Factor => ActionFn(1);) // - pub fn __state27>( + pub fn __state25>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -1769,22 +1643,15 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Times(..)) => { - let mut sym3 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state16(lookahead, tokens, sym2, sym3)); - } Some(__tok @ Tok::Div(..)) => { let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state15(lookahead, tokens, sym2, sym3)); + result = try!(__state20(lookahead, tokens, sym2, sym3)); } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action1(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); + Some(__tok @ Tok::Times(..)) => { + let mut sym3 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state21(lookahead, tokens, sym2, sym3)); } Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); @@ -1800,6 +1667,13 @@ mod __parse__Expr { let nt = super::__action1(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Expr(nt))); } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action1(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } _ => { return Err(lookahead); } @@ -1807,7 +1681,7 @@ mod __parse__Expr { return Ok(result); } - // State 28 + // State 26 // Expr = Expr "+" Factor (*) [")"] // Expr = Expr "+" Factor (*) ["+"] // Expr = Expr "+" Factor (*) ["-"] @@ -1822,13 +1696,13 @@ mod __parse__Expr { // Factor = Factor (*) "/" Term ["-"] // Factor = Factor (*) "/" Term ["/"] // - // "/" -> Shift(S15) - // "*" -> Shift(S16) - // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // ")" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // "-" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) + // "/" -> Shift(S20) + // "*" -> Shift(S21) + // "+" -> Reduce(Expr = Expr, "+", Factor => ActionFn(2);) // - pub fn __state28>( + pub fn __state26>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -1840,19 +1714,12 @@ mod __parse__Expr { Some(__tok @ Tok::Div(..)) => { let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state15(lookahead, tokens, sym2, sym3)); + result = try!(__state20(lookahead, tokens, sym2, sym3)); } Some(__tok @ Tok::Times(..)) => { let mut sym3 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state16(lookahead, tokens, sym2, sym3)); - } - Some(Tok::Plus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action2(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Expr(nt))); + result = try!(__state21(lookahead, tokens, sym2, sym3)); } Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); @@ -1868,6 +1735,13 @@ mod __parse__Expr { let nt = super::__action2(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Expr(nt))); } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action2(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Expr(nt))); + } _ => { return Err(lookahead); } @@ -1875,6 +1749,132 @@ mod __parse__Expr { return Ok(result); } + // State 27 + // Factor = Factor "/" Term (*) [")"] + // Factor = Factor "/" Term (*) ["*"] + // Factor = Factor "/" Term (*) ["+"] + // Factor = Factor "/" Term (*) ["-"] + // Factor = Factor "/" Term (*) ["/"] + // + // ")" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "*" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "/" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "+" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // "-" -> Reduce(Factor = Factor, "/", Term => ActionFn(5);) + // + pub fn __state27>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + _ => { + return Err(lookahead); + } + } + } + + // State 28 + // Factor = Factor "*" Term (*) [")"] + // Factor = Factor "*" Term (*) ["*"] + // Factor = Factor "*" Term (*) ["+"] + // Factor = Factor "*" Term (*) ["-"] + // Factor = Factor "*" Term (*) ["/"] + // + // "-" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "+" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "/" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // ")" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // "*" -> Reduce(Factor = Factor, "*", Term => ActionFn(4);) + // + pub fn __state28>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action4(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Plus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action4(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action4(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action4(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + Some(Tok::Times(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action4(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Factor(nt))); + } + _ => { + return Err(lookahead); + } + } + } + // State 29 // Term = "(" Expr ")" (*) [")"] // Term = "(" Expr ")" (*) ["*"] @@ -1882,11 +1882,11 @@ mod __parse__Expr { // Term = "(" Expr ")" (*) ["-"] // Term = "(" Expr ")" (*) ["/"] // - // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) - // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // "+" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "*" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "-" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // ")" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) + // "/" -> Reduce(Term = "(", Expr, ")" => ActionFn(8);) // pub fn __state29>( mut lookahead: Option, @@ -1897,14 +1897,7 @@ mod __parse__Expr { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action8(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::Term(nt))); - } - Some(Tok::Div(..)) => { + Some(Tok::Plus(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); @@ -1918,7 +1911,7 @@ mod __parse__Expr { let nt = super::__action8(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Term(nt))); } - Some(Tok::Plus(..)) => { + Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); @@ -1932,6 +1925,13 @@ mod __parse__Expr { let nt = super::__action8(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::Term(nt))); } + Some(Tok::Div(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action8(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::Term(nt))); + } _ => { return Err(lookahead); } diff --git a/lalrpop-test/src/sub.rs b/lalrpop-test/src/sub.rs index 6f0160a..54bcd19 100644 --- a/lalrpop-test/src/sub.rs +++ b/lalrpop-test/src/sub.rs @@ -19,10 +19,10 @@ mod __parse__S { use util::tok::Tok; pub enum __Nonterminal { + S(i32), T(i32), E(i32), __S(i32), - S(i32), } // State 0 @@ -37,27 +37,27 @@ mod __parse__S { // T = (*) "Num" ["-"] // __S = (*) S [EOF] // - // "(" -> Shift(S3) - // "Num" -> Shift(S5) + // "Num" -> Shift(S3) + // "(" -> Shift(S2) // - // S -> S2 - // E -> S1 - // T -> S4 + // T -> S1 + // S -> S4 + // E -> S5 pub fn __state0>( mut lookahead: Option, tokens: &mut TOKENS, ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym0 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state3(lookahead, tokens, sym0)); - } Some(Tok::Num(__tok0)) => { let mut sym0 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state5(lookahead, tokens, sym0)); + result = try!(__state3(lookahead, tokens, sym0)); + } + Some(__tok @ Tok::LParen(..)) => { + let mut sym0 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state2(lookahead, tokens, sym0)); } _ => { return Err(lookahead); @@ -66,18 +66,18 @@ mod __parse__S { loop { let (lookahead, nt) = result; match nt { - __Nonterminal::S(nt) => { - let sym0 = &mut Some(nt); - result = try!(__state2(lookahead, tokens, sym0)); - } - __Nonterminal::E(nt) => { + __Nonterminal::T(nt) => { let sym0 = &mut Some(nt); result = try!(__state1(lookahead, tokens, sym0)); } - __Nonterminal::T(nt) => { + __Nonterminal::S(nt) => { let sym0 = &mut Some(nt); result = try!(__state4(lookahead, tokens, sym0)); } + __Nonterminal::E(nt) => { + let sym0 = &mut Some(nt); + result = try!(__state5(lookahead, tokens, sym0)); + } _ => { return Ok((lookahead, nt)); } @@ -86,12 +86,11 @@ mod __parse__S { } // State 1 - // E = E (*) "-" T [EOF] - // E = E (*) "-" T ["-"] - // S = E (*) [EOF] + // E = T (*) [EOF] + // E = T (*) ["-"] // - // "-" -> Shift(S6) - // EOF -> Reduce(S = E => ActionFn(1);) + // EOF -> Reduce(E = T => ActionFn(3);) + // "-" -> Reduce(E = T => ActionFn(3);) // pub fn __state1>( mut lookahead: Option, @@ -100,29 +99,115 @@ mod __parse__S { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state6(lookahead, tokens, sym0, sym1)); - } None => { let sym0 = sym0.take().unwrap(); - let nt = super::__action1(sym0); - return Ok((lookahead, __Nonterminal::S(nt))); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::E(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action3(sym0); + return Ok((lookahead, __Nonterminal::E(nt))); } _ => { return Err(lookahead); } } - return Ok(result); } // State 2 + // E = (*) E "-" T [")"] + // E = (*) E "-" T ["-"] + // E = (*) T [")"] + // E = (*) T ["-"] + // T = (*) "(" E ")" [")"] + // T = (*) "(" E ")" ["-"] + // T = "(" (*) E ")" [EOF] + // T = "(" (*) E ")" ["-"] + // T = (*) "Num" [")"] + // T = (*) "Num" ["-"] + // + // "(" -> Shift(S7) + // "Num" -> Shift(S8) + // + // E -> S6 + // T -> S9 + pub fn __state2>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(lookahead, tokens, sym1)); + } + Some(Tok::Num(__tok0)) => { + let mut sym1 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state8(lookahead, tokens, sym1)); + } + _ => { + return Err(lookahead); + } + } + while sym0.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::E(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state6(lookahead, tokens, sym0, sym1)); + } + __Nonterminal::T(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state9(lookahead, tokens, sym1)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 3 + // T = "Num" (*) [EOF] + // T = "Num" (*) ["-"] + // + // "-" -> Reduce(T = "Num" => ActionFn(4);) + // EOF -> Reduce(T = "Num" => ActionFn(4);) + // + pub fn __state3>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); + } + _ => { + return Err(lookahead); + } + } + } + + // State 4 // __S = S (*) [EOF] // // EOF -> Reduce(__S = S => ActionFn(0);) // - pub fn __state2>( + pub fn __state4>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -140,24 +225,90 @@ mod __parse__S { } } - // State 3 + // State 5 + // E = E (*) "-" T [EOF] + // E = E (*) "-" T ["-"] + // S = E (*) [EOF] + // + // EOF -> Reduce(S = E => ActionFn(1);) + // "-" -> Shift(S10) + // + pub fn __state5>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut sym1 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state10(lookahead, tokens, sym0, sym1)); + } + None => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action1(sym0); + return Ok((lookahead, __Nonterminal::S(nt))); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 6 + // E = E (*) "-" T [")"] + // E = E (*) "-" T ["-"] + // T = "(" E (*) ")" [EOF] + // T = "(" E (*) ")" ["-"] + // + // "-" -> Shift(S11) + // ")" -> Shift(S12) + // + pub fn __state6>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state11(lookahead, tokens, sym1, sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state12(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 7 // E = (*) E "-" T [")"] // E = (*) E "-" T ["-"] // E = (*) T [")"] // E = (*) T ["-"] // T = (*) "(" E ")" [")"] // T = (*) "(" E ")" ["-"] - // T = "(" (*) E ")" [EOF] + // T = "(" (*) E ")" [")"] // T = "(" (*) E ")" ["-"] // T = (*) "Num" [")"] // T = (*) "Num" ["-"] // - // "Num" -> Shift(S7) - // "(" -> Shift(S10) + // "Num" -> Shift(S8) + // "(" -> Shift(S7) // - // T -> S8 - // E -> S9 - pub fn __state3>( + // E -> S13 + // T -> S9 + pub fn __state7>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -167,12 +318,12 @@ mod __parse__S { Some(Tok::Num(__tok0)) => { let mut sym1 = &mut Some((__tok0)); let lookahead = tokens.next(); - result = try!(__state7(lookahead, tokens, sym1)); + result = try!(__state8(lookahead, tokens, sym1)); } Some(__tok @ Tok::LParen(..)) => { let mut sym1 = &mut Some(__tok); let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym1)); + result = try!(__state7(lookahead, tokens, sym1)); } _ => { return Err(lookahead); @@ -181,13 +332,13 @@ mod __parse__S { while sym0.is_some() { let (lookahead, nt) = result; match nt { - __Nonterminal::T(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym1)); - } __Nonterminal::E(nt) => { let sym1 = &mut Some(nt); - result = try!(__state9(lookahead, tokens, sym0, sym1)); + result = try!(__state13(lookahead, tokens, sym0, sym1)); + } + __Nonterminal::T(nt) => { + let sym1 = &mut Some(nt); + result = try!(__state9(lookahead, tokens, sym1)); } _ => { return Ok((lookahead, nt)); @@ -197,14 +348,44 @@ mod __parse__S { return Ok(result); } - // State 4 - // E = T (*) [EOF] + // State 8 + // T = "Num" (*) [")"] + // T = "Num" (*) ["-"] + // + // ")" -> Reduce(T = "Num" => ActionFn(4);) + // "-" -> Reduce(T = "Num" => ActionFn(4);) + // + pub fn __state8>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::RParen(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); + } + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let nt = super::__action4(sym0); + return Ok((lookahead, __Nonterminal::T(nt))); + } + _ => { + return Err(lookahead); + } + } + } + + // State 9 + // E = T (*) [")"] // E = T (*) ["-"] // // "-" -> Reduce(E = T => ActionFn(3);) - // EOF -> Reduce(E = T => ActionFn(3);) + // ")" -> Reduce(E = T => ActionFn(3);) // - pub fn __state4>( + pub fn __state9>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -216,7 +397,7 @@ mod __parse__S { let nt = super::__action3(sym0); return Ok((lookahead, __Nonterminal::E(nt))); } - None => { + Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); let nt = super::__action3(sym0); return Ok((lookahead, __Nonterminal::E(nt))); @@ -227,37 +408,7 @@ mod __parse__S { } } - // State 5 - // T = "Num" (*) [EOF] - // T = "Num" (*) ["-"] - // - // "-" -> Reduce(T = "Num" => ActionFn(4);) - // EOF -> Reduce(T = "Num" => ActionFn(4);) - // - pub fn __state5>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); - } - None => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 6 + // State 10 // E = E "-" (*) T [EOF] // E = E "-" (*) T ["-"] // T = (*) "(" E ")" [EOF] @@ -265,11 +416,11 @@ mod __parse__S { // T = (*) "Num" [EOF] // T = (*) "Num" ["-"] // - // "Num" -> Shift(S5) - // "(" -> Shift(S3) + // "(" -> Shift(S2) + // "Num" -> Shift(S3) // - // T -> S11 - pub fn __state6>( + // T -> S14 + pub fn __state10>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -277,14 +428,14 @@ mod __parse__S { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state5(lookahead, tokens, sym2)); - } Some(__tok @ Tok::LParen(..)) => { let mut sym2 = &mut Some(__tok); let lookahead = tokens.next(); + result = try!(__state2(lookahead, tokens, sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); result = try!(__state3(lookahead, tokens, sym2)); } _ => { @@ -296,158 +447,7 @@ mod __parse__S { match nt { __Nonterminal::T(nt) => { let sym2 = &mut Some(nt); - result = try!(__state11(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 7 - // T = "Num" (*) [")"] - // T = "Num" (*) ["-"] - // - // "-" -> Reduce(T = "Num" => ActionFn(4);) - // ")" -> Reduce(T = "Num" => ActionFn(4);) - // - pub fn __state7>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); - } - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action4(sym0); - return Ok((lookahead, __Nonterminal::T(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 8 - // E = T (*) [")"] - // E = T (*) ["-"] - // - // "-" -> Reduce(E = T => ActionFn(3);) - // ")" -> Reduce(E = T => ActionFn(3);) - // - pub fn __state8>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action3(sym0); - return Ok((lookahead, __Nonterminal::E(nt))); - } - Some(Tok::RParen(..)) => { - let sym0 = sym0.take().unwrap(); - let nt = super::__action3(sym0); - return Ok((lookahead, __Nonterminal::E(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 9 - // E = E (*) "-" T [")"] - // E = E (*) "-" T ["-"] - // T = "(" E (*) ")" [EOF] - // T = "(" E (*) ")" ["-"] - // - // "-" -> Shift(S12) - // ")" -> Shift(S13) - // - pub fn __state9>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state12(lookahead, tokens, sym1, sym2)); - } - Some(__tok @ Tok::RParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state13(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - - // State 10 - // E = (*) E "-" T [")"] - // E = (*) E "-" T ["-"] - // E = (*) T [")"] - // E = (*) T ["-"] - // T = (*) "(" E ")" [")"] - // T = (*) "(" E ")" ["-"] - // T = "(" (*) E ")" [")"] - // T = "(" (*) E ")" ["-"] - // T = (*) "Num" [")"] - // T = (*) "Num" ["-"] - // - // "(" -> Shift(S10) - // "Num" -> Shift(S7) - // - // E -> S14 - // T -> S8 - pub fn __state10>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::LParen(..)) => { - let mut sym1 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym1)); - } - Some(Tok::Num(__tok0)) => { - let mut sym1 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state7(lookahead, tokens, sym1)); - } - _ => { - return Err(lookahead); - } - } - while sym0.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::E(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state14(lookahead, tokens, sym0, sym1)); - } - __Nonterminal::T(nt) => { - let sym1 = &mut Some(nt); - result = try!(__state8(lookahead, tokens, sym1)); + result = try!(__state14(lookahead, tokens, sym0, sym1, sym2)); } _ => { return Ok((lookahead, nt)); @@ -458,13 +458,132 @@ mod __parse__S { } // State 11 + // E = E "-" (*) T [")"] + // E = E "-" (*) T ["-"] + // T = (*) "(" E ")" [")"] + // T = (*) "(" E ")" ["-"] + // T = (*) "Num" [")"] + // T = (*) "Num" ["-"] + // + // "(" -> Shift(S7) + // "Num" -> Shift(S8) + // + // T -> S15 + pub fn __state11>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::LParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state7(lookahead, tokens, sym2)); + } + Some(Tok::Num(__tok0)) => { + let mut sym2 = &mut Some((__tok0)); + let lookahead = tokens.next(); + result = try!(__state8(lookahead, tokens, sym2)); + } + _ => { + return Err(lookahead); + } + } + while sym1.is_some() { + let (lookahead, nt) = result; + match nt { + __Nonterminal::T(nt) => { + let sym2 = &mut Some(nt); + result = try!(__state15(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Ok((lookahead, nt)); + } + } + } + return Ok(result); + } + + // State 12 + // T = "(" E ")" (*) [EOF] + // T = "(" E ")" (*) ["-"] + // + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) + // + pub fn __state12>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + sym2: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(Tok::Minus(..)) => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::T(nt))); + } + None => { + let sym0 = sym0.take().unwrap(); + let sym1 = sym1.take().unwrap(); + let sym2 = sym2.take().unwrap(); + let nt = super::__action5(sym0, sym1, sym2); + return Ok((lookahead, __Nonterminal::T(nt))); + } + _ => { + return Err(lookahead); + } + } + } + + // State 13 + // E = E (*) "-" T [")"] + // E = E (*) "-" T ["-"] + // T = "(" E (*) ")" [")"] + // T = "(" E (*) ")" ["-"] + // + // "-" -> Shift(S11) + // ")" -> Shift(S16) + // + pub fn __state13>( + mut lookahead: Option, + tokens: &mut TOKENS, + sym0: &mut Option, + sym1: &mut Option, + ) -> Result<(Option, __Nonterminal), Option> { + let mut result: (Option, __Nonterminal); + match lookahead { + Some(__tok @ Tok::Minus(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state11(lookahead, tokens, sym1, sym2)); + } + Some(__tok @ Tok::RParen(..)) => { + let mut sym2 = &mut Some(__tok); + let lookahead = tokens.next(); + result = try!(__state16(lookahead, tokens, sym0, sym1, sym2)); + } + _ => { + return Err(lookahead); + } + } + return Ok(result); + } + + // State 14 // E = E "-" T (*) [EOF] // E = E "-" T (*) ["-"] // // EOF -> Reduce(E = E, "-", T => ActionFn(2);) // "-" -> Reduce(E = E, "-", T => ActionFn(2);) // - pub fn __state11>( + pub fn __state14>( mut lookahead: Option, tokens: &mut TOKENS, sym0: &mut Option, @@ -493,125 +612,6 @@ mod __parse__S { } } - // State 12 - // E = E "-" (*) T [")"] - // E = E "-" (*) T ["-"] - // T = (*) "(" E ")" [")"] - // T = (*) "(" E ")" ["-"] - // T = (*) "Num" [")"] - // T = (*) "Num" ["-"] - // - // "Num" -> Shift(S7) - // "(" -> Shift(S10) - // - // T -> S15 - pub fn __state12>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(Tok::Num(__tok0)) => { - let mut sym2 = &mut Some((__tok0)); - let lookahead = tokens.next(); - result = try!(__state7(lookahead, tokens, sym2)); - } - Some(__tok @ Tok::LParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state10(lookahead, tokens, sym2)); - } - _ => { - return Err(lookahead); - } - } - while sym1.is_some() { - let (lookahead, nt) = result; - match nt { - __Nonterminal::T(nt) => { - let sym2 = &mut Some(nt); - result = try!(__state15(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Ok((lookahead, nt)); - } - } - } - return Ok(result); - } - - // State 13 - // T = "(" E ")" (*) [EOF] - // T = "(" E ")" (*) ["-"] - // - // EOF -> Reduce(T = "(", E, ")" => ActionFn(5);) - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) - // - pub fn __state13>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - sym2: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - None => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::T(nt))); - } - Some(Tok::Minus(..)) => { - let sym0 = sym0.take().unwrap(); - let sym1 = sym1.take().unwrap(); - let sym2 = sym2.take().unwrap(); - let nt = super::__action5(sym0, sym1, sym2); - return Ok((lookahead, __Nonterminal::T(nt))); - } - _ => { - return Err(lookahead); - } - } - } - - // State 14 - // E = E (*) "-" T [")"] - // E = E (*) "-" T ["-"] - // T = "(" E (*) ")" [")"] - // T = "(" E (*) ")" ["-"] - // - // "-" -> Shift(S12) - // ")" -> Shift(S16) - // - pub fn __state14>( - mut lookahead: Option, - tokens: &mut TOKENS, - sym0: &mut Option, - sym1: &mut Option, - ) -> Result<(Option, __Nonterminal), Option> { - let mut result: (Option, __Nonterminal); - match lookahead { - Some(__tok @ Tok::Minus(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state12(lookahead, tokens, sym1, sym2)); - } - Some(__tok @ Tok::RParen(..)) => { - let mut sym2 = &mut Some(__tok); - let lookahead = tokens.next(); - result = try!(__state16(lookahead, tokens, sym0, sym1, sym2)); - } - _ => { - return Err(lookahead); - } - } - return Ok(result); - } - // State 15 // E = E "-" T (*) [")"] // E = E "-" T (*) ["-"] @@ -652,8 +652,8 @@ mod __parse__S { // T = "(" E ")" (*) [")"] // T = "(" E ")" (*) ["-"] // - // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) // ")" -> Reduce(T = "(", E, ")" => ActionFn(5);) + // "-" -> Reduce(T = "(", E, ")" => ActionFn(5);) // pub fn __state16>( mut lookahead: Option, @@ -664,14 +664,14 @@ mod __parse__S { ) -> Result<(Option, __Nonterminal), Option> { let mut result: (Option, __Nonterminal); match lookahead { - Some(Tok::Minus(..)) => { + Some(Tok::RParen(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap(); let nt = super::__action5(sym0, sym1, sym2); return Ok((lookahead, __Nonterminal::T(nt))); } - Some(Tok::RParen(..)) => { + Some(Tok::Minus(..)) => { let sym0 = sym0.take().unwrap(); let sym1 = sym1.take().unwrap(); let sym2 = sym2.take().unwrap();