diff options
73 files changed, 3453 insertions, 3167 deletions
diff --git a/autochomp/Cargo.toml b/autochomp/Cargo.toml index 5c323bc..6250332 100644 --- a/autochomp/Cargo.toml +++ b/autochomp/Cargo.toml @@ -6,13 +6,13 @@ edition = "2018" [dev-dependencies] criterion = "0.3.3" -proc-macro2 = "1.0.24" syn = "1.0.58" [dependencies] chewed = {path = "../chewed"} chomp = {path = "../"} chomp-macro = {path = "../chomp-macro"} +proc-macro2 = "1.0.24" [[bench]] name = "parse" diff --git a/autochomp/benches/parse.rs b/autochomp/benches/parse.rs deleted file mode 100644 index a42543a..0000000 --- a/autochomp/benches/parse.rs +++ /dev/null @@ -1,173 +0,0 @@ -use std::error::Error; - -use chewed::{IterWrapper, Parser}; -use chomp::{ - chomp::ast::{Function, NamedExpression}, - nibble, -}; -use criterion::{ - criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, - Throughput, -}; - -const INPUTS: &[&str] = &[ - r##"match _ : None | "a" : Some;"##, - r##"let opt(x) = _ : None | "a" : Some; - match [plus](("a" : First) . (opt(plus) : Next));"##, - r##"let opt(x) = _ : None | x : Some; - let plus(x) = [plus]((x : First) . (opt(plus) : Next)); - let star(x) = opt(plus(x)); - match [rec]("a" : Base | "b" . rec : Step);"##, - r##"let opt(x) = _ : None | x : Some; - let plus(x) = [plus]((x : First) . (opt(plus) : Next)); - let star(x) = opt(plus(x)); - let star_(base, step) = [rec](base : Base | step . rec : Step); - let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; - let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; - let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; - match "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";"##, - r##"let opt(x) = _ : None | x : Some; - let plus(x) = [plus]((x : First) . (opt(plus) : Next)); - let star(x) = opt(plus(x)); - let star_(base, step) = [rec](base : Base | step . rec : Step); - let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; - let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; - let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; - let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | - "a" | "b" | "c" | "d" | "e" | "f" | - "A" | "B" | "C" | "D" | "E" | "F" ; - let XID_Start = - "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | - "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | - "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | - "y" | "z" ; - match "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" ;"##, - r##"let opt(x) = _ : None | x : Some; - let plus(x) = [plus]((x : First) . (opt(plus) : Next)); - let star(x) = opt(plus(x)); - let star_(base, step) = [rec](base : Base | step . rec : Step); - let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; - let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; - let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; - let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | - "a" | "b" | "c" | "d" | "e" | "f" | - "A" | "B" | "C" | "D" | "E" | "F" ; - let XID_Start = - "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | - "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | - "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | - "y" | "z" | - "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | - "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | - "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | - "Y" | "Z" ; - let XID_Continue = - XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; - let literal_char = - (" " | "!" | "#" | "$" | "%" | "&" | "'" | - "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | - "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | - "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" | - "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | - "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | - "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | - "X" | "Y" | "Z" | "[" | "]" | "^" | "_" | - "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" ); - match "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" ;"##, - r##"let opt(x) = _ : None | x : Some; - let plus(x) = [plus]((x : First) . (opt(plus) : Next)); - let star(x) = opt(plus(x)); - let star_(base, step) = [rec](base : Base | step . rec : Step); - let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; - let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; - let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; - let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | - "a" | "b" | "c" | "d" | "e" | "f" | - "A" | "B" | "C" | "D" | "E" | "F" ; - let XID_Start = - "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | - "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | - "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | - "y" | "z" | - "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | - "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | - "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | - "Y" | "Z" ; - let XID_Continue = - XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; - let literal_char = - (" " | "!" | "#" | "$" | "%" | "&" | "'" | - "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | - "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | - "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" | - "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | - "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | - "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | - "X" | "Y" | "Z" | "[" | "]" | "^" | "_" | - "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | - "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | - "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | - "x" | "y" | "z" | "{" | "|" | "}" | "~") : Literal | - "\\" . ( - ("\"" | "'" | "n" | "r" | "t" | "\\" | "0") : Ascii | - "x" . oct_digit . hex_digit : Oct | - "u{" .hex_digit - .opt(hex_digit - .opt(hex_digit - .opt(hex_digit - .opt(hex_digit . opt(hex_digit))))) . "}" : Unicode - ) : Escape ; - let ws = plus(Pattern_Whitespace); - let punctuated(x, p) = [rec]((x : First) . (opt(p . opt(ws) . rec) : Next)); - let list(x) = "(" . opt(ws) . [rec]((x : First) . (opt("," . opt(ws) . opt(rec)) : Next)) . ")"; - let epsilon = "_"; - let ident = XID_Start . star(XID_Continue); - let literal = "\"" . (plus(literal_char) : Contents) . "\""; - let parens(expr) = "(" . opt(ws) . (expr : Inner) . ")"; - let fix(expr) = "[" . opt(ws) . (ident : Arg) . opt(ws) . "]" . opt(ws) . (parens(expr) : Inner); - let term(expr) = - epsilon . opt(ws) : Epsilon - | literal . opt(ws) : Literal - | parens(expr) . opt(ws) : Parens - | fix(expr) . opt(ws) : Fix - | ident . opt(ws) . opt(list(expr) . opt(ws)) : CallOrVariable - ; - let label = ":" . opt(ws) . (ident : Label) . opt(ws); - let cat(expr) = punctuated(term(expr), "."); - let alt(expr) = punctuated((cat(expr) : Cat) . (opt(label) : Name), "|"); - let expr = [expr](alt(expr)); - let let = "let" . ws . (ident : Name) . opt(ws) . (opt(list(ident . opt(ws)) . opt(ws)) : Args) . "=" . opt(ws) . (expr : Expr) . ";" . opt(ws); - let goal = "match" . ws . (expr : Expr) . ";" . opt(ws); - match star_(star_(goal : Goal, let : Let), Pattern_Whitespace);"##, -]; - -fn parse_autochomp(input: &str) -> Result<(Vec<Function>, NamedExpression), Box<dyn Error>> { - IterWrapper::new(input.chars()) - .parse::<autochomp::Ast>() - .map_err(|e| Box::new(e) as Box<dyn Error>) - .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box<dyn Error>)) -} - -fn parse_chomp(input: &str) -> Result<(Vec<Function>, NamedExpression), Box<dyn Error>> { - syn::parse_str::<nibble::File>(input) - .map_err(|e| Box::new(e) as Box<dyn Error>) - .and_then(|file| file.convert().map_err(|e| Box::new(e) as Box<dyn Error>)) -} - -fn bench_parse(c: &mut Criterion) { - let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); - let mut group = c.benchmark_group("Parse"); - group.plot_config(plot_config); - for (i, input) in INPUTS.iter().enumerate() { - group.throughput(Throughput::Bytes(input.len() as u64)); - group.bench_with_input(BenchmarkId::new("Chomp", i), *input, |b, i| { - b.iter(|| parse_chomp(i)) - }); - group.bench_with_input(BenchmarkId::new("AutoChomp", i), *input, |b, i| { - b.iter(|| parse_autochomp(i)) - }); - } -} - -criterion_group!(benches, bench_parse); -criterion_main!(benches); diff --git a/autochomp/benches/parse/data/12.nb b/autochomp/benches/parse/data/12.nb new file mode 100644 index 0000000..eaa4670 --- /dev/null +++ b/autochomp/benches/parse/data/12.nb @@ -0,0 +1 @@ +match "ab"; diff --git a/autochomp/benches/parse/data/1548.nb b/autochomp/benches/parse/data/1548.nb new file mode 100644 index 0000000..cabdfe9 --- /dev/null +++ b/autochomp/benches/parse/data/1548.nb @@ -0,0 +1,40 @@ +let bot = !(/rec/ "a" . rec); +let zero = /zero suc/ zero; +let suc n = /zero suc/ suc (n zero suc); + +let opt some = _ : None | some; +let plus iter = !(/plus/ iter . (opt plus)); +let star iter = opt (plus iter); + +let up_to x n = n bot (/rec/ x . opt rec); + +let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; + +let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; +let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; +let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | + "a" | "b" | "c" | "d" | "e" | "f" | + "A" | "B" | "C" | "D" | "E" | "F" ; + +let XID_Start = + "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | + "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | + "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | + "y" | "z" | + "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | + "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | + "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | + "Y" | "Z" ; +let XID_Continue = + XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; + +match + (" " | "!" | "#" | "$" | "%" | "&" | "'" | + "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | + "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | + "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" | + "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | + "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | + "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | + "X"|"Y" + ); diff --git a/autochomp/benches/parse/data/194.nb b/autochomp/benches/parse/data/194.nb new file mode 100644 index 0000000..01730c6 --- /dev/null +++ b/autochomp/benches/parse/data/194.nb @@ -0,0 +1,7 @@ +let bot = !(/rec/ "a" . rec); +let zero = /zero suc/ zero; +let suc n = /zero suc/ suc (n zero suc); + +let opt some = _ : None | some; +let plus iter = !(/plus/ iter . (opt plus)); +match opt "ab"; diff --git a/autochomp/benches/parse/data/24.nb b/autochomp/benches/parse/data/24.nb new file mode 100644 index 0000000..f960c3b --- /dev/null +++ b/autochomp/benches/parse/data/24.nb @@ -0,0 +1 @@ +match !(/rec/ "a".rec); diff --git a/autochomp/benches/parse/data/3096.nb b/autochomp/benches/parse/data/3096.nb new file mode 100644 index 0000000..f90100c --- /dev/null +++ b/autochomp/benches/parse/data/3096.nb @@ -0,0 +1,82 @@ +let bot = !(/rec/ "a" . rec); +let zero = /zero suc/ zero; +let suc n = /zero suc/ suc (n zero suc); + +let opt some = _ : None | some; +let plus iter = !(/plus/ iter . (opt plus)); +let star iter = opt (plus iter); + +let up_to x n = n bot (/rec/ x . opt rec); + +let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; + +let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; +let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; +let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | + "a" | "b" | "c" | "d" | "e" | "f" | + "A" | "B" | "C" | "D" | "E" | "F" ; + +let XID_Start = + "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | + "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | + "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | + "y" | "z" | + "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | + "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | + "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | + "Y" | "Z" ; +let XID_Continue = + XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; + +let literal_char = + (" " | "!" | "#" | "$" | "%" | "&" | "'" | + "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | + "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | + "8" | "9" | ":" | ";" | "<" | "=" | ">" | "?" | + "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | + "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | + "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | + "X" | "Y" | "Z" | "[" | "]" | "^" | "_" | + "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | + "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | + "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | + "x" | "y" | "z" | "{" | "|" | "}" | "~") : Literal | + "\\" . ( + ("\"" | "'" | "n" | "r" | "t" | "\\" | "0") : Ascii | + "x" . oct_digit . hex_digit : Oct | + "u{" . up_to hex_digit (suc (suc (suc (suc (suc (suc zero)))))) . "}" : Unicode + ) : Escape ; + +let ws = plus Pattern_Whitespace; +let ows = opt ws; + +let list inner = !(/list/ inner . opt (ws . opt list)); +let separated inner sep = !(/separated/ inner . opt (sep . ows . separated)); + +let epsilon = "_"; +let ident = XID_Start . star XID_Continue; +let literal = "\"" . (plus literal_char : Contents) . "\""; +let fix term = "!" . ows . term; +let parens expr = "(" . ows . expr . ")"; + +let names = list ident; + +let term expr = !(/term/ + epsilon : Epsilon + | literal : Literal + | parens expr : Parens + | fix term : Fix + | ident : Variable + ); + +let label = ":" . ows . ident . ows; + +let call expr = list (term expr); +let cat expr = separated (call expr) "."; +let alt expr = separated (cat expr . opt label : Labelled) "|"; +let lambda expr = "/" . ows . names . "/" . ows . alt expr; +let expr = !(/expr/ alt expr | lambda expr); +let goal = "match" . ws . expr . ";" . ows; +let let stmt = "let" . ws . names . "=" . ows . expr . ";" . ows . stmt; +let stmt = !(/stmt/ let stmt | goal); +match !(/skip/ Pattern_Whitespace . skip | stmt); diff --git a/autochomp/benches/parse/data/387.nb b/autochomp/benches/parse/data/387.nb new file mode 100644 index 0000000..0f60b89 --- /dev/null +++ b/autochomp/benches/parse/data/387.nb @@ -0,0 +1,13 @@ +let bot = !(/rec/ "a" . rec); +let zero = /zero suc/ zero; +let suc n = /zero suc/ suc (n zero suc); + +let opt some = _ : None | some; +let plus iter = !(/plus/ iter . (opt plus)); +let star iter = opt (plus iter); + +let up_to x n = n bot (/rec/ x . opt rec); + +let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; + +match = "0" |"1"; diff --git a/autochomp/benches/parse/data/48.nb b/autochomp/benches/parse/data/48.nb new file mode 100644 index 0000000..7059bb8 --- /dev/null +++ b/autochomp/benches/parse/data/48.nb @@ -0,0 +1,2 @@ +let bot = !(/rec/ "a" . rec); +match /zero/zero; diff --git a/autochomp/benches/parse/data/774.nb b/autochomp/benches/parse/data/774.nb new file mode 100644 index 0000000..89c22ca --- /dev/null +++ b/autochomp/benches/parse/data/774.nb @@ -0,0 +1,21 @@ +let bot = !(/rec/ "a" . rec); +let zero = /zero suc/ zero; +let suc n = /zero suc/ suc (n zero suc); + +let opt some = _ : None | some; +let plus iter = !(/plus/ iter . (opt plus)); +let star iter = opt (plus iter); + +let up_to x n = n bot (/rec/ x . opt rec); + +let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; + +let oct_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" ; +let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; +let hex_digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | + "a" | "b" | "c" | "d" | "e" | "f" | + "A" | "B" | "C" | "D" | "E" | "F" ; + +match + "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | + "i" | "j" | "k" | "l"; diff --git a/autochomp/benches/parse/data/97.nb b/autochomp/benches/parse/data/97.nb new file mode 100644 index 0000000..d0d00f9 --- /dev/null +++ b/autochomp/benches/parse/data/97.nb @@ -0,0 +1,3 @@ +let bot = !(/rec/ ("a" . rec)); +let zero = /zero suc/ zero; +match (/zero suc/ suc (_ zero suc)); diff --git a/autochomp/benches/parse/main.rs b/autochomp/benches/parse/main.rs new file mode 100644 index 0000000..64fd88a --- /dev/null +++ b/autochomp/benches/parse/main.rs @@ -0,0 +1,64 @@ +use std::error::Error; + +use chewed::{IterWrapper, Parser}; +use chomp::{ + chomp::ast::NamedExpression, + nibble::{ + self, + convert::{Context, Convert}, + }, +}; +use criterion::{ + criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, + Throughput, +}; + +const INPUTS: &[&str] = &[ + include_str!("data/12.nb"), + include_str!("data/24.nb"), + include_str!("data/48.nb"), + include_str!("data/97.nb"), + include_str!("data/194.nb"), + include_str!("data/387.nb"), + include_str!("data/774.nb"), + include_str!("data/1548.nb"), + include_str!("data/3096.nb"), + +]; + +fn parse_autochomp(input: &str) -> Result<NamedExpression, Box<dyn Error>> { + IterWrapper::new(input.chars()) + .parse::<autochomp::Ast>() + .map_err(|e| Box::new(e) as Box<dyn Error>) + .and_then(|ast| { + ast.convert(&mut Context::default()) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) +} + +fn parse_chomp(input: &str) -> Result<NamedExpression, Box<dyn Error>> { + syn::parse_str::<nibble::Statement>(input) + .map_err(|e| Box::new(e) as Box<dyn Error>) + .and_then(|stmt| { + stmt.convert(&mut Context::default()) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) +} + +fn bench_parse(c: &mut Criterion) { + let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); + let mut group = c.benchmark_group("Parse"); + group.plot_config(plot_config); + for (i, input) in INPUTS.iter().enumerate() { + group.throughput(Throughput::Bytes(input.len() as u64)); + group.bench_with_input(BenchmarkId::new("Chomp", i), *input, |b, i| { + b.iter(|| parse_chomp(i)) + }); + group.bench_with_input(BenchmarkId::new("AutoChomp", i), *input, |b, i| { + b.iter(|| parse_autochomp(i)) + }); + } +} + +criterion_group!(benches, bench_parse); +criterion_main!(benches); diff --git a/autochomp/src/lib.rs b/autochomp/src/lib.rs index c795954..2fed0f0 100644 --- a/autochomp/src/lib.rs +++ b/autochomp/src/lib.rs @@ -1,18 +1,25 @@ -use std::convert::TryInto; +use std::{convert::TryInto, mem}; use chomp::{ chomp::{ - ast::{self, Alt, Call, Cat, Fix, Function, NamedExpression, Parameter, Variable}, - Name, + ast::{self, Alt, Call, Cat, Fix, Lambda, Let, Literal, NamedExpression, Variable}, + name::{Content, Name}, }, - nibble::convert::{Binding, Context, Convert, ConvertError}, + nibble::convert::{Context, Convert, ConvertError}, }; +use chomp_macro::nibble; +use proc_macro2::Span; -chomp_macro::nibble! { - let opt(x) = _ : None | x : Some; - let plus(x) = [plus]((x : First) . (opt(plus) : Next)); - let star(x) = opt(plus(x)); - let star_(base, step) = [rec](base : Base | step . rec : Step); +nibble! { + let bot = !(/rec/ "a" . rec); + let zero = /zero suc/ zero; + let suc n = /zero suc/ suc (n zero suc); + + let opt some = _ : None | some; + let plus iter = !(/plus/ iter . (opt plus)); + let star iter = opt (plus iter); + + let up_to x n = n bot (/rec/ x . opt rec); let Pattern_Whitespace = "\t"|"\n"|"\x0B"|"\x0c"|"\r"|" "|"\u{85}"|"\u{200e}"|"\u{200f}"|"\u{2028}"|"\u{2029}"; @@ -25,9 +32,6 @@ chomp_macro::nibble! { let XID_Start = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | - - - "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | @@ -52,96 +56,146 @@ chomp_macro::nibble! { "x" | "y" | "z" | "{" | "|" | "}" | "~") : Literal | "\\" . ( ("\"" | "'" | "n" | "r" | "t" | "\\" | "0") : Ascii | - "x" . oct_digit . hex_digit : Oct | - "u{" .hex_digit - .opt(hex_digit - .opt(hex_digit - .opt(hex_digit - .opt(hex_digit . opt(hex_digit))))) . "}" : Unicode + "x" . oct_digit . hex_digit : Oct | + "u{" . up_to hex_digit (suc (suc (suc (suc (suc (suc zero)))))) . "}" : Unicode ) : Escape ; - let ws = plus(Pattern_Whitespace); + let ws = plus Pattern_Whitespace; + let ows = opt ws; - let punctuated(x, p) = [rec]((x : First) . (opt(p . opt(ws) . rec) : Next)); - let list(x) = "(" . opt(ws) . [rec]((x : First) . (opt("," . opt(ws) . opt(rec)) : Next)) . ")"; + let list inner = !(/list/ inner . opt (ws . opt list)); + let separated inner sep = !(/separated/ inner . opt (sep . ows . separated)); let epsilon = "_"; - let ident = XID_Start . star(XID_Continue); - let literal = "\"" . (plus(literal_char) : Contents) . "\""; - let parens(expr) = "(" . opt(ws) . (expr : Inner) . ")"; - let fix(expr) = "[" . opt(ws) . (ident : Arg) . opt(ws) . "]" . opt(ws) . (parens(expr) : Inner); - - let term(expr) = - epsilon . opt(ws) : Epsilon - | literal . opt(ws) : Literal - | parens(expr) . opt(ws) : Parens - | fix(expr) . opt(ws) : Fix - | ident . opt(ws) . opt(list(expr) . opt(ws)) : CallOrVariable - ; - - let label = ":" . opt(ws) . (ident : Label) . opt(ws); - let cat(expr) = punctuated(term(expr), "."); - let alt(expr) = punctuated((cat(expr) : Cat) . (opt(label) : Name), "|"); - let expr = [expr](alt(expr)); - let let = "let" . ws . (ident : Name) . opt(ws) . (opt(list(ident . opt(ws)) . opt(ws)) : Args) . "=" . opt(ws) . (expr : Expr) . ";" . opt(ws); - let goal = "match" . ws . (expr : Expr) . ";" . opt(ws); - - match star_(star_(goal : Goal, let : Let), Pattern_Whitespace); -} + let ident = XID_Start . star XID_Continue; + let literal = "\"" . (plus literal_char : Contents) . "\""; + let fix term = "!" . ows . term; + let parens expr = "(" . ows . expr . ")"; + + let names = list ident; + + let term expr = !(/term/ + epsilon : Epsilon + | literal : Literal + | parens expr : Parens + | fix term : Fix + | ident : Variable + ); + + let label = ":" . ows . ident . ows; + + let call expr = list (term expr); + let cat expr = separated (call expr) "."; + let alt expr = separated (cat expr . opt label : Labelled) "|"; + let lambda expr = "/" . ows . names . "/" . ows . alt expr; + let expr = !(/expr/ alt expr | lambda expr); + let goal = "match" . ws . expr . ";" . ows; + let let stmt = "let" . ws . names . "=" . ows . expr . ";" . ows . stmt; + let stmt = !(/stmt/ let stmt | goal); + match !(/skip/ Pattern_Whitespace . skip | stmt); +} + +impl Convert for Ast { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + let mut inner = self; -impl Ast { - pub fn convert(self) -> Result<(Vec<Function>, NamedExpression), ConvertError> { - let content = Star2::from(self.0); - let mut names = Vec::new(); - let mut map = Vec::new(); - - let mut iter = content.into_iter(); - - for stmt in &mut iter { - let name: Name = stmt.name1.into(); - let params = Option::from(stmt.args1) - .into_iter() - .flat_map(List2::into_iter) - .map(Name::from); - let mut context = Context::new(&names, params.clone()); - let mut expr = stmt.expr1.convert(&mut context)?; - names.push(name.clone()); - expr.name = Some(name.clone()); - map.push(Function { - name, - params: params.map(Some).collect(), - expr, - span: None, - }); + while let Ast::Branch1(cat) = inner { + inner = *cat.skip1; } - let mut context = Context::new(&names, Vec::new()); - let goal = iter.consume().expr1.convert(&mut context)?; + match inner { + Ast::Branch1(_) => unreachable!(), + Ast::Stmt1(stmt) => stmt.convert(context), + } + } +} - Ok((map, goal)) +impl Convert for Stmt1 { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + match self { + Stmt1::Goal1(goal) => goal.expr1.convert(context), + Stmt1::Let1(stmt) => { + let mut names = stmt.names1.into_iter().peekable(); + let name = Name::new_let(names.next().unwrap()); + let bound = if names.peek().is_none() { + stmt.expr1.convert(context)? + } else { + let args: Vec<Name> = names.map(Name::new_variable).collect(); + let expr = stmt.expr1; + let inner = context.with_variables(args.clone(), |ctx| expr.convert(ctx))?; + NamedExpression { + name: None, + expr: Lambda { + args, + inner: Box::new(inner), + } + .into(), + span: Span::call_site(), + } + }; + context.push_variable(name.clone()); + let body = stmt.stmt1.convert(context)?; + Ok(NamedExpression { + name: None, + expr: Let { + name: name.clone(), + bound: Box::new(NamedExpression { + name: Some(name), + ..bound + }), + body: Box::new(body), + } + .into(), + span: Span::call_site(), + }) + } + } } } impl Convert for Expr1 { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { - let mut iter = self.0.into_iter(); - let first = iter.next().unwrap().convert(context)?; - let rest = iter - .map(|term| Ok((None, term.convert(context)?))) - .collect::<Result<Vec<_>, _>>()?; - - let mut iter = rest.into_iter(); - if let Some((punct, second)) = iter.next() { + match self { + Expr1::Alt1(alt) => alt.convert(context), + Expr1::Lambda1(lambda) => lambda.convert(context), + } + } +} + +impl Convert for Lambda1 { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + let args: Vec<Name> = self.names1.into_iter().map(Name::new_variable).collect(); + let alt = self.alt1; + let inner = context.with_variables(args.clone(), |ctx| alt.convert(ctx))?; + Ok(NamedExpression { + name: None, + expr: Lambda { + args, + inner: Box::new(inner), + } + .into(), + span: Span::call_site(), + }) + } +} + +impl Convert for Alt1 { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + let first = self.labelled1.convert(context)?; + let mut rest = self + .opt1 + .into_iter() + .map(|inner| inner.convert(context).map(|e| (Span::call_site(), e))) + .peekable(); + if rest.peek().is_some() { Ok(NamedExpression { name: None, expr: Alt { first: Box::new(first), - punct, - second: Box::new(second), - rest: iter.collect(), + rest: rest.collect::<Result<_, _>>()?, } .into(), - span: None, + span: Span::call_site(), }) } else { Ok(first) @@ -149,11 +203,14 @@ impl Convert for Expr1 { } } -impl Convert for First1 { +impl Convert for Labelled1 { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { let named = self.cat1.convert(context)?; - let name = Option::from(self.name1).or(named.name); - + let label = match self.opt1 { + Opt15::None1(_) => None, + Opt15::Label1(l) => Some(Name::new_label(l.ident1)), + }; + let name = Name::merge(label, named.name); Ok(NamedExpression { name, expr: named.expr, @@ -164,24 +221,45 @@ impl Convert for First1 { impl Convert for Cat1 { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { - let mut iter = self.into_iter(); - let first = iter.next().unwrap().convert(context)?; - let rest = iter - .map(|term| Ok((None, term.convert(context)?))) - .collect::<Result<Vec<_>, _>>()?; - - let mut iter = rest.into_iter(); - if let Some((punct, second)) = iter.next() { + let first = self.call1.convert(context)?; + let mut rest = self + .opt1 + .into_iter() + .map(|inner| inner.convert(context).map(|e| (Span::call_site(), e))) + .peekable(); + if rest.peek().is_some() { Ok(NamedExpression { name: None, expr: Cat { first: Box::new(first), - punct, - second: Box::new(second), - rest: iter.collect(), + rest: rest.collect::<Result<_, _>>()?, + } + .into(), + span: Span::call_site(), + }) + } else { + Ok(first) + } + } +} + +impl Convert for Call1 { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + let first = self.term1.convert(context)?; + let mut rest = self + .opt1 + .into_iter() + .map(|inner| inner.convert(context)) + .peekable(); + if rest.peek().is_some() { + Ok(NamedExpression { + name: None, + expr: Call { + on: Box::new(first), + args: rest.collect::<Result<_, _>>()?, } .into(), - span: None, + span: Span::call_site(), }) } else { Ok(first) @@ -192,416 +270,215 @@ impl Convert for Cat1 { impl Convert for Term1 { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { match self { - Self::Epsilon1(_) => Ok(NamedExpression { + Term1::Epsilon1(_) => Ok(NamedExpression { name: None, expr: ast::Epsilon.into(), - span: None, + span: Span::call_site(), }), - Self::Literal1(l) => Ok(NamedExpression { + Term1::Literal1(literal) => Ok(NamedExpression { name: None, - expr: l.value().into(), - span: None, + expr: literal.contents1.into_iter().collect::<Literal>().into(), + span: Span::call_site(), }), - Self::Parens1(p) => p.parens1.expr1.convert(context), - Self::Fix1(f) => f.fix1.convert(context), - Self::CallOrVariable1(c) => c.convert(context), + Term1::Parens1(parens) => parens.expr1.convert(context), + Term1::Fix1(fix) => fix.convert(context), + Term1::Variable1(var) => var.convert(context), } } } impl Convert for Fix1 { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { - let arg = self.arg1.into(); - let expr = *self.inner1.expr1; - let inner = context.with_variable(&arg, |context| expr.convert(context))?; - + let inner = self.term1.convert(context)?; Ok(NamedExpression { name: None, expr: Fix { - arg: Some(arg), inner: Box::new(inner), } .into(), - span: None, + span: Span::call_site(), }) } } -impl Convert for CallOrVariable1 { +impl Convert for Variable1 { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { - let name = self.ident1.into(); - - match self.opt2 { - Opt20::None1(_) => { - let binding = context - .lookup(&name) - .ok_or_else(|| ConvertError::UndeclaredName(Box::new(name.clone())))?; - - Ok(match binding { - Binding::Variable(index) => NamedExpression { - name: Some(name), - expr: Variable { index }.into(), - span: None, - }, - Binding::Parameter(index) => NamedExpression { - name: Some(name), - expr: Parameter { index }.into(), - span: None, - }, - Binding::Global => NamedExpression { - name: None, - expr: Call { - name, - args: Vec::new(), - } - .into(), - span: None, - }, - }) - } - Opt20::Some1(s) => { - let args = s - .list1 - .into_iter() - .map(|arg| arg.convert(context)) - .collect::<Result<_, _>>()?; - Ok(NamedExpression { - name: None, - expr: Call { name, args }.into(), - span: None, - }) - } - } - } -} - -impl Literal3 { - pub fn value(self) -> String { - self.literal1 - .contents1 - .into_iter() - .map(LiteralChar1::value) - .collect() - } -} - -impl LiteralChar1 { - pub fn value(self) -> char { - match self { - Self::Literal1(c) => c.into(), - Self::Escape1(e) => e.1.value(), - } - } -} - -impl Alt143 { - pub fn value(self) -> char { - match self { - Self::Ascii1(a) => a.value(), - Self::Oct1(o) => o.value(), - Self::Unicode1(u) => u.value(), - } - } -} - -impl Ascii1 { - pub fn value(self) -> char { - match self { - Self::Branch1(_) => '\"', - Self::Branch2(_) => '\'', - Self::Branch3(_) => '\n', - Self::Branch4(_) => '\r', - Self::Branch5(_) => '\t', - Self::Branch6(_) => '\\', - Self::Branch7(_) => '\0', - } - } -} - -impl Oct1 { - pub fn value(self) -> char { - let s: String = [char::from(self.oct_digit1), char::from(self.hex_digit1)] - .iter() - .collect(); - u32::from_str_radix(&s, 16).unwrap().try_into().unwrap() - } -} - -impl Unicode1 { - pub fn value(self) -> char { - let s: String = [self.hex_digit1.to_string(), self.opt1.to_string()] - .iter() - .map::<&str, _>(|s| s) - .collect(); - u32::from_str_radix(&s, 16).unwrap().try_into().unwrap() - } -} - -impl IntoIterator for Cat1 { - type Item = Term1; + let name = Name::new_variable(self); + let index = context + .lookup(&name) + .ok_or_else(|| ConvertError::UndeclaredName(Box::new(name.clone())))?; - type IntoIter = Cat1Iter; - - fn into_iter(self) -> Self::IntoIter { - Cat1Iter(Some(self)) - } -} - -pub struct Cat1Iter(Option<Cat1>); - -impl Iterator for Cat1Iter { - type Item = Term1; - - fn next(&mut self) -> Option<Self::Item> { - let cat = self.0.take()?.0; - let term = cat.term1; - self.0 = cat.next1.into(); - Some(term) + Ok(NamedExpression { + name: Some(name), + expr: Variable { index }.into(), + span: Span::call_site(), + }) } } -impl IntoIterator for Contents1 { - type Item = LiteralChar1; +impl IntoIterator for Names1 { + type Item = Ident1; - type IntoIter = Contents1Iter; + type IntoIter = Opt3; fn into_iter(self) -> Self::IntoIter { - Contents1Iter(Some(self)) + Opt3::List1(Box::new(self)) } } -pub struct Contents1Iter(Option<Contents1>); - -impl Iterator for Contents1Iter { - type Item = LiteralChar1; +impl Iterator for Opt3 { + type Item = Ident1; fn next(&mut self) -> Option<Self::Item> { - let cat = self.0.take()?.0; - let lit = cat.literal_char1; - self.0 = cat.next1.into(); - Some(lit) - } -} - -impl IntoIterator for List1 { - type Item = Expr1; - - type IntoIter = Fix192Iter; - - fn into_iter(self) -> Self::IntoIter { - Fix192Iter(Some(self.part3)) + let orig = mem::replace(self, Opt3::None1(Epsilon)); + match orig { + Opt3::None1(_) => None, + Opt3::List1(names) => { + if let Opt4::Some1(some) = names.opt1 { + *self = some.opt1; + } + Some(names.ident1) + } + } } } -pub struct Fix192Iter(Option<Fix192>); - -impl Iterator for Fix192Iter { - type Item = Expr1; +impl Iterator for Opt16 { + type Item = Labelled1; fn next(&mut self) -> Option<Self::Item> { - let cat = self.0.take()?.0; - let expr = *cat.expr1; - self.0 = cat.next1.into(); - Some(expr) - } -} - -impl IntoIterator for Star2 { - type Item = Let1; - - type IntoIter = Star2Iter; - - fn into_iter(self) -> Self::IntoIter { - Star2Iter(Some(self)) - } -} - -pub struct Star2Iter(Option<Star2>); - -impl Star2Iter { - pub fn consume(self) -> Goal1 { - let mut star = self.0.unwrap(); - - loop { - match star.0 { - Alt274::Step1(step) => star = *step.rec1, - Alt274::Goal1(goal) => return goal, + let orig = mem::replace(self, Opt16::None1(Epsilon)); + match orig { + Opt16::None1(_) => None, + Opt16::Some1(some) => { + *self = some.separated1.opt1; + Some(some.separated1.labelled1) } } } } -impl Iterator for Star2Iter { - type Item = Let1; +impl Iterator for Opt14 { + type Item = Call1; fn next(&mut self) -> Option<Self::Item> { - let star = self.0.take().unwrap(); - - // You can probably be safer about this and use `mem::swap` or similar. - // I cannot think of a way how, so this will do. - if let Alt274::Step1(step) = star.0 { - let stmt = step.let1; - self.0 = Some(*step.rec1); - Some(stmt) - } else { - self.0 = Some(star); - None + let orig = mem::replace(self, Opt14::None1(Epsilon)); + match orig { + Opt14::None1(_) => None, + Opt14::Some1(some) => { + *self = some.separated1.opt1; + Some(some.separated1.call1) + } } } } -impl IntoIterator for Alt1 { - type Item = First1; - - type IntoIter = Alt1Iter; - - fn into_iter(self) -> Self::IntoIter { - Alt1Iter(Some(self)) - } -} - -#[derive(Clone)] -pub struct Alt1Iter(Option<Alt1>); - -impl Iterator for Alt1Iter { - type Item = First1; +impl Iterator for Opt13 { + type Item = Term1; fn next(&mut self) -> Option<Self::Item> { - let cat = self.0.take()?.0; - let first = cat.first1; - self.0 = cat.next1.into(); - Some(first) + let orig = mem::replace(self, Opt13::None1(Epsilon)); + match orig { + Opt13::None1(_) => None, + Opt13::Some1(some) => match some.opt1 { + Opt12::None1(_) => None, + Opt12::List1(call) => { + *self = call.opt1; + Some(call.term1) + } + }, + } } } -impl IntoIterator for List2 { - type Item = Ident2; +impl IntoIterator for Contents1 { + type Item = char; - type IntoIter = Fix246Iter; + type IntoIter = Opt11; fn into_iter(self) -> Self::IntoIter { - Fix246Iter(Some(self.part3)) + Opt11::Plus1(Box::new(self)) } } -#[derive(Clone)] -pub struct Fix246Iter(Option<Fix246>); - -impl Iterator for Fix246Iter { - type Item = Ident2; +impl Iterator for Opt11 { + type Item = char; fn next(&mut self) -> Option<Self::Item> { - let cat = self.0.take()?.0; - let expr = cat.first1.ident1; - self.0 = cat.next1.into(); - Some(expr) - } -} - -impl From<Next6> for Option<Alt1> { - fn from(o: Next6) -> Self { - match o { - Next6::None1(_) => None, - Next6::Some1(s) => Some(*s.rec1), - } - } -} - -impl From<Args1> for Option<List2> { - fn from(o: Args1) -> Self { - match o { - Args1::None1(_) => None, - Args1::Some1(s) => Some(s.list1), + let orig = mem::replace(self, Opt11::None1(Epsilon)); + match orig { + Opt11::None1(_) => None, + Opt11::Plus1(contents) => { + *self = contents.opt1; + Some(contents.literal_char1.into()) + } } } } -impl From<Next2> for Option<Contents1> { - fn from(o: Next2) -> Self { - match o { - Next2::None1(_) => None, - Next2::Plus1(s) => Some(*s), +impl From<LiteralChar1> for char { + fn from(c: LiteralChar1) -> Self { + match c { + LiteralChar1::Literal1(c) => c.into(), + LiteralChar1::Escape1(e) => e.into(), } } } -impl From<Next4> for Option<Fix192> { - fn from(o: Next4) -> Self { - match o { - Next4::None1(_) => None, - Next4::Some1(s) => match s.opt2 { - Opt18::None1(_) => None, - Opt18::Rec1(e) => Some(*e), - }, +impl From<Escape1> for char { + fn from(e: Escape1) -> Self { + match e.1 { + Alt171::Ascii1(a) => a.escape(), + Alt171::Oct1(o) => o.into(), + Alt171::Unicode1(u) => u.into(), } } } -impl From<Next5> for Option<Cat1> { - fn from(o: Next5) -> Self { - match o { - Next5::None1(_) => None, - Next5::Some1(s) => Some(*s.rec1) +impl Ascii1 { + fn escape(self) -> char { + match self { + Ascii1::Branch1(_) => '\"', + Ascii1::Branch2(_) => '\'', + Ascii1::Branch3(_) => '\n', + Ascii1::Branch4(_) => '\r', + Ascii1::Branch5(_) => '\t', + Ascii1::Branch6(_) => '\\', + Ascii1::Branch7(_) => '\0', } } } -impl From<Next7> for Option<Fix246> { - fn from(o: Next7) -> Self { - match o { - Next7::None1(_) => None, - Next7::Some1(s) => match s.opt2 { - Opt30::None1(_) => None, - Opt30::Rec1(e) => Some(*e), - }, - } +impl From<Oct1> for char { + fn from(o: Oct1) -> Self { + let s: String = [char::from(o.oct_digit1), char::from(o.hex_digit1)] + .iter() + .collect(); + u32::from_str_radix(&s, 16).unwrap().try_into().unwrap() } } -impl From<Name1> for Option<Name> { - fn from(o: Name1) -> Self { - match o { - Name1::None1(_) => None, - Name1::Label1(l) => Some(l.label1.to_string().into()), - } +impl From<Unicode1> for char { + fn from(u: Unicode1) -> Self { + let s = u.up_to1.to_string(); + u32::from_str_radix(&s, 16).unwrap().try_into().unwrap() } } -impl From<Name2> for Name { - fn from(i: Name2) -> Self { +impl From<Variable1> for Content { + fn from(i: Variable1) -> Self { i.to_string().into() } } -impl From<Arg1> for Name { - fn from(i: Arg1) -> Self { +impl From<Ident2> for Content { + fn from(i: Ident2) -> Self { i.to_string().into() } } -impl From<Ident1> for Name { +impl From<Ident1> for Content { fn from(i: Ident1) -> Self { i.to_string().into() } } - -impl From<Ident2> for Name { - fn from(i: Ident2) -> Self { - i.to_string().into() - } -} - - -impl From<Alt277> for Star2 { - fn from(mut a: Alt277) -> Self { - while let Alt277::Step1(step) = a { - a = (*step.rec1).0; - } - - if let Alt277::Star1(s) = a { - s - } else { - unreachable!() - } - } -} diff --git a/autochomp/src/main.rs b/autochomp/src/main.rs index cbc0646..d8a78e1 100644 --- a/autochomp/src/main.rs +++ b/autochomp/src/main.rs @@ -7,7 +7,7 @@ use std::{ use chewed::{IterWrapper, Parser}; use chomp::{ chomp::{ - ast::substitute::InlineCalls, + ast::substitute::Reduce, typed::{ context::Context, lower::{Backend, GenerateCode}, @@ -16,7 +16,9 @@ use chomp::{ visit::Visitable, }, lower::RustBackend, + nibble::convert::{self, Convert}, }; +use proc_macro2::Span; fn main() { let mut input = String::new(); @@ -28,12 +30,12 @@ fn main() { .parse::<autochomp::Ast>() .map_err(|e| Box::new(e) as Box<dyn Error>) }) - .and_then(|ast| ast.convert().map_err(|e| Box::new(e) as Box<dyn Error>)) - .and_then(|(funs, goal)| { - funs.into_iter() - .try_rfold(goal, |goal, function| { - goal.fold(&mut InlineCalls { function }) - }) + .and_then(|ast| { + ast.convert(&mut convert::Context::default()) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) + .and_then(|expr| { + expr.fold(&mut Reduce) .map_err(|e| Box::new(e) as Box<dyn Error>) }) .and_then(|term| { @@ -46,7 +48,7 @@ fn main() { .map(|typed| { let mut backend = RustBackend::default(); let id = typed.gen(&mut backend); - backend.emit_code(None, None, id) + backend.emit_code(None, Span::call_site(), id) }) .and_then(|code| { write!(io::stdout(), "{:#}", code).map_err(|e| Box::new(e) as Box<dyn Error>) diff --git a/autochomp/tests/compare/main.rs b/autochomp/tests/compare/main.rs index 681014a..112f642 100644 --- a/autochomp/tests/compare/main.rs +++ b/autochomp/tests/compare/main.rs @@ -1,26 +1,39 @@ use chewed::{IterWrapper, Parser}; -use chomp::{chomp::ast::{Function, NamedExpression}, nibble}; +use chomp::{ + chomp::ast::NamedExpression, + nibble::{ + self, + convert::{Context, Convert}, + }, +}; -fn chomp(input: &str) -> (Vec<Function>, NamedExpression) { - syn::parse_str::<nibble::File>(&input).unwrap().convert().unwrap() +fn chomp(input: &str) -> NamedExpression { + syn::parse_str::<nibble::Statement>(&input) + .unwrap() + .convert(&mut Context::default()) + .unwrap() } -fn autonibble(input: &str) -> (Vec<Function>, NamedExpression) { - IterWrapper::new(input.chars()).parse::<autochomp::Ast>().unwrap().convert().unwrap() +fn autonibble(input: &str) -> NamedExpression { + IterWrapper::new(input.chars()) + .parse::<autochomp::Ast>() + .unwrap() + .convert(&mut Context::default()) + .unwrap() } macro_rules! compare { - ($name:ident, $file:literal) => { - #[test] + ($name:ident, $file:literal) => { + #[test] fn $name() { let input = include_str!($file); assert_eq!(chomp(input), autonibble(input)) } - }; + }; } -compare!(compare_sheep, "sheep.nb"); -compare!(compare_ratata, "ratata.nb"); -compare!(compare_regex, "regex.nb"); -compare!(compare_regex_fix, "regex_fix.nb"); -compare!(compare_nibble, "nibble_exp.nb"); +compare!(compare_sheep, "nibble/sheep.nb"); +compare!(compare_ratata, "nibble/ratata.nb"); +compare!(compare_regex, "nibble/regex.nb"); +compare!(compare_regex_fix, "nibble/regex_fix.nb"); +compare!(compare_nibble, "nibble/nibble_exp.nb"); diff --git a/autochomp/tests/compare/nibble b/autochomp/tests/compare/nibble new file mode 120000 index 0000000..bfe7e8e --- /dev/null +++ b/autochomp/tests/compare/nibble @@ -0,0 +1 @@ +../../../tests/full/nibble
\ No newline at end of file diff --git a/autochomp/tests/compare/nibble_exp.nb b/autochomp/tests/compare/nibble_exp.nb deleted file mode 100644 index 6e6d8b5..0000000 --- a/autochomp/tests/compare/nibble_exp.nb +++ /dev/null @@ -1,44 +0,0 @@ -let opt(x) = _ | x; -let plus(x) = [plus](x . opt(plus)); -let star(x) = [star](opt(x . star)); - -let Pattern_Whitespace = "\n"|" "; - -let XID_Start = - "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | - "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | - "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | - "y" | "z" | - "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | - "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | - "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | - "Y" | "Z" ; -let XID_Continue = - XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; - -let literal_char = XID_Continue; - -let ws = star(Pattern_Whitespace); -let must_ws = plus(Pattern_Whitespace); - -let punctuated(x, p) = [rec](x . opt(p . ws . rec)); -let list(x) = "(" . ws . [rec](x . opt("," . ws . opt(rec))) . ")"; - -let epsilon = "_"; -let ident = XID_Start . star(XID_Continue); -let literal = "\"" . plus(literal_char) . "\""; -let parens(expr) = "(" . ws . expr . ")"; -let fix(expr) = "[" . ws . ident . ws . "]" . ws . parens(expr); - -let term(expr) = - epsilon . ws - | literal . ws - | parens(expr) . ws - | fix(expr) . ws - | ident . ws . opt(list(expr) . ws) - ; - -let cat(expr) = punctuated(term(expr), "."); -let alt(expr) = punctuated(cat(expr), "|"); -let expr = [expr](alt(expr)); -match expr;
\ No newline at end of file diff --git a/autochomp/tests/compare/ratata.nb b/autochomp/tests/compare/ratata.nb deleted file mode 100644 index 2cf7cd9..0000000 --- a/autochomp/tests/compare/ratata.nb +++ /dev/null @@ -1,3 +0,0 @@ -let opt(x) = _ | x; -let plus(x) = [rec](x . opt(rec)); -match plus(("r" | "t") . "a"); diff --git a/autochomp/tests/compare/regex.nb b/autochomp/tests/compare/regex.nb deleted file mode 100644 index ad37f3b..0000000 --- a/autochomp/tests/compare/regex.nb +++ /dev/null @@ -1,5 +0,0 @@ -let opt(x) = _ | x; -let plus(x) = [plus](x . opt(plus)); -let star(x) = [star](opt(x . star)); - -match plus("a") . star("b"); diff --git a/autochomp/tests/compare/regex_fix.nb b/autochomp/tests/compare/regex_fix.nb deleted file mode 100644 index 5b7533c..0000000 --- a/autochomp/tests/compare/regex_fix.nb +++ /dev/null @@ -1,4 +0,0 @@ -let opt(x) = _ | x; -let ws = [star](opt(" " . star)); - -match [rec]("a" . opt("." . ws . rec)); diff --git a/autochomp/tests/compare/sheep.nb b/autochomp/tests/compare/sheep.nb deleted file mode 100644 index 1016fec..0000000 --- a/autochomp/tests/compare/sheep.nb +++ /dev/null @@ -1,3 +0,0 @@ -let opt(x) = _ | x; -let plus(x) = [rec](x . opt(rec)); -match "ba" . plus("a"); diff --git a/chomp-bench/benches/arith.rs b/chomp-bench/benches/arith.rs deleted file mode 100644 index f5ca735..0000000 --- a/chomp-bench/benches/arith.rs +++ /dev/null @@ -1,55 +0,0 @@ -use chewed::{IterWrapper, Parser}; -use chomp_bench::arith::*; -use criterion::{ - criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, - Throughput, -}; - -const INPUTS: &[&str] = &[ - r#"(20271 / (22939 / 15971 * 552 / 11046 + -24515 * (4540 - 11399 - -28093 * -10078 / (-29566 * 26980) + 19390) / -5419 + 28124 * 18839))"#, - r#"(-29901 / 30119 * -8463 * 23900 / 31397 - -13633 * 12636 * 19514 + 18527 * -16089 / 11503 / (27237 / -24154 - 20469) + (-32450 - 11210 + -10920 - -25496) - -23339 - -2386 + -2369 * 30331 - 29375 / -12690 * 28378 / 14623 * -24876 / 20642 - -13525 * 23573) * -5233"#, - r#"(-5484 + -23384 / -3161 + -1805 / -6004 - (-21715 + (-17356 + 2879 + 27860) / -20820 + 5682 + (-17408) + -21260 - 16358 - 18313 - 5048 + -12706 - -23282 + -26554 / 29632 / 9642 / 5996 * 1932 / -31535 + -32754 / -8790 - 27069 + 19436 * -2950) * 29752 / (16375) + -31464 / -21004 * 32160 / -20038 - 23328 - 26015 + 18631 - 9077 / 13306 - 26883 - 15513 - (((-28818) / 26778) + 18091 * -1042 + 28644 / 6517) / 29645 - -29958 + 7762 / -14898 - -22849 + -10827 * -227 * -4135 - 6441 - ((8618) + -16510 * (27909 - 3712 - 27794)) + -9878 + (3237) * 13258 - -11441)"#, - r#"-3702 / -6527 * (21650 - 30878 / -16053) * ((-27738) + -10405 / (28028) + -27946 * 11853 / 9995 * (12242 / 19864 + -3983 / -17383 / 24277 + (-25049 * 3811)) * (7738 / -30356 - (15771 + -24122 + 20235) - -1286 * -14431 * 20212 + -9632 / ((4912) / 25444 - 29835 + -1371 + 1684 * -16178 * -3620) * 1965 + -26188 + -25529 / (-31105 / -15380 / ((5700 + 20005 + -2884 - 25243 + -22469 - 5923 / 31855 + 631 + -30564 / 15911 / 2145 / 23146 - 10595) / -16740 / -31327 - -30899 * (27984 / 3269 + -23191 - -28688 * 8627 / 1124 * 25978) * 29991 * -11660 * (43 - 13615 + -14069 * 1794 / -23857 / ((-27289 / 8473 * 13714 * -17557 / -28653 / 15220 / (-20965 * 16822 / 18335 / 30505 * (-29766 / 27525 - 26431) + -1597 / 26109 * ((18233) - 15258 * -1222 + 13992) * -22684 - (32150 * 16543)) / -14948) + 1) / -5206 - -20944 * -10476 - 3481) + -18244 - -21630) * 3726 - -11142 * 3294 + 32359 + 1556 / -6674 * -707 - 16822 * -1006 + -3503)) * 7863 * 7347 * -22972 - ((-12006 + 8695 / -12530 + -14941 * 3203 - (-12244 * 1257 * -27925 + -2966 * -30371 + -22680) - 30152))) / -11978 / -210"#, - r#"(29413 / -10366 / -27050 + -19544 * -12857 + 1657 - 6429 - 1575 / -18805 * (6236 / -4864 + 5328 / (-28766 - -23344 / 1897 - -10264 - -15545 / -22321 / -26281 + -6283 - -32498 + (((-18270) + 24059 + 18757 * -13046 + 410) - 5087 - 16845) + -13501 - -11165 / 10931 - -12920 - 19771 + 31512 / 27430 + 29179 * -5425 / 8472 - 24814 / -6239 * 18302 * 27551 * -14128) * 30808 + -27780 + (-7080 - 24343 + -13633 / -2952 - 19589 + -2432 - 418) - -18630 * (28453 - -23142 + -25301 * 10469 / 21805 + (6705 + -20941) / 12166 * 25067 * -5523 * 1712 / -26749 / 1014 / -2801 * (26069 - 3978 + -4487 / 14353 + -28970 + 17036 * 9916 + -19436 - 21081 / -26225 / 17558 + 9519 * -1431 + 16650 / -10868 * 13316 / 6423 * 2702 + 14993 / 17300 / 26043 / -23097 - 32561 + -24417 * (-17770 - (13434 / -3495 * -19723) - 23871 - (29314)) / 2068 + -27149 * 28478 / -15589 / 22911 + 17746 + -1779 + 32657 / -32373 / 3077 * 15619 / -22630 * -4937 + 9998 / 10994 / -17860 * 14003 / -13166 / -4922)) - -1283 / (1986 * -22161 + 14898 * -3210 / -5045 - 29713 + (19077 - -8307) * -9969 * (-32136 + 28190 / -27538 / -12829 / 9739 * -24631 / -23424 / ((-11618 / (-20080 + -6697 * 13340 - 20386 + 4134 + -18209 + -4881 * -17637 + 7447 * 26973) * -18860) + 1)) / 13606 / (-9977 + -15895 / -30099 / -9410 / -18342 + -4456 + -14061) / -13146 / -25199 - -3110 + 672 * -22419 - -7711 + -13525 - -20730 * (-4259) + 31080 / 22839 + 8319 * (24326 - -28097 * 16074 / 4717 * -32149 * -20741 / (-14546 * (8702 + -14407 / -25071 * 15880 / -17212 * 30943) * -3731 - 28713 + 26127 / -28857 + 12082 + -12964 - -31922) * -12295 + -26824 + (-31061 - -18340) / 25139 - 28096 * 6898 / -29952) + -29845 + -4715 * -29119 - 4858 * -23651 + -1729 * 30872 / 29958 - 5497 * -20518 - 32756 + 3926 / -16980 * -2792 * -17122 + 4842 + -2418 * -2054 * -26420 / ((((15194 - 32629) / -20992 / 15881) * 15405 * -29571) + (-4077) / -27110 * 32297 + 2769 + -13517) + 2643 - 23230 - -5387 - 8726 - -26587 + -22494 + 24391 - 7508 * 10021 + -4357 - 22113 / 26035 * -24269 - -10567 - 24820 - 3097 - -19770 * -17076 - -27736 + 29088) / -28509 * -11910 * 28826 + 32570 * 19325 * 4727) * 1722 / 26883 + (-27628 + -26187) * 11802 / 24563 + 5033 + -15146 + -27513)"#, - r#"(12979 + (298 - 26481 * ((5923 - 6726 + 19168 / -25914 * 13914 * 23609) - -26903 + 3276 + -19404 - 1703 / -25235) / -17437 / (-2842) + -18818 + -16243 / 27336 - 27685 + (-18865 * (-18480 - -17478 - -9375 - 3372 + ((-24167 * -3007 / 5464 + -2137 * 4221 / (-15020 - 10776 + (32357 + 473 - 10821 - -2703 / 4115 / -23982 + -31973 * -30998 * (24811 - -4678 - 28662 + 10412 - -4113 - -3262 - 15999 * 3211 / -3020 * -6464) / 19146 / -4619 - (10771 / 11031 - -25649 - -7294) + (24054 * -12149 / 16568 * -12166 - -26474 - 4943 - 22824) - -22765) - -25755 * -11499 / (18888 - -14928 + 16058 * -4315 + -13126 / 25068 * (32626 + 17867 - 15824 * -1774 + ((-15480 / 19091 * -30564 + -17240) / -9200 / 29188 * -29786 / ((-982) + 14073 + -5634 + -7815 + 29947 / 10520 + 2927 * -8309) / -19134 * (-22986 / 15655 * 29077 * 23443 * 1825 / 23225 - 6852 - 15002 * -23685 - 32055 - 30674 / 986 + -6494) - -17414 * 31020 - (32479 / -28036 * 28599 * (28017 + 29925 - -165) * 28625 + -26315 - -31881 - 21934 + -21972 / (10646 - 26483 / -16697 * 24089 + 11495 - 6621 / -15025 - 2264) * (22670 * (-23759 + -11209 + 32324 + 28251 * 29072 / 11025 + -14724 * 31395 / (27313 / 4137 - 24327 / -30597 * 32152 - -13938 * 27773 / -26771 * ((-27219) / -22901) * -16091 + 5628) + 5655 * -3423 / -30790 * -29574 * 5658 * -24322) * 29173 + 19653 * 9820 - -10342 + 11260 / ((20087 * 29479 - 25646 + -14298)) - 10248) + -4591 - 14790 - 22636 - (19020 / -19470 + -4446 * 7130 - 2792 / 26197 * 4808 / 17490 - (-24149 / 19555 + -26628 + -30998 * -294)) / -7222) * 25697) - 25234) - ((11214 - -31564 + -10569 * (-4725) + (458 - 6879) - -9642 * 9799 / 26368 + 15916 * (-20414 / 5890 + 18922 * -9200 - 9208 * -8747 * (-9368 * -11378 / -7692 * 29902 * 29046 / -16717 + -26066 - 18115 + -18655 * 31486 * 20675 * 5649 - -8691) * 18040 + -19577 * ((-19713 + 10607 * ((9940 + -22331 / -7784 - -7728) * -31226 - -25168 - -26834) - -30717 - -21378 / -15243) + 22146) + -12430 - 30571 / (14939 * 24736)) - 23495 + -32181) / (11070 - -18373 * -20704 / 27354 - -14691 / -5124 * 138 * (9555 + -1883 - -28082 + -16267) / 11533 * -9131 - -22290 / -21173) - 8241 * -22064) - -20958 * -27858 * ((((465 * -26923 - -6191 - 32129 / -1975 + -11590 / 13945 / -10407 / 5364 - -15271 + -25231 + -26030 + 149 * 27863 * 24846 - 10876 * -4830) + 11095 - 14985 - 14794 * -7514 / -18341 + 15650 + (-17855) * 5609 + -14090 - 15229 / -6822 * 8778 / -26898 - 23536 + 9570 * -10457 + 30425 / (7749 * -942) * 872 - -4219 - -12045 + -22119 + -26592 - (3684 * 30521) / -30462 * -7894 + -13625 / 31285 * 11306 / -1579 * 27867 * 25023 * 27415)) * 7677 * (4351 / 1900) - -6939 * -23160)) / 16987 + -6719 / -23373 / (2642) * 28444 + -19212 * -11699 - 27354 / 32706 - -11474 * -10886) + -4212 - (29297 * 23971 / -7597) + -1913 + -24005 / -14712 * 18366 * -12986 / -13173 * (18126 + -23610 * -20339 * 32318 - 14749 * 19735 + -10451 / -27794 - 23756 / 2209 - 6534 * -2505) - 7498 / 8931) - 22490 + 10622 - 7610 * (-17030 * -21501 * (-11016 - 1621 * (-18097) - 12156 + 6527 - -4665 - -17944 * 29826 / -25521 / 29923)) + -29062 * (-3788 / -1915 + (-12670) - 5482 / 7055 + -3398 * (-10656 - 653) * 10720 * 19085 + 20268 * -10871 * 20253 * 15558) / 29909 + 20958 / -19165 * -22428 + 10859 * -5280 / -14587 - (6866 - 18222 / -29698 - 15291 - 14540 - -29608 * -29165 + 14193 / (-28121 + -4893 / 19775 - 10147 * (5616 * -23200) * 3640 * 1237 * -13558 * -1763 + (-8178) / 11790 + (17429 - 21854 * -3927 / 23656 + 12348 * 5137 / 14309 * -18488 * 13020) - 10561) / 29765 + -13417 * 2810 + (-28366 / 29629 - (14959 / 18167 * 286 - 18116 + 7058 - 10855 + 4562 * 11602 / 23425) - -2778 * -14207 / 3758 / -11312 * 6178 - ((8997 * 11541)) / -5691 * -31585 - (-24515 / (-30755) + -7348 + 27659) + -15052) / -7756 * -26870 / -2390 + 1451 / -4749 - 21657 + 30323 - 3963 / -27057 - ((9329 * -161 + -24823 + 4302 + (-28999 / 28055 * -30801 * -21663 / -31240 / -8237 * -19504 - -25665 * 14154 - -23326 / -3055 * -19901) + 8918 - -28896 / -16208 + -22354 / 22638 - 3948 * 25715 - -14005 + 1308 * 30051 * 32473 / -26979 - -25371 / 6007) / 9961 * -29370 / -22262 * 16101 / (-15091) + -14525 - 1190 / -18352 * 23841 * 21697) - 10379 - 19122 - -16478 - -24285 * ((19493 / 11580 * -32162 / 21522 - -7116 * 31276 - 17760 / -1269) + 17912 - -31889 / -2570) + 11872 - 29767) + -3577 * -25613) + -28246 / -25575 - 21962 + 20271) * 20671 + -12290 * 13347) * -32599) + 17055 - 14648 * -32470)"#, - r#"(28462 * -19651 / 14247 * (-22278 + 31250 + -29638 - 20753 + 10762 / 23112) * -14880 / 1803 * 18420 + (6655 * 29648 * -16937 + (-19159) * (-16866 + 25053 / 13685 + (-21958 + ((-8545 - -29613 + (-29393 * 21756) / (-15243 - -14766 + 401) * (-4207 + -19496 / (12759 / (22387 * 27329 / -4872) + -3266 - -7146))) + (-28530 / 31456 - -11453 + (-3203 * 19331 * 11378) - -4934) / -26221 * 7444 - -9611 - 2548 / (-4291) * (19939 - 17652 * -18490 - 15995 + 4129 + -25847)) * 26035 / -19909 * 21891 * -29365 - 12112) * 19406 * (16237 / -27233 + -18666) + 6023 * 12428 + -8146) * (-26919 / 5986 - -23079 + -17427 + 26955 / 25529 - -3493 / -19973 / -5188 * -178 * 12666 - 10876 - -1104 - -16470 - 7404 * 16638 / 7795) * 32620 * 4219 + -12201 * -25468 / -10335 * -26289 * 22428 * 17147 * 28204 + -15740 + 27963 / -1834 * 15208 + -20840 + -8853 / 23186 * 7171 * -21657 + -20720 - 9329 * (-26887 * 22084 - -12873 + 14025 * 9647 / (6956 * 14729 - -13212 / -25456 - 9886 * -21250 / -32208 * 12626 + 20415 - ((-18900 + 8569 - 1942 * -32150 + 31472 - 8534 + 21717 / 23736 + -8792 * -14601 * 12316 / -26682 * -30443 + (-8043 + 27691) + -32371 * (-5165 - -12477 + 3784 * 9705 + 24978 - 10177 + -17478) - -7147) / 30314 - -24951 + 10044 / -9919 / -13876 + 5888 / -28922 / (((((-26902 + -19740 * -24995) + 13186) * -7154 / 30316) / (-24064 - -20599 + 21904 * -7256 * (-24952 * -22194 / -11802 * (-21696 * -20290 * 21468 * -26168 * -12670 / 18807) - -18314 - 23253 * -11039 + 12155 * 28824 * 25373) + -11994 / 24611 + 21380 + 3066 - -9185 + 32075 * 26763)) + 1) + 13061 + 2497 + 10266 - -14752 / (-12724 / -18497 * 3560 - (2570 * -32489 + (-17883 * 15731 + -148 - 6593 * -19281 * 30045 / (15485 + 13293 - 7376)))) / -8664 / -1924) / -27667 * 15227 * 9103 - 1680 + -6672 - -30674 / (5082) - 107 - -11851 - -23245 / 2878 * 23651 * 10331 * -25412 * (-4459 + -24946 / -12944 / -25999 / -9036 / 26759 / -26419 - (-17456 - -24842 / 15026 - -19527 * (-24341 + -7206 / -11939 * -6351 + 3295 * (8699 / 3412 * -24409) / 15346 + -25676 - -9769 * (1572) + -20114 + -3716 + -21737 + -26454 / -26739 * 13205 - 879 - -20534 + -379 * -16468 + 4484 / 29022 * 15923 * -32022 + -4182) - 5414 * 18687 * (12500 + -11723 + (8288 / -3582 - -17302 * 23659 - 9002 * -4682 * -17414 / -30736 + -4073 + (-31141 / -5598 - 2150 + (28506 - -2484 - -7130 * -15410 / 28934 - -18383 / 10809 * 9650 / -22147 * -32006 * (-16674 * 23473) * 7100 - -23655 / 9090) / -28516 * 8471 + (3694 * -4919 / (-20655 + -5183 * 16791 + 19881) / (18140 + -26423 * 16806 - -22668 + 1777 / 21754 + -18878) * -6449 - 14936 * (-24531 / -10600) - -14260 / 28127 * 1095 - 14801 - 15039 * -31901 + -13969))) + 13278 / (8779 * 15547 - (23721 / -9873 / -30249 + -27235 + -3544 / 11662 + -8432 + 19145 - 27139) * (6015 / -16724 / -12829 * (26219 - -14395 + 28730 + -13143 - 5090 + 31404 - (-27231 * 10096) * -10098 * 19477 * 10445 * -28760 * -13340 / 15930 / 21714 + -17955 + 9378 * 16735 / -6281 + ((8100 / ((-17190 / -17949 + 4195 / -6935) + 1) / -16276) * 22775 + 29745 / 25889 * -14752 * 4104 / 4356) / 29073 * -16027 * -24395) * -7582) + 23766 - -25543 - (-30710 - 27673 * 14662 / -8878) - 9033 * -23921 * -29245 * 22642) / 20640) * -9821 + (9658) * -22591 * 7039 - 16308) / 3753 - -5640 * 6706 * 3420 / (-12651 - 29070 / 7389 / -416) * -24146 + (24212 / -7269 - -15208 / (32374 + 3650 - 10270 - 13418 - -31936 - 4969 + 5789 + -14896 * 1016 * -30805 + -32114 - 9443 / -3861 - 10760 * 16873 * 9567 * -22575 / 3484 / 9264) * 4807 / -19576) * 2130 + 19164 / -13610 + (12094 + 20212 / -10778 * 17763 / 15774 + 14254 * 31964 + 6091 / 5415 * 23144 / 29713 - -190 / -16128 * 23355 + 1331 - 27410 * -8901 - 27400 * -31355 + (17858 + -3190 + (-28964 / 18078 / -22396 + 12658 + 20360 + 22201 - (8492) * 14591 / (-31717 - 17009 * 18308 - 4910 * -23924 + 15675 * 3266 / -19555 - -20738) * 4645 * -3003 - (-23343 * (-4959 * (-4007 + -26454 - 29358 + 32346) / -21456 + -13990 + 11037 / -30702 * 1255 - 17499 / ((-27881 / 273 / (1328 + 14728 * -24734 / -19357 / 17496 + 32493) * -30769 * -1881 / -22200) + 1) * -5573 - (3732)) - 23892 / -31091 / -19865 - 18541 + -3308 * -31674 - 21768 / 21992 * (-2490 + -11642)) - 32226 / 5733 - -1842) / ((-4402 + (31243 + 20545 * -18947 * 15553 - 32185 - -15544 + 25570 / ((8209) / -31126 + 21064 + (-28673) + 25436 - 32078) - 13511 + 12125 * -16064 + 10661 / 28882 / 23420 / 10943) / 22054 * -22324 / -9347 / 22211) * 25765 - (-10589 / (20779 - -30851 * 3179 + 20719 * -24539 + -16354 / ((11410 / -15728 * -10628 * -9592 / 16142 * -25936 / (-28291 / -28041 * 11289 + -15627 - -9905 / 14402 + 17454 * -1568 * -24993 - -8953 + (-20670 - 5689 + 3737 * -7806 * -15294 * (-22763 - -8644 - -18758 / -25395 / -24370) * -30225) - 19673 / -15422 + -22593 - 59 + -11421 - ((-16077) - -21202 * 11773 / -4253 - (-20771 - -7582) + 5817 / -13935 - -10357) - -10102 + 25273 / 25914 - 24427 / 13902 - -28815 / 28383 - 27352 + 13656 + 14325 / -27638 * -27603 - 26080)) + 1) + 19594 - 9216 * (-31885 + 20832) + -20354 / 10756 + -5099) / (-31719 / -3525 + -12835 / -20234 - 15296 / 3642) + -18943 + -19426 / 24352 / 18293 * -24762 / -5512) / 12874 + -12099 / -32683 + (-26388 * -14529 + 21577 - -15395 + -796 - -22443 - -11281 - 1928 - -18449 * 19981 / -5746) * -18522 - 17341 * -3211 - -23896 / -4177 / -25970 / (-30811 + 9854 - 17067 / -1603 / 8715) - 9197 * -21185 / 2705 / 6728 * 15796 / -4025) + 21068 + 31455) + (4592 + 18183 + 8485 + -6834 / ((31550 / -32486) + 1)) * 28650 + -18347 * -14764) / (29109 + -29128 / -10152 - 10049 / 18626 - -23978 - -17114 * (-28591 * (26372 + -9209 + 29665) / 18096 + (-25007 - 26405 + 2996 / -28644 / 22814 / 13099) * 15043 + (28348) * -18072 + -10367 * 1771 / 20767) - -24017 / 10878 * -1658 / 5767 + -25479 - (-5300 * -17914 * -11689 / -24778 / 3109 / -30376 / -25381 * (-1069 / 25019 - 12288) * -25054 / 30116 + 3501 / 31526 / -7494 / 26226 / 16679 + (19633 - 24208 / 19295 + -17123 * 29034 - -10379 / -24282 * 9729 + -23687) / 8950 + 22610 / -238 + 7183 + -29038 - ((-5881)) - 8362 + 30766 * 12443 / 32745 + -441 / (5460 * -23905 * 32496 * -5503 / 9272 * 5890 / -8810 + 23444 + 8086 * 27276 + -31230 * 5656 * (-6672 + -8951 / 3548 - (15119) + (14038 + -32637 * (-30436 / 11796) - -6623 / (-27982 - 9243) * 6963 * 2961 / -2786 * 6306 / -31983 * 6966 - -18227 + (7107 / 27364 - (-30275 + 4739) * -6810) / 6625 * (-29555 * -19537 + (-32373 * (13809 / 686 * -14557) / 357 - 21501 + -30131 + -19297 - -12785 + 11836 + (-10698 + -2929 * (15103 - -27188 + -14376 - 28657) * 28073 - -21094 - -25321 - -22172 / ((-840 / 32399 / -2257) + 1) / 25178 + 19291 + -16804 - 2938 + -28256 - -19067 * -14804 - 10724 - 6717 * 12219 + 19278) * 384 + -18730 + -9643 * 1331 / 23274 * (-10492 * -11180 * 19068)) + 16943 - 32751 * 1054 / (605 / 18718 + -11299 * 29842 - 5193 + -23968 * 11870 + -32105) - 3308 / -5889 * 6248 - -22294 * -21184 / 31344) * 18097) + 11440 / ((23191 / -26096) + 1) / -25113 + 6796 + 17250 - -31137 * -6509 * -610 - -19131 - 12374) + -20499 * 23889 - -26401 / 28304 * -25631 * (-16212 * 25857 - -6960 - 4366 / -24739 * 11222 - -5898 * -7364 / (-9867 + ((-29863 * -13611 + 4931)) / -13053 - -2209 - (27458 + 5485 * -22927 - -17665 * -20021 - 6715 * (13821 + -6425) + 16803 - -2899 - 27223 + -9177) - -25226 / -16241 / 10111) / ((-31648 - -20677 + (-2572 / 31132 + (14093 - 4965) - 19833 * 30076 / -19279 + 15683 - (21462 + (-8251) * -2644 * -9052 * 26161 - 14665 + -21187 / 31738 - -3840 + -10100 + -18593 + -6362) / -11208 * 21530 - -23546) * (30363 / -12584 - -11088 * -5164 + -529 - 21777 - 15128 + 21018 / 32234 + 15428 / -14602 / 12522 + 26310 / 13965 * -21449 * -7531 - 20189 - 22347 + -17069 - 1050 + -8729 + -19101 / -27233 * 29316 / -11437 - -24375) - 18027 - -19182) / 18901 + 21595 * -31271) * 13036) * -12539 + 27475 * 5519) * -15957 * 17245 / -24888) + -20948 * -13385 * 23184 - 22017 / -14560 * ((30439) * 10384 + 26933) + 17764 - 30726 + -3558 / 615 / 20488 - -18229 * 12421 + -15135 / -28381 / 2158 * -27046 - -6818 - -10587 * -12195 + -3681) * -15614 + -22720) * -2670 * -16706)) + (15170 * 8216 / -18642 * (-9876 - 27928 + (-30264 / -1973 + 6299 / -3430 / -25858 + 22029 / -8165 / ((18535 - -30010 * 10248 * -23549 / 12952 / -9431) * 24519 - 23149) / 1066) + -29652 * -1597 - -25446 + -20246 + -15988) * 25322 - 17820 * -28963 * 29767 + -10944) / 29361 / 15068 / 12230) + (27836 - 20174 + -30371 + 8256 + 18864 - -31742) / (29065 / -32083 * -24616 / 17626 + -22890) / -22123 / (-17594 + -2420))"#, - r#"(24074 * 26564 * -20104 - ((26092 + -10334 * 26643 - -21713 + 17119 - 8287 - -20065 / 15303 / 27714 / 21595 + 8040 + 28948 + -28961 + 8116 * -27636 - -14253) / 25944 + 22890 + 23799 / (21367 * (22537 / -30308 + 10696 * -4919 - (619 * (-409 * -29384 + (6718 - 27903 / ((7938 / 11588) + 1) - -2512 + -25155 - 8777 + 22547 * -988 + 8767 + -2636 + -5732 + -17106 * 12876 / -20192)) + 28886 / -18221 + -28137 - 21286 + -24969 / 16225 - 28931) + -13325 - -21181 + (17619 + 3059 * 22029 + 21053 + -21598) / (24453 - -6622 * 12678) * 6154 * -28840 / -11565 + 16839 - -22488 / -29677 + 21812 + -3295 * 7424 / (17667 + -26394 * -18812 + 25232 * 14062 + -13542) + -10682) / -21316 * 10977) - -10770 / (28851 - 27884 * 11207 - -18436 / (26617 + 25316 / -20595 * (22559 + -13100) + 4119 - -5944 - -1971 / 15245 + 17703 * -17524 * 20950 - -21541 / 18825 / -24153 + 9168 - (-7712 * (18090 * -22330 / 3790) - (13387 - (1850 * 15426 - (4068 * (16627 - 9372 - 29881 + -7905 / 2188 * -2931 - 26998 * -21455 + -4846) / 3486)) - -4012 / (-2672 / -25870 * 22541 - -18673 / (-28707 + -7534 - -10373 - -9818 / 12315 - 10409) + -10645 - 22468 * (28471 / (-28272 - 12139 / -5149 * -4495 * (4972 - 25293) * -10109 + -17908 + -22578) + (-8136 - -4522 * (18551 - -24302 - -26888 * 13048 + 20196 * 6861 * -11828)) - -4663 + -2761 - 25071 + 4940 * -27684 * -3406 * 14103 * 11448 + 21839 + 30364 + 5757 - 18440 - -26834 * 9810 * -24370 - 12780) / -6317 / -6059 * 17036 / -1052 / -3437 / 8020 - -15839 + -31695 * -9953 / 26930 / 9173 - -19760 / 26510 + -20065 * 27084) + 3163 / ((-17303 * 23442 * -11781 + 17246 - -4764 / (-5721 * -16258 / -10979 - 11372 + (2070 * 64 * 24851 + -1157 - (6085) - -24026 / -7815 * -19608 * 176 + -9192 + 13703) * -25131 / -27418 + 26593 + -30678 + -17757) / 12012 / 16284 + -21750 + 30874 * (24527 - -14650 + 15210 * (-5220 - (-10260 - 3717 * 23789 + 22746 / 651 - 21629 * 23552) + 19537 * 31958 / (-13814 * 23131 / -29333 - (-18325 - -24194 * 8519 * 20067 / 27687 - -29021 / (-802 - 2474) / 5866)) + -9959 / 15002) * 13934) / -24424 / 9026 + (-16208 - -7277 + -17658 + -12057 + 20427) * 19843 / 25237 + 22514 / 19328) - (9735 / 30222 - 26628 - -1062 + 15966 / -24030 / -16352 / 24136 * -23417 / -5731 + 12905 + -22401 * -15881 + -4119 / (18017 * -15321 - -32280 + 16794 + (-1372 / 16253 + 13899 * -11929 + -6711 * (-21472 * (27729 - -4714 / (12406 + -8496 + 10932 / (-16166 - -1532) / 5021) / -10541 + 17722 / 1274) - 9785 / 5443 + 18236) - -6527) / -21169 - -16309 - -26433 - -1077 - -14557 + (-9443 + -7770 * 5042 + -8184 * 16796 * 23703 / -28093 - (17649 - -30816 - -23383)) - 21293 - (-11072 - -12076 + (-170 + -4704 / -23142 + 19266) / -2097 / -22199) - -17044 + 6107 - 6732 * 11770 / 26286 / 15910 - 11193 / 4527 + -2450 * -24249 + -23756 * 17339 / -22288 * -13503 + (-28743 + (639 / ((-14433) - 24335 / 21451 / -8549 * 6510 * -20694) / 1709 - -23039 / 868 - (-13931 + -5955) + -24796 / -29495 / 30187 / -13700 - 19478) - -12748 / 2675 - 23674 / -10830) + 30465 * -18613 - -28822 + (3805 - -3893) * -27922 / -17448 * -10626 + (-8771 / -8197 + -26511 + 32541 - 24230 / 32462 + -10722 * -18945 / -25695 * 2899 * -29826 / (-3963) / -12382 + (24488 - 23680) + (1705 + -30387 * 23419 - -28055 - 2355) / (28480 / -12138) * 11266 / -672 + -3734 / 263) - 26180 * 11443 * 32042 - -26213) * (-8354 / 17634 * 8308 + (30093 / ((16920 / -29423) + 1) + -6000 - -12388 / 16762 - 4258 + 21972 / 4181 + (-10372 * 26998 + 4353 + 29862 * -4003 / (19942 + 21488 / 32164) / 19430 / -22059 + -32515 * 23819 - -28846 / 21317 * (-32478 * (-31428 / -21795 - 6585 - 8351 + 13192 / 28531 - 7169 / -31055) / -22057 + 8811 - 10957 * 32282 + -20310 * 31267 - -24521 + ((11989 - -25258 + -20684 / 8968 - -28362 * (-16723 * 28204 / 3028 * ((-15633 * -12340 / 27031 * -18240 + 5215 * 15835 * 1808 + 6182) * -10696 - -16464 / 20749 * -10965)) * -29 * -8225 * -19490) - 31989 / 4290 * -11887 + -8637) * -10471) / -17895) - -24298 * 26971 - 24952 - 12544 + -15034 + 381 + 22553 - -20820 / -14093) / (17285 + -25737 * 6485 * 19060 / 27515 - -16376 + 23179 / -23697) / -27174) * -30626) / -792 - (-29674 * (-5520 + (-14272 - 11027 + 8403) / 5076 * 30642 * 10333 + 28054) + -28663) - 30668 / (29888) * -22584 / 24534 * 22387 * -21488 * 4035 - 15976 / -16963 - 31201 / 8357 * 4902 + -22369 - -30359 + (-652 + 26781 - 20469 + 11647) + -27150 * 25136 / -4005 - 9162) * 29441 + 23352 / -2728 - -2330 + 12688 * 28182 - (30565 + 7139 / 19181) + 4397 - -21834 + -30711 / (5175 * (7661 - -5755 - -2516 * 392 * 2989 / 15764 / -14464 - 17374 / -2437 / 4755 - 21735 * (20599 / 11407 * (-29773 / (-30325 / 14665 - -1876 * -3042) + -100 / -1497 - 12895 + 2753 - -28834 * 14275 / -30935 / 3816 - 10400 - 7551 * -31631 + -3781 * -6502 * 31622) + -6483 * -23546 * (7154 / 12576 * 30485 - -30017 * 16207 - -24286 - 29932 * -10797 * -16976 + -20402 / -13725 / 30211 * -9941 / 6138 * (-3098 / -15019 * (-31836) / -29333 * 13691 + 4689) + -24565 * -8435 - -5659 / -28390 + (5635 + (-27778 / 11838 * 7178)) / 16906 * 21687 * 7636 / 8570 + -7358 * -17416) / 16222) * 10175) * 17872 + 14477 * -6058 * 16409 / -12673 - 29922 * 12318 / 15042 - 26533)) / -22580 + 28809) * -23526 + 31995 - -28925 / -12114 - 20239 * 27152 / 29400) + 13631 + -6217 / -26771 * 18383 - -7823 / 18890 / 20250 + -18088 * -252 / 8032 / (21990) - 6743 * (-3779 - 1857 + ((-17612 - 11989 + -14606 / (-24900 / 11083 + -2747 / 9102 + -6123) / 31761) - -7762 * 17253 * -21893 * (8334 / -13531 + -21313) + -18737 + -15535 + 14019 * -20593 - -25977 * 6643 * -6651 - -12443 + 16123 / 16425 * -7221 * (8308 + 12696 / -8150 + -7273 + -7006) + (8142 / 2606 / 10281 / -21199 - 926 * 19257 / 15914 / -8956 / -30191 * (1438) / 7257 * 27775 / 24740 / -23808 * -3554 - -906 + -14123 - -29551 + -11816) / 4024 * 16565 + (-23578) * -4610 * 7420 / -24962 / 15233) * -11037 - 19246 * -23669 * (-29734 - -24124 / -2887 * 4444 / 30676 + (14594 / -14376 / -31449 * -16083) - (-5199 - 30358 - 18154 / -5900 - -29741) * 10556) - -27430 + -32454 + (30578 / 15508 + 21512 * -28020 / 13882 / -6797 - 10461 + 11697 / -30772 * 20158 * 5562 * (27905 + -210) * -31117 * (-16688 * -22720 + 26773 - 18134 * 16559 / -12779 - -3403 * 18512 / 13511 + 6 - -20803 - -11823 + -13623 + 5645) + 10809 - -6548) / 1158 + 20777 + -388 * 5499 + (-528 / (-19574 / 24653 + -13487 - 29099 / 21003 / (-7289 - -7216 * -10195 + 7408 - 5907 + 16636 - -12129 / -1025 - -724 * (-15765 / 14119 + -17202)) * -4287 + -1099 * 21420 + -29208 - (-26546 + 6563 * -17851 / -18302 * -26039 * -1748 * 26599 - -20472 / (-22046 + -22727 / 28273 / 4927 + (6451 - 7216) - 24348 - -19729 * -16658 * -25856 / 26215 - -23519 - -29991 + (-11090 - -2630 / -28072 - 13451 + 32397 + -26539 + -3118 / 5826 * 2913 + (-30526 - (-4338)) * 4367 + 11620 - (-28649 - -18304 * 26427) - 9884 * -2700 / (-12637 * 14779 / -6630 - 21156 * -18702 * -19549 + -2870 * 11226 - -22290 + -20844 + -19986) + -9866 / 8727 - 13719) * -21739) * 24469 + -9340) * -7093 * -13803 - 8060 / 1174 / -5832 / -22827)) / -6605 * -16426 - (-19695 / (8515 / ((-5890 / (-26635 - 317 / -2603 / 8459 - 4554 - -19042 * 18323 * 11809 / -9534 - -2244)) + 1) + 32630)) * 1804 / 16748 / (-19288 - (28558 + 31848 - 26230 * -2756 * 5861 - 5196 - 16203 * -10780 + -1358 - 8775 * -32197 - 5178 * 29944 + ((-26591 + (26408 + -17951 - 31635 / 5196 - 32415 + 23870 - 17385 / 1258 * -18017 / -5822 - -25210 * -9185 + -5099 / 25675 + -13962 - -7695 / -32340 / 12040 - 25970) / 16605 / 27976 - 21278 + -18101 / (-13688 * (-9477 * (3222 - -16250 - (3896 + 29487) / 258) + -18308) * -21962 + -11052 * (-6445) * -23671) + 22030 + -23474 + 20070) / 18917 + -9815 * 28949) / -29495 - -11297 - -24266 + -29706 * -21557 / (12855 - 30017 / -6613) * 30555 * 26969 / 5215 / -17945 + -18604 + 6792 - -12018 + (10503 / -24872 * -18323 - 11814 * -25827 - 8326 + -11784 * ((27596 - 27242 / (-8866 + (((13188 * 3897 - 23985) + -9815 - (-18590) - 3058 * 24593 / 5554 + -21755 + -8120 / 7186 + -10369 + -1663 - -29901 * 7044 - -10954 + -17554 * 6493) * -7963 - 579 - -23612 * 8229 / 7128 + -1684) - 19792 + -8720) + -9119 * 31200 + -31018 + (19421 / -14872 - -8262 - -4055) * -6110 * ((-32307 / -11029 / (-15447) - -26107 / -31486 - -20147) - 17017) * (-4003 / -11358 * 24858) - 24428 - 28710 - -5812) / -20441 - 28710 - -10159 + 13676) * -29614 / -20499) + 17021 - -17875 - -25776 / -2394 / -31856 + -12055) * -8065 * -28328 + -23707) / 30185 + 4060 / 1064 * -5872 / 5153 + (-21825 / 10522 * -6072) / -17633 + -10254 / 14490) - 28413 / -29028 + -1096 - 7534 / 8861) / 17759 + 19732 - -18204 * -12995) + (-32233 * -27262 + 532 - 5611 / 25153 + 22073 - (13726 - -18279 / ((20575 - -1206 + ((-28005 * 26064 / ((-3501 + -30905 / 5233 - -26229 * -9614 + 14749 / -7745 - -9387) - 22499 / 22793 + -29810 + (6060 + (13342 - 30368 * 26866 / -29171 + 26) - -3678 * (25200 - 7587 - (15897 / 17765 + 16172 - (-30838 + -2913 / ((-3580 + -32720 / 27676 / -27502 * 1074 + -6408 / -31426 - (12583 * -20145 - 4495 / -18152 * 22516 * (-9378) / (-26646) * 12493 + -30828 / 24784 / (21081 * -2746 / 22047 - -2215 / -15005 * -20516 + -16181 * -4404 * 20332 - -30035) / -7956 * -5780) * 17729 + -27188 * 25839 - 10431 * 20886 + -5815 * -25552 / 30837 + -18410 + -5521 - -12275 + -31333 / 4202) / 22613 / 24520 + -27724 * 3870 / (-2230 / 3532 * 13773 + 14456 - 3114) + -16886 - -30411 - -30637 * 10542 * 25858 * -5423 * -28026 * -8861 * 3 + -5755 + 11411 * -8896 / -2743 * -8724 - -28542 - (926 - (((5298 * 41 - 12666 - -25626) * 30584 + -7518 / -765 * -29034 / -14625 / -23719) - (-19891 + 21396 / 22405 * 12266 * (14044 + (-6807 * -5845 - (24651 - -27257) / -19551 * -5747) + -25864 * -29764 * 18702 * 11701 / (-23768 / 9475 * 10179 - -8165 - (7064 - 21797 - 25144 * 29584 * 14654 + -16791) * -15087 - (-10520 * 26391 / 32394 + 22444) / (13025 / 6887 / ((-10200 / 27149 / 18291 - -20392)) * 17255 - 14777)) - 15398) * -15972 + 30315 * 14347 / -17102 / -26893 * -32118 / -3152 * (-12293 - -26425 * (-15525 + -9232) - (17123 / -31232 - -21030 / 28626 * (27153 / -9941 * 6924) / 27454 / -1642 / (-28306) * -2709 - -28776 * 18843 - (-22031 * 5835) * -20148 + -26090 - 1351 / 30753 / -28971 - (-2027 * 14211 + 12201 + -29450 / 28029 * -10818 - -30005 * 20182 - -2657 - -11185 / -20962 - 18392 - 19874 - 13687 + -11440) - -29661) / 29456 - ((20060 + ((24943 + 28507 / (31112 * -30884 / 5049 * 11727 - -2004 / -31347 + 22702) - 24626 - 5167 / -7962 - 2651 + (-7274) / -29281 * -1624 / -11630 * 28347 * 25824 / 11446 + -5857 / 11846 / 27433 + -1305 + 26838 - -20841 - 21696 * -31494) * 22879 - -3630 - -11751 * 23149 * -12458 / (24269 + 7398 * (16702 / (5077 * (28800 - 27117 * -10710) - 28543 + -16897 - -4355 + -7245 + 9527 - 12844 + -20377 / (-13059 - ((13967 - -32583 * -3478 - -17722 * 3804 / -8681 + (-20737 + (-17569 + (-12770 - 1339 + -17896 / 5036 - -12502 + 6597 / -32221 * (-1069 * 2911 + -24129 + 16555 * (30984 / 32505 - -21223 - -22681 * -14033) * -20202 + 12268 * 22951 / -27450 + 29633) * -25982 - (-4936 * 11640 * -28940 / -31049 - 19518 + -23687) - -5884 - -7223 / 28442 * -13350 * 2257 * -13806 / 9557) + 3130 * -13572) * 9553 * 32285 - -28862 * 28191 * 4232 * -23231 - 22826 * -15229 - -15687 / 27662 - -8883 + 19099 - -8637 - (-32543 / -18664 - 29355) + 29451 / 23022 * 13986 + 8936 / (-506 * -19272 + -2 - -15256 + 21492 / (-29507 * -27990 / -26885 - -18293 * -14421 + -15616 + 29077 + -10947 / 13016 * -2634 / -15022 / 26075 * 6821 - -17638 / -7986 / 27761) - -233 * -24928 + (11183 - 19998 * -7431 - -1419 - -25743 / -16062 * -2252 + 22710 + (-18349 - 14196 + 21447 + 8120) * 26981) - -30635 / 11543 * 5879)))) - -27140 / -6349)) / 25620 / 27177 / -30681 - 15057) + 15570 / 28865 * -21428 - 11658 * 10197 * -2282) * -18656 - 26635 + 20177) - -16781 / (31006 + 10580 + 30866 / 22750 - 4801 * -543 / -18979) / 11246 + 21141) - -5284 / -2477 / -31518 / (16083 + 23490 + 22126 - 29438 - 25928 - 20331))) - -32653 / 26563 + -20611 * (2669 / -25176) - 2414 - (-1389 / -10438 / -1294 - 5897 / 23216 + (21282) * -25941 + 16685 - (-17027 + -24913 + 26927 * -16324 / 21930 / 7161 + 1313 / 9437 / (6146) * -30975 / 23622) * 5168 / 22856 - -17665) / -7079 / (21202) * 27082 + 15352)) + -19944 * 2395)) - 23082 + 26665 / ((-7715 / -30529) + 1) / 7704) + -31535 + 16947 / 24343 * -29130 * 9617 * (-18372 * -18581 + 18430 * 18969 / 13615 / 22197 / -6279 / 384 / ((5924 / -24919 * 6922 * (-6181 * -3050 / -3752 - 30229 * 14685 / -28727 + 15409 - -15384) * 22186) + 1) * 11205 / -20320 / -995 + 13419 * 8146 / 7154)) / -12998 / -10861 + 8511) / 812 + 20817 - -12544 * 31581 + -20054 - -7958 - -23239) * -17150 + 15156 / -22884 + (16474 - -27357 / 30475 + 14466 * 28619 / (-2189 * 4433 * 19230 / (-23148) / -20078 - -26673 + -7694 * 32379 / 5666 / 13177 * (-16630 * 18553 / 6065 - 11668 / -30338 + 21236 * 21123) / -1676 - (((21305 + -7105) * (5445) * -12639 / -6865) - -31703 - 7323 + 4367 + 17515 + -5137 * (-31172 + 113 / 12147 * 24875 * 16717) / 29380 - -1367 + 1335 * -13042 + (5021) / 27281 - 8451 / 5446 - 1031 * -6831 + 16581 * (12953 - -12816 - -24667 - 2865 / -22505 + 12127 * 27389 / 5035 / 11288) + 31151 - -6815 + 4063 + 38 + 32559) / 25403 - 21781) / 29055 - -2890 * 21038) + 15493) / -11644 + -27567 / 10158 - -20571) + -32067 / 27298 / -12125 - 14785 - 23060 / -17060 + -300) - (3305 / -24052 / 13207 - -18958 - -23176 / 18648 + -6447 / -486 / 30288 + -27928 / -4947) / 11939 + -26480 + 29192 / 6704 - 29927 * 3959 * -23026 + -6716 + ((12400 / -19149 / -20745 * 18203 - -15786 * -22274)) - 29361 * 949) * 29933 + -4935 - (-22473 - -3797 - 26609 / (-32611 + 12635 + -3563 + -31444 / (30727 * -25099 + 29679 / -3748 - -16806 - (-26701 + -2472 / 30813) - (22016 - -3905 - 4844 * 15234 - -25455 / 11209 * (23407 / (-3331) + 21634)) + -28877 - 3116) * 11850 / -28982 + ((14338 + 6174 + -28650 - (-14372 * ((29231 + 10436 / 23893 * 4500 + (-32521) - -9729 + 15566 * -27057 + (-27906 - -4916 / 11479) * -12429 * -27678 + -5505 * ((2327 * (21212 / -442 * 14430 / 32497 + 13733 - -7281) - 28841 - -27960 * -26338 + -13431 - (-16731 / 17879 * -12644 + -11977 / 5063) + (-9310 + 13780 * 10650 / -19366 * (-19042 / 11513 * ((-28396 / 31064 * -152 * 21585 * -11601 - -17535 * -8698 + -27459) * 6619 * -1921 / 24869 - 18310) * (-26362 - -6438 * 7504)) + -26073) - ((28445) - -16036 + -23356 / (10030) - -24888 + (16095 - 6260 / -7722 + -4483 * 26856) * 20873 - -23248 / 30451) / ((6866) + 15119 - 13358 / 27867) + (4383 / -25858 - 12608 + (-9813) - 12064 * 24 - (-15381 + 26514 / 16609 + 5524 / 32453 / 24665 / -17960 * 29758 / -25717 * 29997) * -16059) * (-4367 * 25944 * 21078 + 23715 - (-1275 - 19583 * 23832 - -28590) - -18582 * 20975 + 12358 * 6286 / -23371 * -23783 * -28357 + 24699) / 18894 + -4756 / -28171 / -26321 * -31271 - -3378 / -31964 * -21316 - 12770 * ((-18629 + 29623 - -30367 / 517 * -24756 * -5221 / ((21500 + 29011 + 7587 / -14081 + -26508) - -32466 / 10699 * -19874 - 7657 - -19415 + -7837 * -23304 + -13309 + (32486 + (23365 * -16745) * 28349) * -5816 + ((30753 / -18029 / 4202 * -29111 - 13905 - 2270 * (1079 * 13154 / -20792 + -28907) / -30791 - 12132 + -28205 * 27288 / 4813) + (-20480 * -7369 / -5695 * 20268 * 28371 / -4702 * 15233 - -5104 / -32755 + 30720 * 1380 - -3400 * -14926 * -21242 / -9018 - -6439) * -24890 / 26884 / -21896 * -4249 + 5083 * 18699 - -15960 * -952 - -7138 * -31935 - (-17333 - 11954)) - 539 * -6631) + -8004 * 8885 + (-22167 + 15842 * -14726) / 27494 + (-18007 / -29664 * 32734 + 27511 - -9221 + -19066 + -3911))) - (-14514) - 10999 / 16531 + -1425 - 13057 - 22045 / (21030 + -25585 - (17708)) * 13042 / -9712 * 15833 * (4079 + 7418 + -5680 + -3972 * 20069 - 30183 / 12036 + -20670 - 19542 / 6328 + 20811 + -30888 * -13928 * -17284 / 4483 + -4025 - -20644 - 22694 * -1619 * -18757 - -31290 * -18388 + 20788 + (2405 / -11455) - 988 / 1985 / -2816) + (13066 * -15833 + 32655 * -30284 - -22431 - 583 + 12507 + -18308 - 10920 / (32516 * -4515 - 1315 + -16155 - -8136 + -21727) / -24167 / -18204 * -13725 * ((31945 - -13668 / 28725) / -17924 - 1295 * -29610 * -4386 - 22782 + 3420 - 17968 / -22924 + -11322 * -10685 + 5716 / -11549 + -23907 / -29477 - 17360 * (2691 - -23679) - -21752 + 9870 - -10509 * -4127 + (8131 * -4257) / -30127 + 3926 / -1958 * -30642) * 14634 / 8600 * -23285 + 3875 / 609 - 16197 * -27391 / 18191 * -15488 - -23481 - -32175) / -26169) / -22892 * 7471 * 944)) + -21824 / -4759) + 16256) / 28066 / 28886 / (21921 / -5395 * -29235 / -28393 + 16215) - 19065 - 11921 / -18150 - 32011) / 2908 + 564 * (23685 - 18237 + -13421 * -18485 * (27556 * 10836 * 27456 / -3328 * (13613 / -14866 / -16137 - 17795 * (-31661 + 27350 / 12225) - (14675 + 17577 - (-6334) * 3921 * ((-8645 * 27737 + -6249 * 25570 / (25327 / 12466 / 15737 * -12398 - (-13465 * -21339) * 22253 - -9374 * -13887 + (-11636 / -3713 * 1513 + 16099 / 26433 / 4795 / ((-1804 * -28751) * -24831 * 10257 / 7371 + 14892) * -12926 / -31316 + (31019 - (-3126 * 1582) + -26830 * -5642 * -3446) * 31793 + 277 - 11152 / -17473 / -20281 - 21007 - -32739 / 24222 / -21186 - 26159 / -4232) + 13659)) / -24292 + -11397) + 12976 + 3465 - 11181) - -7346 + 27105)) + -1375 / -14999 * -1813 * -19955) + -13532 / 6926 - 27706 * 7671) * -21183 / -2398 + (14287 - -22693 * -24551 + 12551) * ((-29467 - -5259 + 6166 * 11265 + -11180)) / 3753 / -5717 + 9766 + 14052) / -12339 / -4389 - 15050 / -28009 + -16429 - 5813 + (15398 * (26376 - -15536 * -25723) - 3484 + 30028 - -13415 * 13941 * (-24504 + 8516 * 19720 + -7391 / 6607 + 24627 + -27208 * (26667 / -18141 - 18978 / 29199 + -13410 - 6462 / -22094 / 16674 - 4325 * 3376 / -32567 / 15132 + -557 / -26354 - 925 + -13544 - 5285 - -23633 + -6471 / -29046 * 12924 - 29926 + 22608) / -18090 + 22304 + 31012 / -25394 * -25527 / (17020 - -32498 + 11243) * 6613 + -24592 - 16824 - 9652 - 12962 - -22863 / -13861) - 20342 - 30306) / -29428 / -18972 / 2010 + -1859 * -30051 + -12006 / -18546 - 10462 - -9521 + -20267 + -29329 + -30394 * -1760) / 14108 - -7392 * -9405 * -15528 * ((12572))) - -19602 / -21050 * -31014) / 1913 + -4186 / 14006) - 23244)"#, - r#"-3197 / ((-32426 / 7602 + -17645 - -12937 + 6131 / -17310 / (-1736 - 20700 + -13483) / -18389 * 8 / 5892 + 5899 / 8238 + (-2965) * 23743 - -5099 - (6906 + -30679 * 5185 - (13941 + (-15876 / 23620 + 11568 + 22614 + -711 / -8796 / -8069)) - 195 + 1270 + 5430 / -24422 - 16746 + -3081 - ((16437) / -9740 / (-2118 / 14869 * -7594 - -23478 / (-24008 / (-32409 / 4163 * (16908 * 11461 + 11695 * -3792 + (-8947 - (17882) / ((-24111 * 2187 + -15775) - 10681 / 23768 + 20440 * -16071 / 10963 + -6304 - 7999 / -30098 / 29296 / -20523 + 7197 + 5770 * 22621 / -3892 + -11586 + 20146 - 12700 + 3938 * -11454 - -11387 + 22684 + -30845 * -1133 - 7795 - -26971 / 23253 * 9420 + -8767 / -22379 - -10105 / 12201 / 17844 / -3731 - -17039 - 7854 - (-17007 - (16500 + -781 + (2942 + 14249 + -2185 + -32292 * -32604 / -1728 + 22631 / 19387 * -22312 * 32457)) * -22342 - -2845 / 29152 + -5126 * 1410 - (-24084) / -26786 * (13047 + 26856 + 7892 * 26815 - -31489 * 5237 * (-4993 + 24991 * -24189 - 3765 + -310 + -15991 / -8452 / 25262 / -290 * -9983 - -10842 * 15405 / -11300 * 28293) + -16854 / -504 - -9515 + -24669 + -4280 / 21375 / (3883 + 8452 * ((21280 / -24690 * -28747 - -1444 * -20445 + -16852 + -4020 - (-17639 + 31854 * 22156 + (1641) * 28024 + 9501 * 21723 / 9131 + 22591 / -16267 - (-16851 * 23363 / 8647 * 6135 / 29518 + -15603 + -29702 / -20931 / -9570 - -23349 / 31477) - -23267 / -15251) + -3490) + 19894 + -23773 * 30555)) / -25391 + 11769 + -14266 - -17016 / -20234 + 22747 + 15629 + -9713 - 22454 / -7524 / -5919 / -26592 * -4450)) / (12278 * 6315 - 22013 * -6497 + 3557 / 27417 + -473 - 8483 * -31871 * 24390 + -6110 - -22982 * 30688 / -9622 - -4964 / -23790 / 25088 - 16592 / -30721) * 8205 - -26162 * 20776 + 4827 + -13229 * 29273 + -12175 / 13376 / 30362 * 27899) / -26547 * -25390 * 8544 / 16821 - -22848 / -27067 * -27348 + 16941)) * (-12538) * (32614) * 9051 / -30094 / (-12386) / -6292 / 19001 / ((-13272 - 13663 * -345 + -17587 + 28897 + -20531 + -2217 / (-13349 / -19740 - -26826 / 3810 * (3136) * -29738) + -20318 + 27605 / 4462) * (26907 * (-20289 / 15003 / 22995 / -24701 / 514 + ((-17362 * -4545 - -24373 - -23037 * -19806 * 14652 / 15387 * 4542 / 6496 / -8391 - -14418 + 5829 + -17279 / -30281 * (15076 - 31999 * 32439 + 22699 / -11288 * 14384 / -23071 * 27116 + -10839 * 550 - (-29143 / (-28429 - 21952 - -7874) + (18854 + -13958 + -31020 / (-5001 / -28856 + -708 + 132 / -13814) + 25990 / 14377 / 31166 * 19399 / -12146 * -5617)) + -10827 + 28986 - -25639 / -13194 / (-8385 + -24296 * -22971 - 32690 / -27976 - (-10422) - 19279 * (15678 + 28200 - 8555 - -18356 / 5922 * 32315 + (11887 + -6623 / 1046) / -29090 + -2530 + (-24783 / -9401 / 30851 + -23954 - -2115) - 25785 * -1590 - 14436 * -9943 * (-21749 + 26062 * 11794 - 25641 - 14729 / -25455 * 25092 - -23866 - 5524 + -10023 - 11757 * 24889 - (26044 / (-29949)) - (-13810 - (-11434 - -16992 / -7660 + 24213 - 10585 + 16542 - 12374 - -5232 / -4506 / 17464) + -23702 - -13116 * -21595 / -248) - -12615 + -4055 / (20177 - (-11548 * 8212 * -25618 / -4762 * 6814 + (20804 / 21210 + 8282 / ((30252 + 23364 + (-15564 * (-23096 * 2361 - -4431 / 26629 * -26527 + 23024 * -22199 + 13020 - 1476 * 14074 / -17024 / 30430 + ((25900 / -2902 / (-16249 * 22435) * -561 * -13273) - 9720 / -4830) / -2334) / 6265 + 8251 - 16769) * -18087 + 32149 + 30377 * (-13504 - (-30220 - -17540 / -4102 * -21920 * (-19373 * (-22001 + (30645 + 23259 + -28982 * 12531 * -28698) + 17305) * -6293 / -1287 * -12832 + -24492 / 21432) / 16883 / 4077)) - -27942 * (-20245 + 20654 + 20314 + 4125 - 25455 + (-31854) * -32632 * 7846) + -5691 / -12494 / -21442 / -17159 / -18643 - -24590 * -20491 + -21135) / 1772 - 13747 * 1019 / 5266) * -26908) + -20846 + -11027) * -31172 / 15634 / (9205 * (-5535 / -29269 * -24544 * 507 - -10253) / -19463 / (-31405 * (28737 * -28137 - -15582) + 21578 - (3322) + -25157 * 6014 - 14323 / -10663 + 29259 + ((5492) / 29358 / -30716 - -6821 + 20833 - -10531 * 27983 - 31529) - 3598 - 7008 / ((-13252 + 211 + 10697 * -4085 / -1693 / 27976 / -21922 / 18616 - -4188 / -24609 * -21121 - -14508 + (-23399 - -11041) - -13524) * -29138 / 17277 * 1320 * -32488 * -19003 + -27763 + -23451 / -12615 + 3850 / 8633 / -18123 / 32345) * 6407 * -28609 * 8860 * (7468 - -1929 / -13886 / -5391 * 29606 / 32380 / -5427 * 28853) + 7174 - 11151 - 20372 - -7190 - (16393 / -5966 * 13413 * 25090 + 32509 - -13203 * 5188 / 21514 / 18838 / 21029 + 29327 - -18215 * -6811 * -4974) + (-16433 * -25533 * -7043 * -4989 / 14463 - (-10787 * 915 - -3420 * 31014 - (-25774 * 30094 / (-18924 / -19075 - ((-26688 + -1400 - -2683 / -17823) - -2999 / -16572 * (-30893 / 18753) + 30233 * 5697) + (-4627 + -22090 / (-20388 * (-16715 * (-1170 * -13204 / -19721 * -32212 * -8393 + 28343 - 24346 / (25582 * 30638 - -30302 + 14291 - 18050 / 6206 + -6925 - 11026 / -11526 + -2355 + -12342 + 13742 * -1238 * 26304 * -9590)) / 32226 - 22509 + -19904 - -30959 / 29206 * -22947) * ((-29652 / 32081 - 3941 * -14831) * (-1441 * (31604 * -14403 + 23153 / 30313) - (15780 * 19535 / -16260 * 14980 + 29545) + 26723 * -27723 / 2468 * 5014 / 19055 * -31699 - 11837 - -24657 + 272 / 31619 - 26398 - (((-28156) / -763) + 20034 - 23596 - 17859 / -3710 - -9682)) / (-27878 * -13202) * 27700 * -24423 - (8066 / -3642 / -23260 - 5596 / 32218 * 9014 - 27301 * -32679 - -3589 + 22483 - 3590 + 26679 / 20225 - -8266 - -27708 / -25354 * 9484 * 30877 + 2183 - 29280 / -1623 - (10010 * 7598 * -18096) + 10762 * 30071 * -18182 / 5212 * 15147 - -29574 + 8439 / -20143 / -2413 / -29509 / -6783) + 6559 - 26393 * -30672 + 8162 - 24670 * ((15203 - 2918 * 19999 + -25592 / 11783) / -6700 * -26033) - 9807 - -30118 / 11503 * 51) + 3803 + -30764 / 18538 * -30544 / (15964 + 7017 + 13916 - 25696) - 25238 + 8336 / (-6445 + 4258 + 15174)) * -7719 * -28082 / (21500 + 20842 * 1782) - -28992 + 1760 - -6661 - -18287 + 26766 / ((8730 / -8659 / -29007 * -20493 + (10206 / 4288) / -28834) + 1) * -18984 + 29472 + 15437 * 26064 / -5582 * 19072 - 19604 - (14803) - -21358 - 25041 + -4216 / 18981) + 19048 * -24255 * -19525 * -20092 + 11318 + 27533 / -31770 - 32085 * 22266 * 24471 / 23100 + 26842 * 27854)) - 1365 - (5759 * (-8501) + -3095 / -17065 + -17431 / 610 * 30641 / 31703 + 21145 + 11755 / -17185 * (-9760 * 27043)) / -12335 - (29874 / (-31817 - -30134) / -20997 / -6595) + (9068 + 15620 + 12338 * -19367 + (-24148 + (10198 + 2013 + 28292 * -7484 - 10724 - -23837 - 22025 * (-24123 / -2975 / 20948 * 7181) / -7044 * -12619 / -24077 + 28121 / -31517 / 80 * 17193 + (-7607 / -14672 * -6432 + 15512 * -27728 + -15731 / -19053 + -11006 / (-25780 - ((8515 * 17632 - 7253 * 23089 - -30609) * 9783 + (21213 + 1390 / -17489 * 30418) / -25208) - -2777) - 10841) / 5124 + -8658 - -31586 + -27998 + -28372 + 15379 - -8779 / (6366 * -10192 + 21321 + 28502 + -28174 + (12488 * (-27426 / (27764 * 32348 * 30885 - -29610 - -18515 / -10207 * -32572 * 5169 - -31342 / -31901 - -11146 * -7213 + -22121 * 21099 / 8101 - (-14685 - 12866) + 7736 * 13756 * 22901 * -8043 + -27120 * -20743 + -8702) / 30296 + (-18985 + -442 * -26517) * (23796 + -22893 / (13399 - -31249) * (-1563 * -616 / -15895 * 19104 * -27644) * 2344 + 8368 * 14192 * -769 * -25835 * -29914 + (23862 * -30776 / -15452 / -29759 * -4080 + -2623 / -32242 - -29301 / 31194 * -5965 / 8266 / 2481 / -14327) + -24093 - 14407 + 4518 + -29176 / -29770 / 28305 + 10650 * (-24992 / 19092 / -539) + -18758 + -12493 * 12062) + ((29366 / (6899 - 11781 + (13602 - -19844 * 12263 * 9232))) - -32179)) - 14542 + -2111 * -31133 * -31411 - (-29750 + (-10062 / 21323 * -6434 - -31303 - (18387 / 12072 - (8027 - (-15834) * -12067 * -6134 - (-9528 - -3365 * 10625 + -29157) + 4853 * 6452 + -5442) / (32045 + 18615 * -28398 + 25730 - -28866 - 9988 - -12236 / 31373 * (-3303 / 7178) + 3018 / -2744) + -26327 + -16081 - -21265 * -3049 / (26836 - -7923 + (21080 * -8938 * 3580 + -25922 / 26490 * -23194 * (((2940)) * -4396 - 13477 * 20538) - 17752) - (-25181 + 23868 + -13784 / 15498 * (1712 * 22204 * -14063 / -12437 + -24964 + -20435 * -31395 - (-14223 - 29448 / -21374 * -8919 - -24442 / -26206 - -4250 + (-31481 * (18010) * -30822 / -1201 / -22842 - 31899 / -5816 - -7496 + (22894 / -25818) / 19401 + -7067 / 5853 + 23346 - -27275 * 20157 + -23091 / -24801 + (-18344 * 7328 - -29203))) + 6070 + -18055 / 3306 / 28515 - 24263 / -18808 * 28554 - 17263 * 29821 * 19538 / -28794 / 29011 * -27578 - -18405 - -17617 / -3593 * (-25267 - -29022 + 1668 * 4715 / 24387) * (-7432 / 26063 - 20870 + -25903 - 22811 - -31279 / -30646 / -2803 + -389 / 8651 / -22738 + -29609) / -8845 / -25228 + (-27111 / ((27715 / (-30759 - ((-2033 / 23693 / -32602 / 27859 / 1810 + ((-26166) / -5679 * 14639 * -21419)) * (-2826) / -25557 * 2021) / -4923 / ((-9724 / -26453 * (898 - -22971) / (14850 * -5411 / -8043)) + 1) * -7709 * (-12519 * -15731 / 10981 + -28541 - -15499 + 8236 * 31524 / -10723 - -32261 / 393 - -29075 + 16477 - (16954) - -24158 * 1283 + -28077 * 7275 - -31927 / -4480) / 7415 * -11218 * -20502 / 22714 - -21430 * -9350 - 15100 + -24051) + 30703 / -824 / 6119) * 29260 - 4957) * -19343) * 8533) + 10357) + 28778 - -23578 * 27211 * -19006 + -24243)) / (-22084 - 30403 / -31185) / -24648 + 12449 * -9394 / -21279 * 3409) * 5118 / -4294 / -29712 - (4314 + -29822 / 5143 / (-27994 + 7570 - (-12290 + -6132 + -11613 - -8189 / 32350 - 22731 / 15337 * 18525 - -24619 - 26566 * -31619 + 23626 * 24041 - 15409 / -4076)) * -26412 - 21103 - -16780 - 26657 * 9287 * 6415 - -3713 / 20781) + -7945 - -14636) - -3544 - 2580 - (30593 - (-22973 / -18539 * 3783) * 20181 + 30328 + -16907 * (-23794 - -439 + 23 + -1447 + 6844 / -8235 + -9028 * 26354 - -5341 - -12488 + 25104 * 6908 * 15884 / -16592 - -5866 / -31446 / 3508 + 29919 + -3907 - -15484 / -24603 / -25835 / -28670 * -29179 * 8595) - -27899 * -14739 - -13670 + -22730 - -3559 / (-21182 - -20710 + 12098 * -13667 - -21369 * (-28052 + -6376 / 17781 - 14684) + -30338 - 0 / -11154) * (-19303 / 177 / -4677) / 18030 + -14928 + 2107 + 1338 + -17828 * 24003 / 28895 * -16960 * -5241 + 24136 + -9911 * 437 - 20258 / (10249 * -24160 - 12011 / 16569 + 13814 * 31380 * 23316 + (-23199 * (-977 - 7105 * -30318) - ((-3806 * 9285 * -7108 - 28035 + (-26033 - ((26331 - -2794 - -27396 * -25246 * -31765 / 3659 - -21408)) + -8191 * -28239 * 29428 + -32546 * -11519 - -19071 / 12592 / -29072 + 19927 / 32261 * 14712 * -6871 / -23597) + -5250 * -1933) * -19948) - -28060 - 22011 + -13326) + (27603 * 4012 * -18592 - (410 * 19508 - -31037 + -11978)) * 16568) * 23405 * (-1721) / 1219 / (-11261 + 18533 * ((23656 - -31135 * 16749 + 25425 * -19556 + -27568 / 6776 - 14003 * 1180 + 6070 / (-20025) + (-25205 / 3936) * -18029 * 32151 - 429 - 27492 / 15486 / 7396 - -6440 + -1184 * 25390 - -19650 + -23777 / -10377) + -7404 - 2221 / -12170 + -18967 - -11471 + -28844 + -15303 + (17677 + 13333 / -4619 * 9755 - 15660) * 1440 + 27928 / (((20883 - 26781 + 19946 - -20635 / -8490 - 24582 / 31213 + -316 + -32626) * -22410 + (11007 * (16019 + -18524 * -29715 * -8229 + 11771 / -27954) * -26038 + -17805 * -349 - -28679 / -9593 / 22374 / 27887 + 18329 / 32663 * -24304 * 5931 * -26053 * -5129 - (-5718 / -15643 / 30245 / -2079 - -5013 / (-19647 - -1235) / -15840 / (-7601))) / 15264 * 9300 / -10685) / 10774 * -28647 + -25711 - 26937 * -13293 - -15662 / 10666 + -21449 + -24110 / -6669 + -26785 - 11960) + 27491 * -24319 - -9676 * -10358 / 22579 / 6845 / 19946) / (-23923) - 31233 / (28175 * 8634 - 16406 / 10972 * 6542 - -27236 * -15707 + -25443 / -6025 / (12758 + -10932 / -29303) - -12842 / -8264 - 21223 - -1980 * -29809 * 2935 * 11992 / -14638 - -14068 - -17340) / -6306 * 1394 / -8175 / -12793 / -6544 - 24181 * -29827 / -13540 + -13507) * 29345 / -3409 - 13138 / 1065 * -20603 + -5698 / -3016 * 27439 + -14481 - 14910 - -4607 + (-9869 * (-2606 * (-346 * -7711 * ((30116 + (23577 / -21700 - (14770 * -21221 + (6000 + -6226 + -1216 * -13262 - -3873) + -20359 * -8436 - (15289)) + -6454 - (-32025 / -22498 * 12919 / 1517 / ((-4405 - 1203 * -4877 - 14025 * 10932 + 20312 + -12415 - -3299 + (29546) + -8607 / -22049 / 23963 - -31844 / -3754) + 20588 + -15452 + 9643 / -29757 * 16583 - 16037 * 14385 * 3121 / -6775 - 13145 - -28416) * -7899) * (13262 / 23377 - -18867 - (-2816 * 23286 / -14422 / -7859 * (23542 * 24491 * -32399 + -1375 + 17665 + -31932 * -61 - (-31664) / 31497 - -13375 * 30644 * 24065 / 31619 / -29759 - -3080 + 32353 - 29496 * -18711 * -6107 + 27618 / ((-25337 / -28542 / 13414) + 1) * 31687) / -23082 / 5888 / 5675 - (-13680) - -28745 * 23499) / 2071) - -26625 * -11823 - 28331 / -28850 / 22905 + -30900) / -15649 * -25436 / 28219 + -24512 - 10441 * -10004 / 23716) / -95 / 6 * -20918 - -7014 + (-26946 / 25165 * -11448 + -22201 + 4670 - -115) + -6037 + -6349 * -24067 + -4357 - 22428 * (-27790 * 12725 - (-17317 / (3789 * 6384 * -28293 * -8114 - 31693 + 10695 - 32075) - 32339 * 24973 * 14613 / (-1347 + -24725 - 2202 / 882 * -26557 / -32270 / ((-7329 / ((23323 / 24565 - -12061 / (10892 * -1187 * -32305 / (22195 / (-1493 * (-23791 / 29229 - -15298 * (22781 / 29254 * -16763 / 32233 / 10856 - -22422 / 10143 * 9598 / (16985 / -18891 - 15167 - 16644 + (27536 + 5644) * -21893 / -23478 / -10494 - 4783) + 6148 / (-31596 / -9990 / -9630 * ((7425) + (25304 * -18629) + -27776 * -7374 - -27891 + -5925 / 4328 + 10980) + -11038 / -12248 * -25974 / 8416 - 13183 * -664 * -32612 / 19728 / -14698 * -8905 * -12077 / 1866 / -32448) + -12515 / -14467 - -10523 + (26767 / 23560 - 18789 + -27923 - -27933 + -26457 / 14121 * 20189 + 11152 / -6509 / (-31116 * 4232 / 14029))) * (-26954 - -24193) * -30422 / 8489 - 18278)) - 10626 + 14580 * 6392 + 12491 / 19027 / 10522 + 13997 - -2839 / 14070 / -22510 - 15345 / -4697 + (-17712 - (9650 * -6990 - -1296 - 5435 - 21608 * 556 / -18238 / -11059 / -2747 / 16300 - 22007 + 28519 * -6710 / 26491 + 30480 + -19501 + (((-27664 / (18610 * (7343 - (-25168 - (24382 / 2063 - 14 / -16222 - (11764) + -30877 - (-22446) / -23061 - -19040 + -20634) / -9391 * 18707 - -2192 - -29844 - 21630 / ((-12498 / -18956 / -30987 / 26949 / -11643) + 1) * -2829 - -14316 * -25281 + 19814 / -5003 - -22026 + -24027 + 3608 / -8055 * -28720 - -8492 / -25064 * -20102 - 32170 * (6055 + 14586 / -23562 / 20868 - (-20758 + -21003 * -27515 + 18131 + 13137 * -16469 + -24499 + -4743 + (2304 + 16765 - 23790 - (-20704 / 24576 / -12135 + 14628 * 24920 / 16083 / -3161 / ((-30264 / 13975 + -7520 + 12712 - 23684 / 15909 * -12733 / 30053 / 1042) + -8698 * 5411 - -24667 + -1707 - (-532 / 24529 / 28655 * -16476 / -24027 - -24917 * 17916 + -6442 / 2699 * -1302 - (289 - 15616 / -22664 + -23979 - -10116 / -15936 + 2345 - 18238 - 7189 - -19124 + -5278 - 3572 - -20286 - 22901 - 9941 - (-17971 + 12002 / -24743 - 18435) + 18605 * 6087 - -20234 * 30548 * 809 - -7651 / 15947) + (-29945 + -21189) + -25621 / 22111 * -25188 + -471 * 7605 + 2038 / 20887 + -32763 - 25705 * 5380 + 21449 + -25051 * 5492 / 14108 * -31771 + (-19922 * -7018 - -21337 + 13504 * -28584 * -20290 - 22730 * ((((-18535 - -14849 / 20342 / 9869 / 29300 / 23419 - (32159 - -5683 / -17024 * (6445 / -9785 + -3478) / 11483 / (13364 - 4148 - -28119 / (-3644 * 31569 * 27369 / -22898 + -22667) - 15355 - -32549 - -21244 + (15564 + 22268 - 15322 / -7713 * 17143 * 32214 + 11037) / -21147 / -13439 / 21947 * 9371) / -26558 / (12834 / -7288 * (-7827 + -24645 - (-1623 + 829 + 31216 / -4126 - -5936) + 17055 / -14313 * (26080 / 22182 + -6589 * 23323 + 28905 / 23772 * 7321 - -32026 / -25406 * (28544 / -19967) - -2578 + 25054 + 15209 * 9187 / -22220 * 28051 / 30619 * 16105 * (29749 * 30146 + 16573 * -13768 - (-638 + -26675 + -16406 + 17885) * -21728 + 27022 * -11666 - 21278 - (8764 * 294 - 3314 + -25004 / -13631) / -21485)) + -18779 / -12712) / -7396 + -30080 * -15892) / -25310 * (-3746 / -22921 * (1446 - (-24129 - (-25056 * (20657 / 12738 + -13365) + 16258 / -5250 + -21430 - -30599 + 9936 * 25327 * 743 / (10234 - 25303) - -4425 * -26678 + 13608 - (((1997 + -23115 * -20915 * -7583 - 15759 / -21174 / -25211 + -29350 * 13825 + 31867 + -31106 - 24080)) * 6438) - -27034) * -5384 * -32007 * (10504 + -22849 + -26591 / (13936 + 3196 - -27417 + (-22256 + -4220 + 242 * 29608 / 3550) - -12898 + 17762 * 8592 / 20923) / 22457 / (18639 / -26485 - -31513) + 20406 - (7317 / 30576) - (2882) - -18561 + -24277 * -29820 + -25755 * 27585 - -17843 * 28718 * (((-13100 + -29752 / ((-32497 / 31573 * 7264 - 11944 + 8601 * 5977 + 22760 * -18656 - -25256 / -26887) - -25159 * -23251 * -13689 * 28832) * 2652 / ((-11192 / -18464) + 1) + (-32406) * -31180 * 3656 + 25076 * 9089 - 19713 + ((1805 * -24702 + 10852 - -23885 + 23333 - 11836) - 9308 - -17205 * 22763 + 28228 - 3501 - 19977 / -25626 + -5796)) - -11574 * -25814 * -21347 * -18357 - -18973) * (-27424 / -16471 * -7919 + 18245 + -7861 - -8599 / -5367 + 17874 - 13397 - 23746 + -19944 * 4703 / -1414 / 29069 / -31847 + 4497 + -653 / 21125 / 27615 / -18966 - -32312 + 8328 * ((27566 * -7484) - -26241 - -2874 + -8677 - 13000 * 14251 / 10282 / -5814) / 8747 / 17346 / -25353 * (7841) / 9137 + 31623 / (1310 + -4100 + -7996 + -3293 * -19946 * (12391 - 6246 + -29783 / -27865) + -22089 - -24198 + 29403 + 32246 - 17149 * 29640 - -7010 / (7165 - 27185 - 23886 / 24419 + -21411 + ((-9853) * 14450 * (-2794 - (22154 - -4418 / 26201) - 13986) / 24691 * (6080 / 14010 / -13509) - 22954 - -18107 / -19483 * 27744 / -26547 / -7574 - -12498 - -26392) / -20767 * 16064 / -23388 * -24853) / 29293 + -23677 + 24817 - 30861 - -18083 + 26070 - 27134 * (-13843 / (15696 - 28746 / ((20037 * -7987 * -7661 - -10551 + -27395 * 26943 * -687 + (29967 + 15929 - -408 * 6331 + -16961 + 30232 + 19844 + (898 + 4460) - -12268 - 13067 - 22059 - -18975 / 15420 - 21760 + 24357 * (10128 * 22648 / -24656 - -10908) + -1091 + 9518 - -18711 * -14663 * -17549 + -22148 + -32643 + 4632) - -22534) + -11869) - 22585 / 27803 / -28242 * -30942 + 30978 - -27543 / 14046 / -28139 / 3644 - -19899 * -7877 / 26048 - 31425 + 11650) / 29094 * (23227 * -24240) * 16683) * 3427 - -24206 + -7555 * 19353 + 16690) / 27232 + (-11988 + 32564) + -16734) / 8877 / 2098 / 30597) / 27728)) + 6417 + 31379) / (-20880 + -20075 + 18129 * 11491 * 15814) * 9778 / -20240 + -4941 + 3195 - 4274 / -19424 / (-31275 + 32653)) / -23662 + 28242 / 27563 / -17248 + 9223 / 8376 - -28563 + -13485 - 5992 * 12442 - -27256 * 7890 + 13693 - -10191) - -8011 + 27470 - -31372 * 12233 + -8074 - 32351 * -7056 * -10732 + 17074 * -25533 - ((-13703 * -19766 + (21191 / (((-25223 / (-31117 / -28947 / 12627 + 24845) - 29121 + 21563) / 1280 / (-26376 + -9897 * 25590 / -23720 - -21441 * -5377 + 16391)) + 1) - -25960 - 32483 * (-20883 * -12829 / -12107 * 29758 * -22787 * (5120) - 22027)) / (690) / -16603) + (28718) / 30799 * 2136 - 10206) + -11220 + -17092 * 17790 / 9015 / -30144 / ((-17297 + 4781 / -4447 - -27897 - 25588 + 29793 * 15802 - -3409 + -2550 * 11361 / (-14329 * 22518) + -28564 + 29481 + -4431 / -19878 - 32240 - 13665) + 31488 - (-17953 * -28579 - 31828 / -2876) * (14791 * 23785 - -11737 - 15203 * 26004 + 5862 / -24241 - -18810 + 11362) * -10411 + 12721 / -26564 - 2968 * -12794 / (-27477 * (-4792 + (-30994 / 5643 - -3448 / 6659))) + -26432 / -17351 + -27194 - -14718 + -9030 / 22282 + 21584 + -20429) - 26809 / -18747) + -10940) - 8490 - 7758 + -25443) / -27065 * ((-28627 / 12041 - 29145 / 20422 + -6696 / (32199 * -15101 / -12462) * -21284)) / -17651 * -30470) * -26016 + 6180 / -20184 + 23009 / 11390 - -9474 * -14463 - -20090) * -27234 + -23823 + 9540 / -1166 - -15365 / -15180 / 19138 / ((4988 / 24351 / -12950 / 6944 * 22090) + 1) + -11340 * 29910 / (-3031 + 17141 * -556) * -10473 * -1377 / (-15675 * -22413 * 14767 * 1374 - -15418 + -27470 + -15359 * -23744 + -5328 + -2618 + -18632 + ((-31259 * 14844 + 15169 + -2161 + 29983) * (24448 * (11389 + -11661 * 3191 * 28481 + 10183 / 16974 / -22982 * 31209 - -3998 + 19435 * 18682 + 18999 - 3599 / -11322) - 6942 / 22762 * (16572 + 5761 * -26103 / 5384 - 14359 - -31798 * 26964 * -23805 + -20768 + -28417 * -24251 - -11429 + -31260)) * 6005 + -9629 / -7353 * 2156 + 22814 / -13613) - 5934 - (-7042 / -8572 - -13774) * 30182 + -27082 - 1019 * 8783) + 8163 / -18292 + 11442 - 8341 * ((18432 - -11303 * -22507 / -30442 + -2777 * 22465 * -9728) + 24434 / -32546 * -13848 / -7932) / 2971 / -14477 * 29680) / 29735 - ((25054 + -30176 - -27344 * -26394 + -30678 / -7733 - -18513 - (12729 / 19458 - 17131 / -26672 * 18207) - -3490 / 32275) - -15852 - 17033 + (-31171)) - 30326 / -3651 + (-32069 + -2703 + -32395 / -15195 - 13259 * 20565 * 5147 + 28562 + 10248 * (30192 - -16728 - -28012 - 11291) + -20244 + 16773 / -27491 / -3990) + -22930 / ((2776 + -16728 - 16061) / 17086 - -15542) - 27392) - (-21464 - -24068 / -22732 / -17074) / -2506 / -28876 / 30492 * 7647 - 11115 * 6462 + -13410 / 29078 - -26592 / 26421 + 1938 / -6697) + -27816 + (-16837 / 3009 / 7268) * -18243 / -337 - -6217 / 5798 - 44 + -26165 + 3433 + 31018) * 23777 * -26319 + 24374 + -19031 * -9670) / -32264 * -25030 / 19929 / 27411 - ((-12147) / 15054 / 11802 * 22309 * -14508 + 7518 / -3924 / -29819) - -16047) + -31746 / (1445 * -30340 - -32756 * -26090 / 2176 / 3814 * -31216 * (-24521 + 2596 / (21309 - 19345 + (-23679 + 5309 * -23436 / (3352)) * 23198 * 19568 / -8253 * -15399 / 18434 + -26110 - -20773 * -12769 / -12314)) * (-15708 + 21464 - 14054 * -18281 - -24564 + -23993 / -9837 / 17681 / -6001 / 4869 + -31661 - 32515 * 183 / 1072 / -8758 * 26678) / (-14159 - 14726) / 9311 - -6343) + -22825 / ((1709 + -9105 / 22596 * 15339 + -31245 - -29881 + -22168) / -6525 + -13934 * -8085 - (10714 / 15233 * -11033 * (-328 - 25395 + -32475 * 25843)) * -4920 + 18906 + 18119 + -20719 - 12165 * -3876 * 23041 - 16564 * -19304 * -13901 + 1261 - 6088 * ((28034 + 4708 * -14603 / -23257) / 30007 / 12889 - 2079 / (-1053 * 26793 * -22945 - -23830 / 22100 - (17686 - 1073 / (-27678 - (1833 * -27605 / ((25810 / 14475 * (27549 + -14713 + 24005 - 2721 * (-32137 + 25164 + 3294) + 473 / 10972) * 6257 * (-5021 / -20459 * 7676 * -10841 + 27082 / -1927 * (-29652 - -1731 - 22544 / -30304 - -14655 * 30499 - 31540 - 31910 * (4135 - -10858 + (9637 + -20385 / 5934 - -30117 + 4972 + ((-30990 * -22121 + 20911 - -29560 / (-29445 - -31687 * 9674 / 19059 / -31854 - -11177) / 11869) * -16306) * -18171 + 19723 / 14621 * -23609 / -22777 - -8857 * (-24332 / -2763 - 1255 / -31969 - 13753 + -30907 * -19585 + 7266 * -29897 * (-12242 / -19061 - -23851)) + -9807) / 23012 + 1665 + (20340) - -15744 - -30133 - 156 / 15575 + 29307 / -18084 + -2158) * -24268 + -20599 * 29525 - -7999 * -11905 + -363 / -13944 * 16917 + 18080 + -30758 / -19247 / -8349 * 29269 / (4413 - -26340 / -20285 / (-2178 - -16030) / -22438 + -2539 / ((2360 / 22633 * -4188 / 24450 - -26569) * 10449 + 11380 / 14756 - 23830 * 2106 + 110) - -1117 + 4037) + 9039 + -6035 * 30949 / 20926) / 23000 / (26086 + 13937 * 6799 - 7465 / -730 - 16644) / (5867 - 22940 * -31956 + -26790 / -19588)) / -30950 / -5556) - (32626 * -17389 * -9809 * 2792 * (13248 / -30365 + (-7364 * 15413 + -19689 / 17418) * 26875 / 20753 * 5034 / -1854) + 1072 - 914) / -3243 - (-4542 / 29764 - -4004 / 14355 + 8078 + 14275 + -22962 - 7526 - -16993 / -16044 / 5097 + 17353 / -2275 * (25880 * 21958) + (-14494 * (10871 * 12547 * (-18271 * -20148 / -6764 - -5681 * 3451) + (12918) + -18041 / -27591 / -3407 * (12515 + -26719 / 5618 * -15439 * 28476 / -27065 * (8050 / -21546) / 10991) * -28460) + (-23139) / (22095 - -26673 + 5021 / -30457 * 29323 * -20665 + -14942 + 17844 - -24275 * -14333 * -8716 * 16863 + -23421 * -10539 - 5057 / 19838 / 16340) / 25155 + (-14893 * 18997 - (20267 - -17458 - -31894 / 30057)) + 13868 + 20957 * 28499 / 7267 / -25193 / 17288) / -5659) - 26902 - 26578 - -20967) - 12319 / 18293 / (-19404 - (-17349 * (-6394 / (-816 - (16653 / -1725 * -8589 / 30284 - -436 * 25447 * 31434 - 20137) * 15166 + -7425 - 21649 * ((15177 - -18532 * -11869 / 24862) * 16750 - 26463 + 16067 + -22363 * 10952 * -29108 / (-29923 * 16306) + 25666 * 24735) - -14158 * 26547 / (2425) / (31692 + 7996 - -31977) / (-23897 + 26528 * -20557 - -26704 * -8810 + 12605 / -11972 * 32680 / (-23320 * -15859 * -28973 + -18025 / 26927 + -24584 + (8286 - 16361 / 8191 * -23344 - -30513 * -29745 * 30676 + -25903 + 13774) + -31759) - 29091 - -12465 - 26724) + 16247 / (-17505 * -361 - (-19165 / 10124) + 24281 + (-11424 + -22667 + -21241 * 3588) - (9413)) * 25983 + -4269 * -10736 - 6371 + 7124 / 13533) / 23450 * -17641 / -18815 + -5095) + 4628 * 8248 * (17806 * 16440 * -13990 * (15361 - -18221 - -17275 / (-4299 + -28009 * 20570 - -25787) / 20364 + 1882) + -29345) + 29278 * -10085))) + -24677 - -12635 / -18038 - -13516 + 21429 + -19375 / -29228 - 16740) * (-7309 / (8791 * -2892 * -917 + 12782 * 28125 - -16655 / -16521) * 29963 - 10195 - -9758 * -19451 + -18385 + 17848 * -28868 / (-117) + 5628 / 32477 + -13844 * 13285 * -9090 / 11881 / 23519 * -26970 * -529 * (-22359 + ((14484 + -6665)) * -11184 * (21661 * 5116 / 15398 * 21051 / 14085 + 32552 / -7472 / -28166 + -16815 * -15142 - -5338 + -1818 / 7149 + 15221 * 13629 * -26427 + (-23576 * (-25707 + 17353) / 26886 / -5080 - 18051 - -16505 - (-16844 / 30417 - -7514 / -32261 * 11738) - 18509 / (17640 * -28695) + -10418 + -8968 / -17074) + -27925) / 31908 * -8006 * 27145 / 17593 + 12113 / (6421 * 25028) / 18731) - 16726 / -13261) / 14119 * (14923 - -9709 * -20606 - -4738) / -21095 / 9007 * 16377 * -5850 * -22161 + -18685 * (32622 - -20366 / -23557 - -15091) / -25453 + 31096 / -2533 / (-26467 + (-9384 / 18212 / -4693 - 12383 / 16980 + -28112 - 18556 / -9495 / 25375 / 3772 * 8660 / -21184 * ((-2007 * -4696 + -15924 + 32041))) + 1312 + 20471 - -21843 + 20782 / -13786 * 23432 - 32100 + -6571 - -19848 + -19030 / 15884 / 8485 + 23909 + ((16773 - 15305 - 7122 + (-26014)) / 19073 * -1931 / -10737 / -22239 / 24553 * 20682 - ((9140 + 16449 * -32012 / (10892 / -15128 / 10559 + (-16005 / -30593 * ((-22566 + 31162 * (-18775 / -27752 + -10033 / -14584 * 15130) / 21763 * (1635 / -6831 + -29726 / -16391 + -25911) - 5907 * -16403 * 7964) * 19797 - -311 / 6655 * 13969 + -13033) * -846 - -13079) + -15030 - 32346 / -1143 + -32286 + -14905 / 14343 / -19922 * 14552 * 4554 / -6139 / -23086 * 13205 / 169 * -18083 * -24106 - 3796 / 15195 + (16271 + -16002 * -16363) + 5439 - -5817 / 13326 / -9278 + -32019) + 32762 - -12102 / (-1790 / 30687 * -14470 - 26330 + 4804 + 18388 - -20037 + -3471) - 28042 - 1324 + -41 / 27169 / -29886 + 18389 + -25044) - 20007)) * 25894 + 20797 * 298 * -23421 + (22209 / 19047) + -1127 * -25561 + 15335 * -13006) - -6585 / 6389 - -18327)) + (2728) + -26732 + (-19077 - -12047 + -11313 * 25288 - -28638 / -16482 + -30061 / 17049) / -23664 / -17218 + -18230 + 4865 / -32669 / 3455) + 3763 / -21090 * 3753) / 26668 - 25357 * 23630 + 10373 / 5008) + 312 / 2895 * 27005 - -4519 / -17339) / 1883 + -3054 / -731 * -31970 + (-7675 - -5502) / -24324 * -5288 / -29253 / -18246 - 23807 * 26650 - -1347 / 6936 - -6909 - (-18405 / -3299 * 5796 + (12578 - 3899 - -280) * (-4824 + 22133 - 28011 * -30585 / -24286) - -31669) - 1292 - 4824 - -16650 + 10756 / -5692) + -27184 + -20184 - -14241 / 26722 * -12376 - 15841 + -11612 * -10071 - 8211 - -20806) * -5286 * -25931 - 16589 - -25320) - -26789 - 5116 / (13437 - -3102 / -31058 / 5773 - (-2493 - -18073 + 9181 / 4237 * -29608 / 29579 + -30036) - 334) / 19653 * -1175 + 30108 * -27200 + 3412 * 30090 * -21383 * 7016 * 23260 * -1465)) * -25003 * 22192) - -1970 - -13127) - (-13022) - -24461 * -16660 * -27171 / -27436 - -29747)) + 1) * 2188 + -20717) - 25496 * 6366 * 13894 * (29104 + -26332) / -16110 - 15918 + -13848 * -16062 / (13557 * (((9066 / 9300) + -14070 + 8553 * -1837 - 23363 + 2067 + -32379 / 28505) * 20106 - 83 - -12624 * -29306 + (14518 / -27434 + 21783 * -13187 / -23210 - 11007 + 1140 - -21599 * 26750 / -31592 + -32742 / (-17731 / -4500 / -4892 / 8159 * -22686 - -29115 * -12209 - -8478 * -8120 - -31876 / -11870 / 18616 + 32374 * -26472 * -25675 * 25540) * (-6875 / -30713 + -30058 / -3790) / 17942) - (-28600 + -15903 * -457 - -27266 / -4414 + -24901 + 27957 - 5394 + -17184 / -21433 + ((29733 - -6841) / -31696 + 15970 / -12986 + 13784 - -20232 / 24883 / 19509 / 8693 / -868 + 16418 * -7119 * 28477 + (-8462 + 4492)) + 19790) * -27966 / -5808) * -11377 + -30699 / 14156 * 6540 + 9059 / -15631 / 30231)) - -32235 * -20993) - -26080) + 5897 * (-17374 * -32645 * -16860 + 12743 * 14187 - -32343 - 15139 / -13872 / 29192 * -657 - 19424 - -690 / 26687 - (26665 / -14590) * 31449) - -24737 - 828 / -1794) + -21572 * -16033 / -32481 * ((28925 + (6235 * 11185 + -16181 - 15202) + (-17201) * (-7396) / 26930 - -8596) * (-10158)) / -21203 * -5254 * -7008 + 6657 * 26419 + -6620) + 9093 + 13561 / 28806 - -15563 + 30708 - 3595 + 10846 + 15665 - ((15604 - (13308 * -31486 * (-32681 / (-22091 + (-4954 / 28480) - -26081 - -32220 / 11961 / 4181 + 32706 * 6046 * -10875) + -12170 / -10183) * -4044 / 29464 / 23228 / (18570 / 17586 / -32304 + -27627 * 20885 - -30382 - 30227) + 20722 - -29674 - 11405 * -27887 - -6385 / -16042 / -31599 - -14058 / -5140 / -22271 / (-15911 + -24359 / 16114 * -25972) / ((-29732 * 20552 + 2851 * 22246 * -24720 + -24805 * -13930) / 24439 + 32598 * (-2415 * 1851)) + 30931 * 8331) - -3081 - -27283 / (((-15967 / 20142 - (5405 * -11570 - 24467 + 26157 + -4690 - -31091 + (18286 / -12347 + (5606) / -9786 - -16033 / 32519) * 31174 / -27671 * -20148 + -5613) / 30838 / 16540)) + 1) + 7520 - (23949 / 22985) + -271 - -10031 * -3406 / 17309) / -28580 / -11247 / -21893 + 30559 * -17025 - 3259 - (29350 - 14761) - 216 * 24739 / -9932 * -3935 - -19360 / -5960 - 4545 + 2938 - 2264 / 8839 * -6615 + 11773 * 19871 / 6393 * -9760 + -15547 / 22882))) * 5517) / -13195) + 22946) * -31148 * -25178 / -9336 - -16334 * 17679 + (-6169 / -31851 - -6971 / 10237 + 14303 * -29841 + 24053 + -6489 - 32147 - -4835 - -14667) + 27908 + -14784 * -9682) + 1860 * -18524 - -29780) / -8514) * 4346 - (11111 * 1765) + (31143 * 25674 - -21881 * -14345 / -882) / ((-1864 + -3560 / -22622 + -22045 * -25391 / (-9521 - -6860 + -11961 / 32727 * 12244 / -6247 + 1597 / -30440))) + -9838 * 3511 / (24727 + -23685) * 15460 / 19432 * 8432) - 30483 + -11107) / 263 - -15171 - 5066 + -5793 + 996 - 28244 + 478 / (-22672 - -9538) * 2622 - 15301 - -26793 * (-6971 / ((-17080 * 16018 - (-23075 * (-17491 - 12611) / 15861 * 773 - 18048 - (-3585 + (31248 * -5364 + -10042 + -30927 - 30029 + -25746 * 6814 + 26319 + (26008 * -25934) * -4197 + 2614) / 7822 / (-14429 / 22339 - -170 / -19520 - -9491 - -7040 * 8129 * 2458) * 17425 + -11186 / 17468 * (31560 * -12314 / 161 - 21410 * 5635 - -9659)) + -31643 + 12022 / (-18206 / 8400 - -20341 / 23728 / -11155 / (-8219 / -20911 * 30772 / 12218 * 31309 / 23712 - 11183 * -8484) + 26354) + -14614 + 160 + 19123 + (-29937 * 22540 + 26908 - -27186 + -15031 / 12006 - -26441 + 17486 * -19360 - -10497 * 18306) / -22209 / -12777 - -14839 * 1232 / 31134 - -8950 * 24990 + 4445) / -1980 * 4740 + 14585 * ((-3252 + -7113 * -26170 * 26321 / 20274 - 2090 / 13500)) - 31502 - -7455) / 24830 - -2396) - (-4576 - 5115 - 7216 * -13277 * 28699 * 12247 - -3259 - 29518 - 9508 + 2246 / (15612 / -5002 / 12954 + 11472) + 10052 * 15929 * (3035 / 31491 / -24036 - 14846 - 18546 - -28533 * 23637 / -28049 - -25190)) + 896 + -28719 / (20297 * -32678 + 8043 + -31149 + 22395) - -21188 + 21059 - -28107 * -1477 * 2583 + 12951)) * (2531 / -31555 + 24389 * (-31652 * -26051 * -16748 * 15701 * (21362 / -26824 + -11605 * -22227 / 1381) / 6020 - 17017 / 22038 / -9424 * (27429 / -5558 + -21584 + 8458 + 13039 / 86 * 28075 + ((28290 * -30912 / -12874 + (20779 * (-18650 + 13576 / 31435 - -2274 - -19277 / 5243 / (3971 / -20122 - (-12438) - 10687 / 20504 * 4303 + -18607 + -10881 + (-6211 * 26362) / 402 / 4118 / -12160 / ((-23251 * -14084 / 26759 - 6497 * -12444 / 25298 + 8223 / 14839 - (25659 * -1349 - -22232 - -19620) + -6876 / -7343 - -1272 / -9382 + 7589 * -16022) * -10048 + (5051 - -31175 * -1181 / (28855 + -28306 / 30428 + -15400 + -11818 * 15822 - -12181 / 11205 * -22486))) * 25382 / 18391 + 1457) * 12416 + -9949 + -15389))) / -1581 + 6291 / (-28474 * (12115 / 18522 / (-24147 * 4944) * -20685 - 1016) / -26369 / -173 + -24549 * -13960 - 14179 + -26878 + (21571 * 10158 * -30718)) - -18079 + -9889 / 17863 - 32086 + 32327 + 11663) * -17745 + -6516 - -779 * 17692 - 19471 + -2572 + -12362 * 23023) - (25093) / -29527 + 25340 - 29584 + -10494 * -18389 * -15928 + -11535 + -4000 / -25890 - 7829 * 16026 / -19059 - 4920 * -18699)) - 24451 / (30624 / -12710 - 25010) - 9431 + 15793 - 3271 - 8692 - (-21075 - -8370 - -5640 / -29221 / 17570 + -18092 + -26570 + -20505 / 29448 + 10624 + 1081 - -1567 / -28399 - 17087) * -31433 / -13214) + 20247 / -15863 + -22150)) + 13749 / (30321 / ((-7482 - 792 * 18474 - 18964 + -19173 * -27373 + 27925 - 17442 * -25464 / -29461 + 12059 - -3356)) - 23535 * -934 / 30363 / 9074 - 21595 - (6368 + -32667 / 19705 - 11790 - 24074 + 3652 - 22146 - -10199 + 31962 + 4491 - -22451 * 14954) * -27566)) - 10380 - 4835 / -2959) * -26293 / (16020 + -31582 + -31472 / -8078 / (19431)) * -6778 / (32599 - (21966 * -24450 + (-18899 + 10531 + 20639) - (25899 * -30590 - (168) - 19932 + -20418 * 3671 - -30854) + -27286 * -19083 / -25379 * 3327 / -23485 * 28592) * 31837 + 16229 + 856 - -16994 - 10289 - -23864 / -24903 + 6968) / 4150 + -26626 / 2868 + 21167) + -4400 + -28341 * (2331 - 606 + -11654 + -9210 + -1073 * -22392 * -23979 - -15075 - -20431 + 5938 / -18919 / ((8922 / 20887) + 1) - 11581 / -14854 - 26159 + 2036 + 22722 * 770 / 18876) + 8734 * 26266 * (17960 * -12011 * -14475 + 12125 / -29057) / -28190 * 1447 * 17833 * -6749 - 20757 * -15109 / 20656 / 8303) * (13436 - 3576 - 5404 / 4849 / 24929 / 12133) * -28542 / 27539 / 7360) / -24767 - -17772 / 6711) * 21972) - 9923) / ((-11310 + 18894 / -21603 * 21228 * 25893 + -24567 - ((-21973 + -17804 * 12869 - -18223 - 16837 - 32494 * 10523 - -15959 * -6253 / -494 + -19984 + 23266 + -25622 / 20744 - 20914 + (18161 + (-14839) / 20129 - -409 * (-26258 * 16616 * -28364 - 24516 * 31275 / 1025 * -8775 - 9869) + -1261 / 9598 / 25664 * 26046 - 18288) + -6843 / 14906 * 5928) / -5882 * 30) - 18187 + 16130 * -11180 + -19932 * -7683 * 23970 + -11319 / -20168 / 7327 * -7456 - -4400) * 14669 + 15471 * -5260 * -9998 + 19 + -14821 / (-3046 / 8394 / 15497 + -9060) * -8007 + 24905 / -20052 * 7017) - 19864) - 14443 - 31 / 28562 - 7585 - 30125 * -14277 / ((-10555 + 30318 / 18671 * -13231 - 11062 / -17701) / 2480 * 4029 / 3961 + -14720 * 16557) + 16024 + 7063) * (-23044 / -9493 * -4063 - 31543 + 18986) / -4908 - (19926) / 15035 - (-473 + (31299 + -7281 + -8787) * 6568) * -2138) / 20263 + -31324 * 13882 + 9512 - -9995) / (-7128 - -14273 + 31322 + -26769 * 18175) / (28741 - -23027 * -28768) * 5980 - -10074 / ((-4955 / -9134 / (-6007 - -30053 + (-26589) - -16640 * 9850 + 26032 * -23881 / -8705) / -12428 / -56) + 1) - (-21496 - -21387)) - 12912 * 11293 - 6509 + (((10247 / ((31514) / -11535 * -14429 + 4519 + 25061 * (-25300 + -14063 / -27458) + 25832 - 13513 * -23935 / -20546 - 30060) - -13212 / -18032 * (-7217 + 21466 / (9466 * 14948 * -17361 + -30104 * ((21264 + 28738 - 16347 * -8089 / 27467 + -327 / -16975 * (26042 + -8067 / (-9090 / 17958 + 3999 * 26870 / 10682 * 14067 + -19535 * 30661 + 13517 - 8566 / 31363 / 4223 + 5819 * (27734 + 17460 / 10193) + 32314) / 6488 / 7263) / 1467 * -31577) + -29684 + -30909 * 4604 * 13415) * -24530 / -4270 + 16375 * (-16713)) / 21260 / (-2973 - 14306 * 27583 * (-17245 + 25774 - 13258) * 14627 / -9092 - 13381 * 22627 - (27784 + 5731 - -13526 / 24668 - 32005 * 528 * -1323 / 15512)) + -12174 * 14647 / -30764 - 224 / -2975 * -2756) * (6093)) * -12886 - 22538 - -7903 + 22038 * 32686 - -2042 / (21003 + 32248 - (-13346 - 542) * -10089) * 2111 / 4220 - -3974)) * -5254 / 2398 + 25033)) * -9402 * 3216 * 6607 - 1298 * (-15505 - -12731)) * 30659 / 16347 * -4525"#, -]; - -fn parse_chewed(input: &str) -> i64 { - IterWrapper::new(input.chars()) - .parse::<nibble::Ast>() - .unwrap() - .into() -} - -fn parse_handwritten(input: &str) -> i64 { - parse_expr(&mut IterWrapper::new(input.chars())).unwrap() -} - -fn parse_lalrpop(parser: &lalr::ExpressionParser, input: &str) -> i64 { - parser.parse(input).unwrap() -} - -fn bench_parse(c: &mut Criterion) { - let lalr_parser = lalr::ExpressionParser::new(); - let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); - let mut group = c.benchmark_group("Arith"); - group.plot_config(plot_config); - for (i, input) in INPUTS.iter().enumerate() { - group.throughput(Throughput::Bytes(input.len() as u64)); - group.bench_with_input(BenchmarkId::new("Chewed", i), *input, |b, i| { - b.iter(|| parse_chewed(i)) - }); - group.bench_with_input(BenchmarkId::new("Handwritten", i), *input, |b, i| { - b.iter(|| parse_handwritten(i)) - }); - group.bench_with_input(BenchmarkId::new("LALRPOP", i), *input, |b, i| { - b.iter(|| parse_lalrpop(&lalr_parser, i)) - }); - } -} - -criterion_group!(benches, bench_parse); -criterion_main!(benches); diff --git a/chomp-bench/benches/arith/data/1066.arith b/chomp-bench/benches/arith/data/1066.arith new file mode 100644 index 0000000..6636cca --- /dev/null +++ b/chomp-bench/benches/arith/data/1066.arith @@ -0,0 +1 @@ +-3702 / -6527 * (21650 - 30878 / -16053) * ((-27738) + -10405 / (28028) + -27946 * 11853 / 9995 * (12242 / 19864 + -3983 / -17383 / 24277 + (-25049 * 3811)) * (7738 / -30356 - (15771 + -24122 + 20235) - -1286 * -14431 * 20212 + -9632 / ((4912) / 25444 - 29835 + -1371 + 1684 * -16178 * -3620) * 1965 + -26188 + -25529 / (-31105 / -15380 / ((5700 + 20005 + -2884 - 25243 + -22469 - 5923 / 31855 + 631 + -30564 / 15911 / 2145 / 23146 - 10595) / -16740 / -31327 - -30899 * (27984 / 3269 + -23191 - -28688 * 8627 / 1124 * 25978) * 29991 * -11660 * (43 - 13615 + -14069 * 1794 / -23857 / ((-27289 / 8473 * 13714 * -17557 / -28653 / 15220 / (-20965 * 16822 / 18335 / 30505 * (-29766 / 27525 - 26431) + -1597 / 26109 * ((18233) - 15258 * -1222 + 13992) * -22684 - (32150 * 16543)) / -14948) + 1) / -5206 - -20944 * -10476 - 3481) + -18244 - -21630) * 3726 - -11142 * 3294 + 32359 + 1556 / -6674 * -707 - 16822 * -1006 + -3503)) * 7863 * 7347 * -22972 - ((-12006 + 8695 / -12530 + -14941 * 3203 - (-12244 * 1257 * -27925 + -2966 * -30371 + -22680) - 30152))) / -11978 / -210
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/134.arith b/chomp-bench/benches/arith/data/134.arith new file mode 100644 index 0000000..4f6e64b --- /dev/null +++ b/chomp-bench/benches/arith/data/134.arith @@ -0,0 +1 @@ +(20271 / (22939 / 15971 * 552 / 11046 + -24515 * (4540 - 11399 - -28093 * -10078 / (-29566 * 26980) + 19390) / -5419 + 28124 * 18839))
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/17850.arith b/chomp-bench/benches/arith/data/17850.arith new file mode 100644 index 0000000..332dba9 --- /dev/null +++ b/chomp-bench/benches/arith/data/17850.arith @@ -0,0 +1 @@ +(24074 * 26564 * -20104 - ((26092 + -10334 * 26643 - -21713 + 17119 - 8287 - -20065 / 15303 / 27714 / 21595 + 8040 + 28948 + -28961 + 8116 * -27636 - -14253) / 25944 + 22890 + 23799 / (21367 * (22537 / -30308 + 10696 * -4919 - (619 * (-409 * -29384 + (6718 - 27903 / ((7938 / 11588) + 1) - -2512 + -25155 - 8777 + 22547 * -988 + 8767 + -2636 + -5732 + -17106 * 12876 / -20192)) + 28886 / -18221 + -28137 - 21286 + -24969 / 16225 - 28931) + -13325 - -21181 + (17619 + 3059 * 22029 + 21053 + -21598) / (24453 - -6622 * 12678) * 6154 * -28840 / -11565 + 16839 - -22488 / -29677 + 21812 + -3295 * 7424 / (17667 + -26394 * -18812 + 25232 * 14062 + -13542) + -10682) / -21316 * 10977) - -10770 / (28851 - 27884 * 11207 - -18436 / (26617 + 25316 / -20595 * (22559 + -13100) + 4119 - -5944 - -1971 / 15245 + 17703 * -17524 * 20950 - -21541 / 18825 / -24153 + 9168 - (-7712 * (18090 * -22330 / 3790) - (13387 - (1850 * 15426 - (4068 * (16627 - 9372 - 29881 + -7905 / 2188 * -2931 - 26998 * -21455 + -4846) / 3486)) - -4012 / (-2672 / -25870 * 22541 - -18673 / (-28707 + -7534 - -10373 - -9818 / 12315 - 10409) + -10645 - 22468 * (28471 / (-28272 - 12139 / -5149 * -4495 * (4972 - 25293) * -10109 + -17908 + -22578) + (-8136 - -4522 * (18551 - -24302 - -26888 * 13048 + 20196 * 6861 * -11828)) - -4663 + -2761 - 25071 + 4940 * -27684 * -3406 * 14103 * 11448 + 21839 + 30364 + 5757 - 18440 - -26834 * 9810 * -24370 - 12780) / -6317 / -6059 * 17036 / -1052 / -3437 / 8020 - -15839 + -31695 * -9953 / 26930 / 9173 - -19760 / 26510 + -20065 * 27084) + 3163 / ((-17303 * 23442 * -11781 + 17246 - -4764 / (-5721 * -16258 / -10979 - 11372 + (2070 * 64 * 24851 + -1157 - (6085) - -24026 / -7815 * -19608 * 176 + -9192 + 13703) * -25131 / -27418 + 26593 + -30678 + -17757) / 12012 / 16284 + -21750 + 30874 * (24527 - -14650 + 15210 * (-5220 - (-10260 - 3717 * 23789 + 22746 / 651 - 21629 * 23552) + 19537 * 31958 / (-13814 * 23131 / -29333 - (-18325 - -24194 * 8519 * 20067 / 27687 - -29021 / (-802 - 2474) / 5866)) + -9959 / 15002) * 13934) / -24424 / 9026 + (-16208 - -7277 + -17658 + -12057 + 20427) * 19843 / 25237 + 22514 / 19328) - (9735 / 30222 - 26628 - -1062 + 15966 / -24030 / -16352 / 24136 * -23417 / -5731 + 12905 + -22401 * -15881 + -4119 / (18017 * -15321 - -32280 + 16794 + (-1372 / 16253 + 13899 * -11929 + -6711 * (-21472 * (27729 - -4714 / (12406 + -8496 + 10932 / (-16166 - -1532) / 5021) / -10541 + 17722 / 1274) - 9785 / 5443 + 18236) - -6527) / -21169 - -16309 - -26433 - -1077 - -14557 + (-9443 + -7770 * 5042 + -8184 * 16796 * 23703 / -28093 - (17649 - -30816 - -23383)) - 21293 - (-11072 - -12076 + (-170 + -4704 / -23142 + 19266) / -2097 / -22199) - -17044 + 6107 - 6732 * 11770 / 26286 / 15910 - 11193 / 4527 + -2450 * -24249 + -23756 * 17339 / -22288 * -13503 + (-28743 + (639 / ((-14433) - 24335 / 21451 / -8549 * 6510 * -20694) / 1709 - -23039 / 868 - (-13931 + -5955) + -24796 / -29495 / 30187 / -13700 - 19478) - -12748 / 2675 - 23674 / -10830) + 30465 * -18613 - -28822 + (3805 - -3893) * -27922 / -17448 * -10626 + (-8771 / -8197 + -26511 + 32541 - 24230 / 32462 + -10722 * -18945 / -25695 * 2899 * -29826 / (-3963) / -12382 + (24488 - 23680) + (1705 + -30387 * 23419 - -28055 - 2355) / (28480 / -12138) * 11266 / -672 + -3734 / 263) - 26180 * 11443 * 32042 - -26213) * (-8354 / 17634 * 8308 + (30093 / ((16920 / -29423) + 1) + -6000 - -12388 / 16762 - 4258 + 21972 / 4181 + (-10372 * 26998 + 4353 + 29862 * -4003 / (19942 + 21488 / 32164) / 19430 / -22059 + -32515 * 23819 - -28846 / 21317 * (-32478 * (-31428 / -21795 - 6585 - 8351 + 13192 / 28531 - 7169 / -31055) / -22057 + 8811 - 10957 * 32282 + -20310 * 31267 - -24521 + ((11989 - -25258 + -20684 / 8968 - -28362 * (-16723 * 28204 / 3028 * ((-15633 * -12340 / 27031 * -18240 + 5215 * 15835 * 1808 + 6182) * -10696 - -16464 / 20749 * -10965)) * -29 * -8225 * -19490) - 31989 / 4290 * -11887 + -8637) * -10471) / -17895) - -24298 * 26971 - 24952 - 12544 + -15034 + 381 + 22553 - -20820 / -14093) / (17285 + -25737 * 6485 * 19060 / 27515 - -16376 + 23179 / -23697) / -27174) * -30626) / -792 - (-29674 * (-5520 + (-14272 - 11027 + 8403) / 5076 * 30642 * 10333 + 28054) + -28663) - 30668 / (29888) * -22584 / 24534 * 22387 * -21488 * 4035 - 15976 / -16963 - 31201 / 8357 * 4902 + -22369 - -30359 + (-652 + 26781 - 20469 + 11647) + -27150 * 25136 / -4005 - 9162) * 29441 + 23352 / -2728 - -2330 + 12688 * 28182 - (30565 + 7139 / 19181) + 4397 - -21834 + -30711 / (5175 * (7661 - -5755 - -2516 * 392 * 2989 / 15764 / -14464 - 17374 / -2437 / 4755 - 21735 * (20599 / 11407 * (-29773 / (-30325 / 14665 - -1876 * -3042) + -100 / -1497 - 12895 + 2753 - -28834 * 14275 / -30935 / 3816 - 10400 - 7551 * -31631 + -3781 * -6502 * 31622) + -6483 * -23546 * (7154 / 12576 * 30485 - -30017 * 16207 - -24286 - 29932 * -10797 * -16976 + -20402 / -13725 / 30211 * -9941 / 6138 * (-3098 / -15019 * (-31836) / -29333 * 13691 + 4689) + -24565 * -8435 - -5659 / -28390 + (5635 + (-27778 / 11838 * 7178)) / 16906 * 21687 * 7636 / 8570 + -7358 * -17416) / 16222) * 10175) * 17872 + 14477 * -6058 * 16409 / -12673 - 29922 * 12318 / 15042 - 26533)) / -22580 + 28809) * -23526 + 31995 - -28925 / -12114 - 20239 * 27152 / 29400) + 13631 + -6217 / -26771 * 18383 - -7823 / 18890 / 20250 + -18088 * -252 / 8032 / (21990) - 6743 * (-3779 - 1857 + ((-17612 - 11989 + -14606 / (-24900 / 11083 + -2747 / 9102 + -6123) / 31761) - -7762 * 17253 * -21893 * (8334 / -13531 + -21313) + -18737 + -15535 + 14019 * -20593 - -25977 * 6643 * -6651 - -12443 + 16123 / 16425 * -7221 * (8308 + 12696 / -8150 + -7273 + -7006) + (8142 / 2606 / 10281 / -21199 - 926 * 19257 / 15914 / -8956 / -30191 * (1438) / 7257 * 27775 / 24740 / -23808 * -3554 - -906 + -14123 - -29551 + -11816) / 4024 * 16565 + (-23578) * -4610 * 7420 / -24962 / 15233) * -11037 - 19246 * -23669 * (-29734 - -24124 / -2887 * 4444 / 30676 + (14594 / -14376 / -31449 * -16083) - (-5199 - 30358 - 18154 / -5900 - -29741) * 10556) - -27430 + -32454 + (30578 / 15508 + 21512 * -28020 / 13882 / -6797 - 10461 + 11697 / -30772 * 20158 * 5562 * (27905 + -210) * -31117 * (-16688 * -22720 + 26773 - 18134 * 16559 / -12779 - -3403 * 18512 / 13511 + 6 - -20803 - -11823 + -13623 + 5645) + 10809 - -6548) / 1158 + 20777 + -388 * 5499 + (-528 / (-19574 / 24653 + -13487 - 29099 / 21003 / (-7289 - -7216 * -10195 + 7408 - 5907 + 16636 - -12129 / -1025 - -724 * (-15765 / 14119 + -17202)) * -4287 + -1099 * 21420 + -29208 - (-26546 + 6563 * -17851 / -18302 * -26039 * -1748 * 26599 - -20472 / (-22046 + -22727 / 28273 / 4927 + (6451 - 7216) - 24348 - -19729 * -16658 * -25856 / 26215 - -23519 - -29991 + (-11090 - -2630 / -28072 - 13451 + 32397 + -26539 + -3118 / 5826 * 2913 + (-30526 - (-4338)) * 4367 + 11620 - (-28649 - -18304 * 26427) - 9884 * -2700 / (-12637 * 14779 / -6630 - 21156 * -18702 * -19549 + -2870 * 11226 - -22290 + -20844 + -19986) + -9866 / 8727 - 13719) * -21739) * 24469 + -9340) * -7093 * -13803 - 8060 / 1174 / -5832 / -22827)) / -6605 * -16426 - (-19695 / (8515 / ((-5890 / (-26635 - 317 / -2603 / 8459 - 4554 - -19042 * 18323 * 11809 / -9534 - -2244)) + 1) + 32630)) * 1804 / 16748 / (-19288 - (28558 + 31848 - 26230 * -2756 * 5861 - 5196 - 16203 * -10780 + -1358 - 8775 * -32197 - 5178 * 29944 + ((-26591 + (26408 + -17951 - 31635 / 5196 - 32415 + 23870 - 17385 / 1258 * -18017 / -5822 - -25210 * -9185 + -5099 / 25675 + -13962 - -7695 / -32340 / 12040 - 25970) / 16605 / 27976 - 21278 + -18101 / (-13688 * (-9477 * (3222 - -16250 - (3896 + 29487) / 258) + -18308) * -21962 + -11052 * (-6445) * -23671) + 22030 + -23474 + 20070) / 18917 + -9815 * 28949) / -29495 - -11297 - -24266 + -29706 * -21557 / (12855 - 30017 / -6613) * 30555 * 26969 / 5215 / -17945 + -18604 + 6792 - -12018 + (10503 / -24872 * -18323 - 11814 * -25827 - 8326 + -11784 * ((27596 - 27242 / (-8866 + (((13188 * 3897 - 23985) + -9815 - (-18590) - 3058 * 24593 / 5554 + -21755 + -8120 / 7186 + -10369 + -1663 - -29901 * 7044 - -10954 + -17554 * 6493) * -7963 - 579 - -23612 * 8229 / 7128 + -1684) - 19792 + -8720) + -9119 * 31200 + -31018 + (19421 / -14872 - -8262 - -4055) * -6110 * ((-32307 / -11029 / (-15447) - -26107 / -31486 - -20147) - 17017) * (-4003 / -11358 * 24858) - 24428 - 28710 - -5812) / -20441 - 28710 - -10159 + 13676) * -29614 / -20499) + 17021 - -17875 - -25776 / -2394 / -31856 + -12055) * -8065 * -28328 + -23707) / 30185 + 4060 / 1064 * -5872 / 5153 + (-21825 / 10522 * -6072) / -17633 + -10254 / 14490) - 28413 / -29028 + -1096 - 7534 / 8861) / 17759 + 19732 - -18204 * -12995) + (-32233 * -27262 + 532 - 5611 / 25153 + 22073 - (13726 - -18279 / ((20575 - -1206 + ((-28005 * 26064 / ((-3501 + -30905 / 5233 - -26229 * -9614 + 14749 / -7745 - -9387) - 22499 / 22793 + -29810 + (6060 + (13342 - 30368 * 26866 / -29171 + 26) - -3678 * (25200 - 7587 - (15897 / 17765 + 16172 - (-30838 + -2913 / ((-3580 + -32720 / 27676 / -27502 * 1074 + -6408 / -31426 - (12583 * -20145 - 4495 / -18152 * 22516 * (-9378) / (-26646) * 12493 + -30828 / 24784 / (21081 * -2746 / 22047 - -2215 / -15005 * -20516 + -16181 * -4404 * 20332 - -30035) / -7956 * -5780) * 17729 + -27188 * 25839 - 10431 * 20886 + -5815 * -25552 / 30837 + -18410 + -5521 - -12275 + -31333 / 4202) / 22613 / 24520 + -27724 * 3870 / (-2230 / 3532 * 13773 + 14456 - 3114) + -16886 - -30411 - -30637 * 10542 * 25858 * -5423 * -28026 * -8861 * 3 + -5755 + 11411 * -8896 / -2743 * -8724 - -28542 - (926 - (((5298 * 41 - 12666 - -25626) * 30584 + -7518 / -765 * -29034 / -14625 / -23719) - (-19891 + 21396 / 22405 * 12266 * (14044 + (-6807 * -5845 - (24651 - -27257) / -19551 * -5747) + -25864 * -29764 * 18702 * 11701 / (-23768 / 9475 * 10179 - -8165 - (7064 - 21797 - 25144 * 29584 * 14654 + -16791) * -15087 - (-10520 * 26391 / 32394 + 22444) / (13025 / 6887 / ((-10200 / 27149 / 18291 - -20392)) * 17255 - 14777)) - 15398) * -15972 + 30315 * 14347 / -17102 / -26893 * -32118 / -3152 * (-12293 - -26425 * (-15525 + -9232) - (17123 / -31232 - -21030 / 28626 * (27153 / -9941 * 6924) / 27454 / -1642 / (-28306) * -2709 - -28776 * 18843 - (-22031 * 5835) * -20148 + -26090 - 1351 / 30753 / -28971 - (-2027 * 14211 + 12201 + -29450 / 28029 * -10818 - -30005 * 20182 - -2657 - -11185 / -20962 - 18392 - 19874 - 13687 + -11440) - -29661) / 29456 - ((20060 + ((24943 + 28507 / (31112 * -30884 / 5049 * 11727 - -2004 / -31347 + 22702) - 24626 - 5167 / -7962 - 2651 + (-7274) / -29281 * -1624 / -11630 * 28347 * 25824 / 11446 + -5857 / 11846 / 27433 + -1305 + 26838 - -20841 - 21696 * -31494) * 22879 - -3630 - -11751 * 23149 * -12458 / (24269 + 7398 * (16702 / (5077 * (28800 - 27117 * -10710) - 28543 + -16897 - -4355 + -7245 + 9527 - 12844 + -20377 / (-13059 - ((13967 - -32583 * -3478 - -17722 * 3804 / -8681 + (-20737 + (-17569 + (-12770 - 1339 + -17896 / 5036 - -12502 + 6597 / -32221 * (-1069 * 2911 + -24129 + 16555 * (30984 / 32505 - -21223 - -22681 * -14033) * -20202 + 12268 * 22951 / -27450 + 29633) * -25982 - (-4936 * 11640 * -28940 / -31049 - 19518 + -23687) - -5884 - -7223 / 28442 * -13350 * 2257 * -13806 / 9557) + 3130 * -13572) * 9553 * 32285 - -28862 * 28191 * 4232 * -23231 - 22826 * -15229 - -15687 / 27662 - -8883 + 19099 - -8637 - (-32543 / -18664 - 29355) + 29451 / 23022 * 13986 + 8936 / (-506 * -19272 + -2 - -15256 + 21492 / (-29507 * -27990 / -26885 - -18293 * -14421 + -15616 + 29077 + -10947 / 13016 * -2634 / -15022 / 26075 * 6821 - -17638 / -7986 / 27761) - -233 * -24928 + (11183 - 19998 * -7431 - -1419 - -25743 / -16062 * -2252 + 22710 + (-18349 - 14196 + 21447 + 8120) * 26981) - -30635 / 11543 * 5879)))) - -27140 / -6349)) / 25620 / 27177 / -30681 - 15057) + 15570 / 28865 * -21428 - 11658 * 10197 * -2282) * -18656 - 26635 + 20177) - -16781 / (31006 + 10580 + 30866 / 22750 - 4801 * -543 / -18979) / 11246 + 21141) - -5284 / -2477 / -31518 / (16083 + 23490 + 22126 - 29438 - 25928 - 20331))) - -32653 / 26563 + -20611 * (2669 / -25176) - 2414 - (-1389 / -10438 / -1294 - 5897 / 23216 + (21282) * -25941 + 16685 - (-17027 + -24913 + 26927 * -16324 / 21930 / 7161 + 1313 / 9437 / (6146) * -30975 / 23622) * 5168 / 22856 - -17665) / -7079 / (21202) * 27082 + 15352)) + -19944 * 2395)) - 23082 + 26665 / ((-7715 / -30529) + 1) / 7704) + -31535 + 16947 / 24343 * -29130 * 9617 * (-18372 * -18581 + 18430 * 18969 / 13615 / 22197 / -6279 / 384 / ((5924 / -24919 * 6922 * (-6181 * -3050 / -3752 - 30229 * 14685 / -28727 + 15409 - -15384) * 22186) + 1) * 11205 / -20320 / -995 + 13419 * 8146 / 7154)) / -12998 / -10861 + 8511) / 812 + 20817 - -12544 * 31581 + -20054 - -7958 - -23239) * -17150 + 15156 / -22884 + (16474 - -27357 / 30475 + 14466 * 28619 / (-2189 * 4433 * 19230 / (-23148) / -20078 - -26673 + -7694 * 32379 / 5666 / 13177 * (-16630 * 18553 / 6065 - 11668 / -30338 + 21236 * 21123) / -1676 - (((21305 + -7105) * (5445) * -12639 / -6865) - -31703 - 7323 + 4367 + 17515 + -5137 * (-31172 + 113 / 12147 * 24875 * 16717) / 29380 - -1367 + 1335 * -13042 + (5021) / 27281 - 8451 / 5446 - 1031 * -6831 + 16581 * (12953 - -12816 - -24667 - 2865 / -22505 + 12127 * 27389 / 5035 / 11288) + 31151 - -6815 + 4063 + 38 + 32559) / 25403 - 21781) / 29055 - -2890 * 21038) + 15493) / -11644 + -27567 / 10158 - -20571) + -32067 / 27298 / -12125 - 14785 - 23060 / -17060 + -300) - (3305 / -24052 / 13207 - -18958 - -23176 / 18648 + -6447 / -486 / 30288 + -27928 / -4947) / 11939 + -26480 + 29192 / 6704 - 29927 * 3959 * -23026 + -6716 + ((12400 / -19149 / -20745 * 18203 - -15786 * -22274)) - 29361 * 949) * 29933 + -4935 - (-22473 - -3797 - 26609 / (-32611 + 12635 + -3563 + -31444 / (30727 * -25099 + 29679 / -3748 - -16806 - (-26701 + -2472 / 30813) - (22016 - -3905 - 4844 * 15234 - -25455 / 11209 * (23407 / (-3331) + 21634)) + -28877 - 3116) * 11850 / -28982 + ((14338 + 6174 + -28650 - (-14372 * ((29231 + 10436 / 23893 * 4500 + (-32521) - -9729 + 15566 * -27057 + (-27906 - -4916 / 11479) * -12429 * -27678 + -5505 * ((2327 * (21212 / -442 * 14430 / 32497 + 13733 - -7281) - 28841 - -27960 * -26338 + -13431 - (-16731 / 17879 * -12644 + -11977 / 5063) + (-9310 + 13780 * 10650 / -19366 * (-19042 / 11513 * ((-28396 / 31064 * -152 * 21585 * -11601 - -17535 * -8698 + -27459) * 6619 * -1921 / 24869 - 18310) * (-26362 - -6438 * 7504)) + -26073) - ((28445) - -16036 + -23356 / (10030) - -24888 + (16095 - 6260 / -7722 + -4483 * 26856) * 20873 - -23248 / 30451) / ((6866) + 15119 - 13358 / 27867) + (4383 / -25858 - 12608 + (-9813) - 12064 * 24 - (-15381 + 26514 / 16609 + 5524 / 32453 / 24665 / -17960 * 29758 / -25717 * 29997) * -16059) * (-4367 * 25944 * 21078 + 23715 - (-1275 - 19583 * 23832 - -28590) - -18582 * 20975 + 12358 * 6286 / -23371 * -23783 * -28357 + 24699) / 18894 + -4756 / -28171 / -26321 * -31271 - -3378 / -31964 * -21316 - 12770 * ((-18629 + 29623 - -30367 / 517 * -24756 * -5221 / ((21500 + 29011 + 7587 / -14081 + -26508) - -32466 / 10699 * -19874 - 7657 - -19415 + -7837 * -23304 + -13309 + (32486 + (23365 * -16745) * 28349) * -5816 + ((30753 / -18029 / 4202 * -29111 - 13905 - 2270 * (1079 * 13154 / -20792 + -28907) / -30791 - 12132 + -28205 * 27288 / 4813) + (-20480 * -7369 / -5695 * 20268 * 28371 / -4702 * 15233 - -5104 / -32755 + 30720 * 1380 - -3400 * -14926 * -21242 / -9018 - -6439) * -24890 / 26884 / -21896 * -4249 + 5083 * 18699 - -15960 * -952 - -7138 * -31935 - (-17333 - 11954)) - 539 * -6631) + -8004 * 8885 + (-22167 + 15842 * -14726) / 27494 + (-18007 / -29664 * 32734 + 27511 - -9221 + -19066 + -3911))) - (-14514) - 10999 / 16531 + -1425 - 13057 - 22045 / (21030 + -25585 - (17708)) * 13042 / -9712 * 15833 * (4079 + 7418 + -5680 + -3972 * 20069 - 30183 / 12036 + -20670 - 19542 / 6328 + 20811 + -30888 * -13928 * -17284 / 4483 + -4025 - -20644 - 22694 * -1619 * -18757 - -31290 * -18388 + 20788 + (2405 / -11455) - 988 / 1985 / -2816) + (13066 * -15833 + 32655 * -30284 - -22431 - 583 + 12507 + -18308 - 10920 / (32516 * -4515 - 1315 + -16155 - -8136 + -21727) / -24167 / -18204 * -13725 * ((31945 - -13668 / 28725) / -17924 - 1295 * -29610 * -4386 - 22782 + 3420 - 17968 / -22924 + -11322 * -10685 + 5716 / -11549 + -23907 / -29477 - 17360 * (2691 - -23679) - -21752 + 9870 - -10509 * -4127 + (8131 * -4257) / -30127 + 3926 / -1958 * -30642) * 14634 / 8600 * -23285 + 3875 / 609 - 16197 * -27391 / 18191 * -15488 - -23481 - -32175) / -26169) / -22892 * 7471 * 944)) + -21824 / -4759) + 16256) / 28066 / 28886 / (21921 / -5395 * -29235 / -28393 + 16215) - 19065 - 11921 / -18150 - 32011) / 2908 + 564 * (23685 - 18237 + -13421 * -18485 * (27556 * 10836 * 27456 / -3328 * (13613 / -14866 / -16137 - 17795 * (-31661 + 27350 / 12225) - (14675 + 17577 - (-6334) * 3921 * ((-8645 * 27737 + -6249 * 25570 / (25327 / 12466 / 15737 * -12398 - (-13465 * -21339) * 22253 - -9374 * -13887 + (-11636 / -3713 * 1513 + 16099 / 26433 / 4795 / ((-1804 * -28751) * -24831 * 10257 / 7371 + 14892) * -12926 / -31316 + (31019 - (-3126 * 1582) + -26830 * -5642 * -3446) * 31793 + 277 - 11152 / -17473 / -20281 - 21007 - -32739 / 24222 / -21186 - 26159 / -4232) + 13659)) / -24292 + -11397) + 12976 + 3465 - 11181) - -7346 + 27105)) + -1375 / -14999 * -1813 * -19955) + -13532 / 6926 - 27706 * 7671) * -21183 / -2398 + (14287 - -22693 * -24551 + 12551) * ((-29467 - -5259 + 6166 * 11265 + -11180)) / 3753 / -5717 + 9766 + 14052) / -12339 / -4389 - 15050 / -28009 + -16429 - 5813 + (15398 * (26376 - -15536 * -25723) - 3484 + 30028 - -13415 * 13941 * (-24504 + 8516 * 19720 + -7391 / 6607 + 24627 + -27208 * (26667 / -18141 - 18978 / 29199 + -13410 - 6462 / -22094 / 16674 - 4325 * 3376 / -32567 / 15132 + -557 / -26354 - 925 + -13544 - 5285 - -23633 + -6471 / -29046 * 12924 - 29926 + 22608) / -18090 + 22304 + 31012 / -25394 * -25527 / (17020 - -32498 + 11243) * 6613 + -24592 - 16824 - 9652 - 12962 - -22863 / -13861) - 20342 - 30306) / -29428 / -18972 / 2010 + -1859 * -30051 + -12006 / -18546 - 10462 - -9521 + -20267 + -29329 + -30394 * -1760) / 14108 - -7392 * -9405 * -15528 * ((12572))) - -19602 / -21050 * -31014) / 1913 + -4186 / 14006) - 23244)
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/2180.arith b/chomp-bench/benches/arith/data/2180.arith new file mode 100644 index 0000000..ab5bc5b --- /dev/null +++ b/chomp-bench/benches/arith/data/2180.arith @@ -0,0 +1 @@ +(29413 / -10366 / -27050 + -19544 * -12857 + 1657 - 6429 - 1575 / -18805 * (6236 / -4864 + 5328 / (-28766 - -23344 / 1897 - -10264 - -15545 / -22321 / -26281 + -6283 - -32498 + (((-18270) + 24059 + 18757 * -13046 + 410) - 5087 - 16845) + -13501 - -11165 / 10931 - -12920 - 19771 + 31512 / 27430 + 29179 * -5425 / 8472 - 24814 / -6239 * 18302 * 27551 * -14128) * 30808 + -27780 + (-7080 - 24343 + -13633 / -2952 - 19589 + -2432 - 418) - -18630 * (28453 - -23142 + -25301 * 10469 / 21805 + (6705 + -20941) / 12166 * 25067 * -5523 * 1712 / -26749 / 1014 / -2801 * (26069 - 3978 + -4487 / 14353 + -28970 + 17036 * 9916 + -19436 - 21081 / -26225 / 17558 + 9519 * -1431 + 16650 / -10868 * 13316 / 6423 * 2702 + 14993 / 17300 / 26043 / -23097 - 32561 + -24417 * (-17770 - (13434 / -3495 * -19723) - 23871 - (29314)) / 2068 + -27149 * 28478 / -15589 / 22911 + 17746 + -1779 + 32657 / -32373 / 3077 * 15619 / -22630 * -4937 + 9998 / 10994 / -17860 * 14003 / -13166 / -4922)) - -1283 / (1986 * -22161 + 14898 * -3210 / -5045 - 29713 + (19077 - -8307) * -9969 * (-32136 + 28190 / -27538 / -12829 / 9739 * -24631 / -23424 / ((-11618 / (-20080 + -6697 * 13340 - 20386 + 4134 + -18209 + -4881 * -17637 + 7447 * 26973) * -18860) + 1)) / 13606 / (-9977 + -15895 / -30099 / -9410 / -18342 + -4456 + -14061) / -13146 / -25199 - -3110 + 672 * -22419 - -7711 + -13525 - -20730 * (-4259) + 31080 / 22839 + 8319 * (24326 - -28097 * 16074 / 4717 * -32149 * -20741 / (-14546 * (8702 + -14407 / -25071 * 15880 / -17212 * 30943) * -3731 - 28713 + 26127 / -28857 + 12082 + -12964 - -31922) * -12295 + -26824 + (-31061 - -18340) / 25139 - 28096 * 6898 / -29952) + -29845 + -4715 * -29119 - 4858 * -23651 + -1729 * 30872 / 29958 - 5497 * -20518 - 32756 + 3926 / -16980 * -2792 * -17122 + 4842 + -2418 * -2054 * -26420 / ((((15194 - 32629) / -20992 / 15881) * 15405 * -29571) + (-4077) / -27110 * 32297 + 2769 + -13517) + 2643 - 23230 - -5387 - 8726 - -26587 + -22494 + 24391 - 7508 * 10021 + -4357 - 22113 / 26035 * -24269 - -10567 - 24820 - 3097 - -19770 * -17076 - -27736 + 29088) / -28509 * -11910 * 28826 + 32570 * 19325 * 4727) * 1722 / 26883 + (-27628 + -26187) * 11802 / 24563 + 5033 + -15146 + -27513)
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/262.arith b/chomp-bench/benches/arith/data/262.arith new file mode 100644 index 0000000..c54084f --- /dev/null +++ b/chomp-bench/benches/arith/data/262.arith @@ -0,0 +1 @@ +(-29901 / 30119 * -8463 * 23900 / 31397 - -13633 * 12636 * 19514 + 18527 * -16089 / 11503 / (27237 / -24154 - 20469) + (-32450 - 11210 + -10920 - -25496) - -23339 - -2386 + -2369 * 30331 - 29375 / -12690 * 28378 / 14623 * -24876 / 20642 - -13525 * 23573) * -5233
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/35389.arith b/chomp-bench/benches/arith/data/35389.arith new file mode 100644 index 0000000..c57c37e --- /dev/null +++ b/chomp-bench/benches/arith/data/35389.arith @@ -0,0 +1 @@ +-3197 / ((-32426 / 7602 + -17645 - -12937 + 6131 / -17310 / (-1736 - 20700 + -13483) / -18389 * 8 / 5892 + 5899 / 8238 + (-2965) * 23743 - -5099 - (6906 + -30679 * 5185 - (13941 + (-15876 / 23620 + 11568 + 22614 + -711 / -8796 / -8069)) - 195 + 1270 + 5430 / -24422 - 16746 + -3081 - ((16437) / -9740 / (-2118 / 14869 * -7594 - -23478 / (-24008 / (-32409 / 4163 * (16908 * 11461 + 11695 * -3792 + (-8947 - (17882) / ((-24111 * 2187 + -15775) - 10681 / 23768 + 20440 * -16071 / 10963 + -6304 - 7999 / -30098 / 29296 / -20523 + 7197 + 5770 * 22621 / -3892 + -11586 + 20146 - 12700 + 3938 * -11454 - -11387 + 22684 + -30845 * -1133 - 7795 - -26971 / 23253 * 9420 + -8767 / -22379 - -10105 / 12201 / 17844 / -3731 - -17039 - 7854 - (-17007 - (16500 + -781 + (2942 + 14249 + -2185 + -32292 * -32604 / -1728 + 22631 / 19387 * -22312 * 32457)) * -22342 - -2845 / 29152 + -5126 * 1410 - (-24084) / -26786 * (13047 + 26856 + 7892 * 26815 - -31489 * 5237 * (-4993 + 24991 * -24189 - 3765 + -310 + -15991 / -8452 / 25262 / -290 * -9983 - -10842 * 15405 / -11300 * 28293) + -16854 / -504 - -9515 + -24669 + -4280 / 21375 / (3883 + 8452 * ((21280 / -24690 * -28747 - -1444 * -20445 + -16852 + -4020 - (-17639 + 31854 * 22156 + (1641) * 28024 + 9501 * 21723 / 9131 + 22591 / -16267 - (-16851 * 23363 / 8647 * 6135 / 29518 + -15603 + -29702 / -20931 / -9570 - -23349 / 31477) - -23267 / -15251) + -3490) + 19894 + -23773 * 30555)) / -25391 + 11769 + -14266 - -17016 / -20234 + 22747 + 15629 + -9713 - 22454 / -7524 / -5919 / -26592 * -4450)) / (12278 * 6315 - 22013 * -6497 + 3557 / 27417 + -473 - 8483 * -31871 * 24390 + -6110 - -22982 * 30688 / -9622 - -4964 / -23790 / 25088 - 16592 / -30721) * 8205 - -26162 * 20776 + 4827 + -13229 * 29273 + -12175 / 13376 / 30362 * 27899) / -26547 * -25390 * 8544 / 16821 - -22848 / -27067 * -27348 + 16941)) * (-12538) * (32614) * 9051 / -30094 / (-12386) / -6292 / 19001 / ((-13272 - 13663 * -345 + -17587 + 28897 + -20531 + -2217 / (-13349 / -19740 - -26826 / 3810 * (3136) * -29738) + -20318 + 27605 / 4462) * (26907 * (-20289 / 15003 / 22995 / -24701 / 514 + ((-17362 * -4545 - -24373 - -23037 * -19806 * 14652 / 15387 * 4542 / 6496 / -8391 - -14418 + 5829 + -17279 / -30281 * (15076 - 31999 * 32439 + 22699 / -11288 * 14384 / -23071 * 27116 + -10839 * 550 - (-29143 / (-28429 - 21952 - -7874) + (18854 + -13958 + -31020 / (-5001 / -28856 + -708 + 132 / -13814) + 25990 / 14377 / 31166 * 19399 / -12146 * -5617)) + -10827 + 28986 - -25639 / -13194 / (-8385 + -24296 * -22971 - 32690 / -27976 - (-10422) - 19279 * (15678 + 28200 - 8555 - -18356 / 5922 * 32315 + (11887 + -6623 / 1046) / -29090 + -2530 + (-24783 / -9401 / 30851 + -23954 - -2115) - 25785 * -1590 - 14436 * -9943 * (-21749 + 26062 * 11794 - 25641 - 14729 / -25455 * 25092 - -23866 - 5524 + -10023 - 11757 * 24889 - (26044 / (-29949)) - (-13810 - (-11434 - -16992 / -7660 + 24213 - 10585 + 16542 - 12374 - -5232 / -4506 / 17464) + -23702 - -13116 * -21595 / -248) - -12615 + -4055 / (20177 - (-11548 * 8212 * -25618 / -4762 * 6814 + (20804 / 21210 + 8282 / ((30252 + 23364 + (-15564 * (-23096 * 2361 - -4431 / 26629 * -26527 + 23024 * -22199 + 13020 - 1476 * 14074 / -17024 / 30430 + ((25900 / -2902 / (-16249 * 22435) * -561 * -13273) - 9720 / -4830) / -2334) / 6265 + 8251 - 16769) * -18087 + 32149 + 30377 * (-13504 - (-30220 - -17540 / -4102 * -21920 * (-19373 * (-22001 + (30645 + 23259 + -28982 * 12531 * -28698) + 17305) * -6293 / -1287 * -12832 + -24492 / 21432) / 16883 / 4077)) - -27942 * (-20245 + 20654 + 20314 + 4125 - 25455 + (-31854) * -32632 * 7846) + -5691 / -12494 / -21442 / -17159 / -18643 - -24590 * -20491 + -21135) / 1772 - 13747 * 1019 / 5266) * -26908) + -20846 + -11027) * -31172 / 15634 / (9205 * (-5535 / -29269 * -24544 * 507 - -10253) / -19463 / (-31405 * (28737 * -28137 - -15582) + 21578 - (3322) + -25157 * 6014 - 14323 / -10663 + 29259 + ((5492) / 29358 / -30716 - -6821 + 20833 - -10531 * 27983 - 31529) - 3598 - 7008 / ((-13252 + 211 + 10697 * -4085 / -1693 / 27976 / -21922 / 18616 - -4188 / -24609 * -21121 - -14508 + (-23399 - -11041) - -13524) * -29138 / 17277 * 1320 * -32488 * -19003 + -27763 + -23451 / -12615 + 3850 / 8633 / -18123 / 32345) * 6407 * -28609 * 8860 * (7468 - -1929 / -13886 / -5391 * 29606 / 32380 / -5427 * 28853) + 7174 - 11151 - 20372 - -7190 - (16393 / -5966 * 13413 * 25090 + 32509 - -13203 * 5188 / 21514 / 18838 / 21029 + 29327 - -18215 * -6811 * -4974) + (-16433 * -25533 * -7043 * -4989 / 14463 - (-10787 * 915 - -3420 * 31014 - (-25774 * 30094 / (-18924 / -19075 - ((-26688 + -1400 - -2683 / -17823) - -2999 / -16572 * (-30893 / 18753) + 30233 * 5697) + (-4627 + -22090 / (-20388 * (-16715 * (-1170 * -13204 / -19721 * -32212 * -8393 + 28343 - 24346 / (25582 * 30638 - -30302 + 14291 - 18050 / 6206 + -6925 - 11026 / -11526 + -2355 + -12342 + 13742 * -1238 * 26304 * -9590)) / 32226 - 22509 + -19904 - -30959 / 29206 * -22947) * ((-29652 / 32081 - 3941 * -14831) * (-1441 * (31604 * -14403 + 23153 / 30313) - (15780 * 19535 / -16260 * 14980 + 29545) + 26723 * -27723 / 2468 * 5014 / 19055 * -31699 - 11837 - -24657 + 272 / 31619 - 26398 - (((-28156) / -763) + 20034 - 23596 - 17859 / -3710 - -9682)) / (-27878 * -13202) * 27700 * -24423 - (8066 / -3642 / -23260 - 5596 / 32218 * 9014 - 27301 * -32679 - -3589 + 22483 - 3590 + 26679 / 20225 - -8266 - -27708 / -25354 * 9484 * 30877 + 2183 - 29280 / -1623 - (10010 * 7598 * -18096) + 10762 * 30071 * -18182 / 5212 * 15147 - -29574 + 8439 / -20143 / -2413 / -29509 / -6783) + 6559 - 26393 * -30672 + 8162 - 24670 * ((15203 - 2918 * 19999 + -25592 / 11783) / -6700 * -26033) - 9807 - -30118 / 11503 * 51) + 3803 + -30764 / 18538 * -30544 / (15964 + 7017 + 13916 - 25696) - 25238 + 8336 / (-6445 + 4258 + 15174)) * -7719 * -28082 / (21500 + 20842 * 1782) - -28992 + 1760 - -6661 - -18287 + 26766 / ((8730 / -8659 / -29007 * -20493 + (10206 / 4288) / -28834) + 1) * -18984 + 29472 + 15437 * 26064 / -5582 * 19072 - 19604 - (14803) - -21358 - 25041 + -4216 / 18981) + 19048 * -24255 * -19525 * -20092 + 11318 + 27533 / -31770 - 32085 * 22266 * 24471 / 23100 + 26842 * 27854)) - 1365 - (5759 * (-8501) + -3095 / -17065 + -17431 / 610 * 30641 / 31703 + 21145 + 11755 / -17185 * (-9760 * 27043)) / -12335 - (29874 / (-31817 - -30134) / -20997 / -6595) + (9068 + 15620 + 12338 * -19367 + (-24148 + (10198 + 2013 + 28292 * -7484 - 10724 - -23837 - 22025 * (-24123 / -2975 / 20948 * 7181) / -7044 * -12619 / -24077 + 28121 / -31517 / 80 * 17193 + (-7607 / -14672 * -6432 + 15512 * -27728 + -15731 / -19053 + -11006 / (-25780 - ((8515 * 17632 - 7253 * 23089 - -30609) * 9783 + (21213 + 1390 / -17489 * 30418) / -25208) - -2777) - 10841) / 5124 + -8658 - -31586 + -27998 + -28372 + 15379 - -8779 / (6366 * -10192 + 21321 + 28502 + -28174 + (12488 * (-27426 / (27764 * 32348 * 30885 - -29610 - -18515 / -10207 * -32572 * 5169 - -31342 / -31901 - -11146 * -7213 + -22121 * 21099 / 8101 - (-14685 - 12866) + 7736 * 13756 * 22901 * -8043 + -27120 * -20743 + -8702) / 30296 + (-18985 + -442 * -26517) * (23796 + -22893 / (13399 - -31249) * (-1563 * -616 / -15895 * 19104 * -27644) * 2344 + 8368 * 14192 * -769 * -25835 * -29914 + (23862 * -30776 / -15452 / -29759 * -4080 + -2623 / -32242 - -29301 / 31194 * -5965 / 8266 / 2481 / -14327) + -24093 - 14407 + 4518 + -29176 / -29770 / 28305 + 10650 * (-24992 / 19092 / -539) + -18758 + -12493 * 12062) + ((29366 / (6899 - 11781 + (13602 - -19844 * 12263 * 9232))) - -32179)) - 14542 + -2111 * -31133 * -31411 - (-29750 + (-10062 / 21323 * -6434 - -31303 - (18387 / 12072 - (8027 - (-15834) * -12067 * -6134 - (-9528 - -3365 * 10625 + -29157) + 4853 * 6452 + -5442) / (32045 + 18615 * -28398 + 25730 - -28866 - 9988 - -12236 / 31373 * (-3303 / 7178) + 3018 / -2744) + -26327 + -16081 - -21265 * -3049 / (26836 - -7923 + (21080 * -8938 * 3580 + -25922 / 26490 * -23194 * (((2940)) * -4396 - 13477 * 20538) - 17752) - (-25181 + 23868 + -13784 / 15498 * (1712 * 22204 * -14063 / -12437 + -24964 + -20435 * -31395 - (-14223 - 29448 / -21374 * -8919 - -24442 / -26206 - -4250 + (-31481 * (18010) * -30822 / -1201 / -22842 - 31899 / -5816 - -7496 + (22894 / -25818) / 19401 + -7067 / 5853 + 23346 - -27275 * 20157 + -23091 / -24801 + (-18344 * 7328 - -29203))) + 6070 + -18055 / 3306 / 28515 - 24263 / -18808 * 28554 - 17263 * 29821 * 19538 / -28794 / 29011 * -27578 - -18405 - -17617 / -3593 * (-25267 - -29022 + 1668 * 4715 / 24387) * (-7432 / 26063 - 20870 + -25903 - 22811 - -31279 / -30646 / -2803 + -389 / 8651 / -22738 + -29609) / -8845 / -25228 + (-27111 / ((27715 / (-30759 - ((-2033 / 23693 / -32602 / 27859 / 1810 + ((-26166) / -5679 * 14639 * -21419)) * (-2826) / -25557 * 2021) / -4923 / ((-9724 / -26453 * (898 - -22971) / (14850 * -5411 / -8043)) + 1) * -7709 * (-12519 * -15731 / 10981 + -28541 - -15499 + 8236 * 31524 / -10723 - -32261 / 393 - -29075 + 16477 - (16954) - -24158 * 1283 + -28077 * 7275 - -31927 / -4480) / 7415 * -11218 * -20502 / 22714 - -21430 * -9350 - 15100 + -24051) + 30703 / -824 / 6119) * 29260 - 4957) * -19343) * 8533) + 10357) + 28778 - -23578 * 27211 * -19006 + -24243)) / (-22084 - 30403 / -31185) / -24648 + 12449 * -9394 / -21279 * 3409) * 5118 / -4294 / -29712 - (4314 + -29822 / 5143 / (-27994 + 7570 - (-12290 + -6132 + -11613 - -8189 / 32350 - 22731 / 15337 * 18525 - -24619 - 26566 * -31619 + 23626 * 24041 - 15409 / -4076)) * -26412 - 21103 - -16780 - 26657 * 9287 * 6415 - -3713 / 20781) + -7945 - -14636) - -3544 - 2580 - (30593 - (-22973 / -18539 * 3783) * 20181 + 30328 + -16907 * (-23794 - -439 + 23 + -1447 + 6844 / -8235 + -9028 * 26354 - -5341 - -12488 + 25104 * 6908 * 15884 / -16592 - -5866 / -31446 / 3508 + 29919 + -3907 - -15484 / -24603 / -25835 / -28670 * -29179 * 8595) - -27899 * -14739 - -13670 + -22730 - -3559 / (-21182 - -20710 + 12098 * -13667 - -21369 * (-28052 + -6376 / 17781 - 14684) + -30338 - 0 / -11154) * (-19303 / 177 / -4677) / 18030 + -14928 + 2107 + 1338 + -17828 * 24003 / 28895 * -16960 * -5241 + 24136 + -9911 * 437 - 20258 / (10249 * -24160 - 12011 / 16569 + 13814 * 31380 * 23316 + (-23199 * (-977 - 7105 * -30318) - ((-3806 * 9285 * -7108 - 28035 + (-26033 - ((26331 - -2794 - -27396 * -25246 * -31765 / 3659 - -21408)) + -8191 * -28239 * 29428 + -32546 * -11519 - -19071 / 12592 / -29072 + 19927 / 32261 * 14712 * -6871 / -23597) + -5250 * -1933) * -19948) - -28060 - 22011 + -13326) + (27603 * 4012 * -18592 - (410 * 19508 - -31037 + -11978)) * 16568) * 23405 * (-1721) / 1219 / (-11261 + 18533 * ((23656 - -31135 * 16749 + 25425 * -19556 + -27568 / 6776 - 14003 * 1180 + 6070 / (-20025) + (-25205 / 3936) * -18029 * 32151 - 429 - 27492 / 15486 / 7396 - -6440 + -1184 * 25390 - -19650 + -23777 / -10377) + -7404 - 2221 / -12170 + -18967 - -11471 + -28844 + -15303 + (17677 + 13333 / -4619 * 9755 - 15660) * 1440 + 27928 / (((20883 - 26781 + 19946 - -20635 / -8490 - 24582 / 31213 + -316 + -32626) * -22410 + (11007 * (16019 + -18524 * -29715 * -8229 + 11771 / -27954) * -26038 + -17805 * -349 - -28679 / -9593 / 22374 / 27887 + 18329 / 32663 * -24304 * 5931 * -26053 * -5129 - (-5718 / -15643 / 30245 / -2079 - -5013 / (-19647 - -1235) / -15840 / (-7601))) / 15264 * 9300 / -10685) / 10774 * -28647 + -25711 - 26937 * -13293 - -15662 / 10666 + -21449 + -24110 / -6669 + -26785 - 11960) + 27491 * -24319 - -9676 * -10358 / 22579 / 6845 / 19946) / (-23923) - 31233 / (28175 * 8634 - 16406 / 10972 * 6542 - -27236 * -15707 + -25443 / -6025 / (12758 + -10932 / -29303) - -12842 / -8264 - 21223 - -1980 * -29809 * 2935 * 11992 / -14638 - -14068 - -17340) / -6306 * 1394 / -8175 / -12793 / -6544 - 24181 * -29827 / -13540 + -13507) * 29345 / -3409 - 13138 / 1065 * -20603 + -5698 / -3016 * 27439 + -14481 - 14910 - -4607 + (-9869 * (-2606 * (-346 * -7711 * ((30116 + (23577 / -21700 - (14770 * -21221 + (6000 + -6226 + -1216 * -13262 - -3873) + -20359 * -8436 - (15289)) + -6454 - (-32025 / -22498 * 12919 / 1517 / ((-4405 - 1203 * -4877 - 14025 * 10932 + 20312 + -12415 - -3299 + (29546) + -8607 / -22049 / 23963 - -31844 / -3754) + 20588 + -15452 + 9643 / -29757 * 16583 - 16037 * 14385 * 3121 / -6775 - 13145 - -28416) * -7899) * (13262 / 23377 - -18867 - (-2816 * 23286 / -14422 / -7859 * (23542 * 24491 * -32399 + -1375 + 17665 + -31932 * -61 - (-31664) / 31497 - -13375 * 30644 * 24065 / 31619 / -29759 - -3080 + 32353 - 29496 * -18711 * -6107 + 27618 / ((-25337 / -28542 / 13414) + 1) * 31687) / -23082 / 5888 / 5675 - (-13680) - -28745 * 23499) / 2071) - -26625 * -11823 - 28331 / -28850 / 22905 + -30900) / -15649 * -25436 / 28219 + -24512 - 10441 * -10004 / 23716) / -95 / 6 * -20918 - -7014 + (-26946 / 25165 * -11448 + -22201 + 4670 - -115) + -6037 + -6349 * -24067 + -4357 - 22428 * (-27790 * 12725 - (-17317 / (3789 * 6384 * -28293 * -8114 - 31693 + 10695 - 32075) - 32339 * 24973 * 14613 / (-1347 + -24725 - 2202 / 882 * -26557 / -32270 / ((-7329 / ((23323 / 24565 - -12061 / (10892 * -1187 * -32305 / (22195 / (-1493 * (-23791 / 29229 - -15298 * (22781 / 29254 * -16763 / 32233 / 10856 - -22422 / 10143 * 9598 / (16985 / -18891 - 15167 - 16644 + (27536 + 5644) * -21893 / -23478 / -10494 - 4783) + 6148 / (-31596 / -9990 / -9630 * ((7425) + (25304 * -18629) + -27776 * -7374 - -27891 + -5925 / 4328 + 10980) + -11038 / -12248 * -25974 / 8416 - 13183 * -664 * -32612 / 19728 / -14698 * -8905 * -12077 / 1866 / -32448) + -12515 / -14467 - -10523 + (26767 / 23560 - 18789 + -27923 - -27933 + -26457 / 14121 * 20189 + 11152 / -6509 / (-31116 * 4232 / 14029))) * (-26954 - -24193) * -30422 / 8489 - 18278)) - 10626 + 14580 * 6392 + 12491 / 19027 / 10522 + 13997 - -2839 / 14070 / -22510 - 15345 / -4697 + (-17712 - (9650 * -6990 - -1296 - 5435 - 21608 * 556 / -18238 / -11059 / -2747 / 16300 - 22007 + 28519 * -6710 / 26491 + 30480 + -19501 + (((-27664 / (18610 * (7343 - (-25168 - (24382 / 2063 - 14 / -16222 - (11764) + -30877 - (-22446) / -23061 - -19040 + -20634) / -9391 * 18707 - -2192 - -29844 - 21630 / ((-12498 / -18956 / -30987 / 26949 / -11643) + 1) * -2829 - -14316 * -25281 + 19814 / -5003 - -22026 + -24027 + 3608 / -8055 * -28720 - -8492 / -25064 * -20102 - 32170 * (6055 + 14586 / -23562 / 20868 - (-20758 + -21003 * -27515 + 18131 + 13137 * -16469 + -24499 + -4743 + (2304 + 16765 - 23790 - (-20704 / 24576 / -12135 + 14628 * 24920 / 16083 / -3161 / ((-30264 / 13975 + -7520 + 12712 - 23684 / 15909 * -12733 / 30053 / 1042) + -8698 * 5411 - -24667 + -1707 - (-532 / 24529 / 28655 * -16476 / -24027 - -24917 * 17916 + -6442 / 2699 * -1302 - (289 - 15616 / -22664 + -23979 - -10116 / -15936 + 2345 - 18238 - 7189 - -19124 + -5278 - 3572 - -20286 - 22901 - 9941 - (-17971 + 12002 / -24743 - 18435) + 18605 * 6087 - -20234 * 30548 * 809 - -7651 / 15947) + (-29945 + -21189) + -25621 / 22111 * -25188 + -471 * 7605 + 2038 / 20887 + -32763 - 25705 * 5380 + 21449 + -25051 * 5492 / 14108 * -31771 + (-19922 * -7018 - -21337 + 13504 * -28584 * -20290 - 22730 * ((((-18535 - -14849 / 20342 / 9869 / 29300 / 23419 - (32159 - -5683 / -17024 * (6445 / -9785 + -3478) / 11483 / (13364 - 4148 - -28119 / (-3644 * 31569 * 27369 / -22898 + -22667) - 15355 - -32549 - -21244 + (15564 + 22268 - 15322 / -7713 * 17143 * 32214 + 11037) / -21147 / -13439 / 21947 * 9371) / -26558 / (12834 / -7288 * (-7827 + -24645 - (-1623 + 829 + 31216 / -4126 - -5936) + 17055 / -14313 * (26080 / 22182 + -6589 * 23323 + 28905 / 23772 * 7321 - -32026 / -25406 * (28544 / -19967) - -2578 + 25054 + 15209 * 9187 / -22220 * 28051 / 30619 * 16105 * (29749 * 30146 + 16573 * -13768 - (-638 + -26675 + -16406 + 17885) * -21728 + 27022 * -11666 - 21278 - (8764 * 294 - 3314 + -25004 / -13631) / -21485)) + -18779 / -12712) / -7396 + -30080 * -15892) / -25310 * (-3746 / -22921 * (1446 - (-24129 - (-25056 * (20657 / 12738 + -13365) + 16258 / -5250 + -21430 - -30599 + 9936 * 25327 * 743 / (10234 - 25303) - -4425 * -26678 + 13608 - (((1997 + -23115 * -20915 * -7583 - 15759 / -21174 / -25211 + -29350 * 13825 + 31867 + -31106 - 24080)) * 6438) - -27034) * -5384 * -32007 * (10504 + -22849 + -26591 / (13936 + 3196 - -27417 + (-22256 + -4220 + 242 * 29608 / 3550) - -12898 + 17762 * 8592 / 20923) / 22457 / (18639 / -26485 - -31513) + 20406 - (7317 / 30576) - (2882) - -18561 + -24277 * -29820 + -25755 * 27585 - -17843 * 28718 * (((-13100 + -29752 / ((-32497 / 31573 * 7264 - 11944 + 8601 * 5977 + 22760 * -18656 - -25256 / -26887) - -25159 * -23251 * -13689 * 28832) * 2652 / ((-11192 / -18464) + 1) + (-32406) * -31180 * 3656 + 25076 * 9089 - 19713 + ((1805 * -24702 + 10852 - -23885 + 23333 - 11836) - 9308 - -17205 * 22763 + 28228 - 3501 - 19977 / -25626 + -5796)) - -11574 * -25814 * -21347 * -18357 - -18973) * (-27424 / -16471 * -7919 + 18245 + -7861 - -8599 / -5367 + 17874 - 13397 - 23746 + -19944 * 4703 / -1414 / 29069 / -31847 + 4497 + -653 / 21125 / 27615 / -18966 - -32312 + 8328 * ((27566 * -7484) - -26241 - -2874 + -8677 - 13000 * 14251 / 10282 / -5814) / 8747 / 17346 / -25353 * (7841) / 9137 + 31623 / (1310 + -4100 + -7996 + -3293 * -19946 * (12391 - 6246 + -29783 / -27865) + -22089 - -24198 + 29403 + 32246 - 17149 * 29640 - -7010 / (7165 - 27185 - 23886 / 24419 + -21411 + ((-9853) * 14450 * (-2794 - (22154 - -4418 / 26201) - 13986) / 24691 * (6080 / 14010 / -13509) - 22954 - -18107 / -19483 * 27744 / -26547 / -7574 - -12498 - -26392) / -20767 * 16064 / -23388 * -24853) / 29293 + -23677 + 24817 - 30861 - -18083 + 26070 - 27134 * (-13843 / (15696 - 28746 / ((20037 * -7987 * -7661 - -10551 + -27395 * 26943 * -687 + (29967 + 15929 - -408 * 6331 + -16961 + 30232 + 19844 + (898 + 4460) - -12268 - 13067 - 22059 - -18975 / 15420 - 21760 + 24357 * (10128 * 22648 / -24656 - -10908) + -1091 + 9518 - -18711 * -14663 * -17549 + -22148 + -32643 + 4632) - -22534) + -11869) - 22585 / 27803 / -28242 * -30942 + 30978 - -27543 / 14046 / -28139 / 3644 - -19899 * -7877 / 26048 - 31425 + 11650) / 29094 * (23227 * -24240) * 16683) * 3427 - -24206 + -7555 * 19353 + 16690) / 27232 + (-11988 + 32564) + -16734) / 8877 / 2098 / 30597) / 27728)) + 6417 + 31379) / (-20880 + -20075 + 18129 * 11491 * 15814) * 9778 / -20240 + -4941 + 3195 - 4274 / -19424 / (-31275 + 32653)) / -23662 + 28242 / 27563 / -17248 + 9223 / 8376 - -28563 + -13485 - 5992 * 12442 - -27256 * 7890 + 13693 - -10191) - -8011 + 27470 - -31372 * 12233 + -8074 - 32351 * -7056 * -10732 + 17074 * -25533 - ((-13703 * -19766 + (21191 / (((-25223 / (-31117 / -28947 / 12627 + 24845) - 29121 + 21563) / 1280 / (-26376 + -9897 * 25590 / -23720 - -21441 * -5377 + 16391)) + 1) - -25960 - 32483 * (-20883 * -12829 / -12107 * 29758 * -22787 * (5120) - 22027)) / (690) / -16603) + (28718) / 30799 * 2136 - 10206) + -11220 + -17092 * 17790 / 9015 / -30144 / ((-17297 + 4781 / -4447 - -27897 - 25588 + 29793 * 15802 - -3409 + -2550 * 11361 / (-14329 * 22518) + -28564 + 29481 + -4431 / -19878 - 32240 - 13665) + 31488 - (-17953 * -28579 - 31828 / -2876) * (14791 * 23785 - -11737 - 15203 * 26004 + 5862 / -24241 - -18810 + 11362) * -10411 + 12721 / -26564 - 2968 * -12794 / (-27477 * (-4792 + (-30994 / 5643 - -3448 / 6659))) + -26432 / -17351 + -27194 - -14718 + -9030 / 22282 + 21584 + -20429) - 26809 / -18747) + -10940) - 8490 - 7758 + -25443) / -27065 * ((-28627 / 12041 - 29145 / 20422 + -6696 / (32199 * -15101 / -12462) * -21284)) / -17651 * -30470) * -26016 + 6180 / -20184 + 23009 / 11390 - -9474 * -14463 - -20090) * -27234 + -23823 + 9540 / -1166 - -15365 / -15180 / 19138 / ((4988 / 24351 / -12950 / 6944 * 22090) + 1) + -11340 * 29910 / (-3031 + 17141 * -556) * -10473 * -1377 / (-15675 * -22413 * 14767 * 1374 - -15418 + -27470 + -15359 * -23744 + -5328 + -2618 + -18632 + ((-31259 * 14844 + 15169 + -2161 + 29983) * (24448 * (11389 + -11661 * 3191 * 28481 + 10183 / 16974 / -22982 * 31209 - -3998 + 19435 * 18682 + 18999 - 3599 / -11322) - 6942 / 22762 * (16572 + 5761 * -26103 / 5384 - 14359 - -31798 * 26964 * -23805 + -20768 + -28417 * -24251 - -11429 + -31260)) * 6005 + -9629 / -7353 * 2156 + 22814 / -13613) - 5934 - (-7042 / -8572 - -13774) * 30182 + -27082 - 1019 * 8783) + 8163 / -18292 + 11442 - 8341 * ((18432 - -11303 * -22507 / -30442 + -2777 * 22465 * -9728) + 24434 / -32546 * -13848 / -7932) / 2971 / -14477 * 29680) / 29735 - ((25054 + -30176 - -27344 * -26394 + -30678 / -7733 - -18513 - (12729 / 19458 - 17131 / -26672 * 18207) - -3490 / 32275) - -15852 - 17033 + (-31171)) - 30326 / -3651 + (-32069 + -2703 + -32395 / -15195 - 13259 * 20565 * 5147 + 28562 + 10248 * (30192 - -16728 - -28012 - 11291) + -20244 + 16773 / -27491 / -3990) + -22930 / ((2776 + -16728 - 16061) / 17086 - -15542) - 27392) - (-21464 - -24068 / -22732 / -17074) / -2506 / -28876 / 30492 * 7647 - 11115 * 6462 + -13410 / 29078 - -26592 / 26421 + 1938 / -6697) + -27816 + (-16837 / 3009 / 7268) * -18243 / -337 - -6217 / 5798 - 44 + -26165 + 3433 + 31018) * 23777 * -26319 + 24374 + -19031 * -9670) / -32264 * -25030 / 19929 / 27411 - ((-12147) / 15054 / 11802 * 22309 * -14508 + 7518 / -3924 / -29819) - -16047) + -31746 / (1445 * -30340 - -32756 * -26090 / 2176 / 3814 * -31216 * (-24521 + 2596 / (21309 - 19345 + (-23679 + 5309 * -23436 / (3352)) * 23198 * 19568 / -8253 * -15399 / 18434 + -26110 - -20773 * -12769 / -12314)) * (-15708 + 21464 - 14054 * -18281 - -24564 + -23993 / -9837 / 17681 / -6001 / 4869 + -31661 - 32515 * 183 / 1072 / -8758 * 26678) / (-14159 - 14726) / 9311 - -6343) + -22825 / ((1709 + -9105 / 22596 * 15339 + -31245 - -29881 + -22168) / -6525 + -13934 * -8085 - (10714 / 15233 * -11033 * (-328 - 25395 + -32475 * 25843)) * -4920 + 18906 + 18119 + -20719 - 12165 * -3876 * 23041 - 16564 * -19304 * -13901 + 1261 - 6088 * ((28034 + 4708 * -14603 / -23257) / 30007 / 12889 - 2079 / (-1053 * 26793 * -22945 - -23830 / 22100 - (17686 - 1073 / (-27678 - (1833 * -27605 / ((25810 / 14475 * (27549 + -14713 + 24005 - 2721 * (-32137 + 25164 + 3294) + 473 / 10972) * 6257 * (-5021 / -20459 * 7676 * -10841 + 27082 / -1927 * (-29652 - -1731 - 22544 / -30304 - -14655 * 30499 - 31540 - 31910 * (4135 - -10858 + (9637 + -20385 / 5934 - -30117 + 4972 + ((-30990 * -22121 + 20911 - -29560 / (-29445 - -31687 * 9674 / 19059 / -31854 - -11177) / 11869) * -16306) * -18171 + 19723 / 14621 * -23609 / -22777 - -8857 * (-24332 / -2763 - 1255 / -31969 - 13753 + -30907 * -19585 + 7266 * -29897 * (-12242 / -19061 - -23851)) + -9807) / 23012 + 1665 + (20340) - -15744 - -30133 - 156 / 15575 + 29307 / -18084 + -2158) * -24268 + -20599 * 29525 - -7999 * -11905 + -363 / -13944 * 16917 + 18080 + -30758 / -19247 / -8349 * 29269 / (4413 - -26340 / -20285 / (-2178 - -16030) / -22438 + -2539 / ((2360 / 22633 * -4188 / 24450 - -26569) * 10449 + 11380 / 14756 - 23830 * 2106 + 110) - -1117 + 4037) + 9039 + -6035 * 30949 / 20926) / 23000 / (26086 + 13937 * 6799 - 7465 / -730 - 16644) / (5867 - 22940 * -31956 + -26790 / -19588)) / -30950 / -5556) - (32626 * -17389 * -9809 * 2792 * (13248 / -30365 + (-7364 * 15413 + -19689 / 17418) * 26875 / 20753 * 5034 / -1854) + 1072 - 914) / -3243 - (-4542 / 29764 - -4004 / 14355 + 8078 + 14275 + -22962 - 7526 - -16993 / -16044 / 5097 + 17353 / -2275 * (25880 * 21958) + (-14494 * (10871 * 12547 * (-18271 * -20148 / -6764 - -5681 * 3451) + (12918) + -18041 / -27591 / -3407 * (12515 + -26719 / 5618 * -15439 * 28476 / -27065 * (8050 / -21546) / 10991) * -28460) + (-23139) / (22095 - -26673 + 5021 / -30457 * 29323 * -20665 + -14942 + 17844 - -24275 * -14333 * -8716 * 16863 + -23421 * -10539 - 5057 / 19838 / 16340) / 25155 + (-14893 * 18997 - (20267 - -17458 - -31894 / 30057)) + 13868 + 20957 * 28499 / 7267 / -25193 / 17288) / -5659) - 26902 - 26578 - -20967) - 12319 / 18293 / (-19404 - (-17349 * (-6394 / (-816 - (16653 / -1725 * -8589 / 30284 - -436 * 25447 * 31434 - 20137) * 15166 + -7425 - 21649 * ((15177 - -18532 * -11869 / 24862) * 16750 - 26463 + 16067 + -22363 * 10952 * -29108 / (-29923 * 16306) + 25666 * 24735) - -14158 * 26547 / (2425) / (31692 + 7996 - -31977) / (-23897 + 26528 * -20557 - -26704 * -8810 + 12605 / -11972 * 32680 / (-23320 * -15859 * -28973 + -18025 / 26927 + -24584 + (8286 - 16361 / 8191 * -23344 - -30513 * -29745 * 30676 + -25903 + 13774) + -31759) - 29091 - -12465 - 26724) + 16247 / (-17505 * -361 - (-19165 / 10124) + 24281 + (-11424 + -22667 + -21241 * 3588) - (9413)) * 25983 + -4269 * -10736 - 6371 + 7124 / 13533) / 23450 * -17641 / -18815 + -5095) + 4628 * 8248 * (17806 * 16440 * -13990 * (15361 - -18221 - -17275 / (-4299 + -28009 * 20570 - -25787) / 20364 + 1882) + -29345) + 29278 * -10085))) + -24677 - -12635 / -18038 - -13516 + 21429 + -19375 / -29228 - 16740) * (-7309 / (8791 * -2892 * -917 + 12782 * 28125 - -16655 / -16521) * 29963 - 10195 - -9758 * -19451 + -18385 + 17848 * -28868 / (-117) + 5628 / 32477 + -13844 * 13285 * -9090 / 11881 / 23519 * -26970 * -529 * (-22359 + ((14484 + -6665)) * -11184 * (21661 * 5116 / 15398 * 21051 / 14085 + 32552 / -7472 / -28166 + -16815 * -15142 - -5338 + -1818 / 7149 + 15221 * 13629 * -26427 + (-23576 * (-25707 + 17353) / 26886 / -5080 - 18051 - -16505 - (-16844 / 30417 - -7514 / -32261 * 11738) - 18509 / (17640 * -28695) + -10418 + -8968 / -17074) + -27925) / 31908 * -8006 * 27145 / 17593 + 12113 / (6421 * 25028) / 18731) - 16726 / -13261) / 14119 * (14923 - -9709 * -20606 - -4738) / -21095 / 9007 * 16377 * -5850 * -22161 + -18685 * (32622 - -20366 / -23557 - -15091) / -25453 + 31096 / -2533 / (-26467 + (-9384 / 18212 / -4693 - 12383 / 16980 + -28112 - 18556 / -9495 / 25375 / 3772 * 8660 / -21184 * ((-2007 * -4696 + -15924 + 32041))) + 1312 + 20471 - -21843 + 20782 / -13786 * 23432 - 32100 + -6571 - -19848 + -19030 / 15884 / 8485 + 23909 + ((16773 - 15305 - 7122 + (-26014)) / 19073 * -1931 / -10737 / -22239 / 24553 * 20682 - ((9140 + 16449 * -32012 / (10892 / -15128 / 10559 + (-16005 / -30593 * ((-22566 + 31162 * (-18775 / -27752 + -10033 / -14584 * 15130) / 21763 * (1635 / -6831 + -29726 / -16391 + -25911) - 5907 * -16403 * 7964) * 19797 - -311 / 6655 * 13969 + -13033) * -846 - -13079) + -15030 - 32346 / -1143 + -32286 + -14905 / 14343 / -19922 * 14552 * 4554 / -6139 / -23086 * 13205 / 169 * -18083 * -24106 - 3796 / 15195 + (16271 + -16002 * -16363) + 5439 - -5817 / 13326 / -9278 + -32019) + 32762 - -12102 / (-1790 / 30687 * -14470 - 26330 + 4804 + 18388 - -20037 + -3471) - 28042 - 1324 + -41 / 27169 / -29886 + 18389 + -25044) - 20007)) * 25894 + 20797 * 298 * -23421 + (22209 / 19047) + -1127 * -25561 + 15335 * -13006) - -6585 / 6389 - -18327)) + (2728) + -26732 + (-19077 - -12047 + -11313 * 25288 - -28638 / -16482 + -30061 / 17049) / -23664 / -17218 + -18230 + 4865 / -32669 / 3455) + 3763 / -21090 * 3753) / 26668 - 25357 * 23630 + 10373 / 5008) + 312 / 2895 * 27005 - -4519 / -17339) / 1883 + -3054 / -731 * -31970 + (-7675 - -5502) / -24324 * -5288 / -29253 / -18246 - 23807 * 26650 - -1347 / 6936 - -6909 - (-18405 / -3299 * 5796 + (12578 - 3899 - -280) * (-4824 + 22133 - 28011 * -30585 / -24286) - -31669) - 1292 - 4824 - -16650 + 10756 / -5692) + -27184 + -20184 - -14241 / 26722 * -12376 - 15841 + -11612 * -10071 - 8211 - -20806) * -5286 * -25931 - 16589 - -25320) - -26789 - 5116 / (13437 - -3102 / -31058 / 5773 - (-2493 - -18073 + 9181 / 4237 * -29608 / 29579 + -30036) - 334) / 19653 * -1175 + 30108 * -27200 + 3412 * 30090 * -21383 * 7016 * 23260 * -1465)) * -25003 * 22192) - -1970 - -13127) - (-13022) - -24461 * -16660 * -27171 / -27436 - -29747)) + 1) * 2188 + -20717) - 25496 * 6366 * 13894 * (29104 + -26332) / -16110 - 15918 + -13848 * -16062 / (13557 * (((9066 / 9300) + -14070 + 8553 * -1837 - 23363 + 2067 + -32379 / 28505) * 20106 - 83 - -12624 * -29306 + (14518 / -27434 + 21783 * -13187 / -23210 - 11007 + 1140 - -21599 * 26750 / -31592 + -32742 / (-17731 / -4500 / -4892 / 8159 * -22686 - -29115 * -12209 - -8478 * -8120 - -31876 / -11870 / 18616 + 32374 * -26472 * -25675 * 25540) * (-6875 / -30713 + -30058 / -3790) / 17942) - (-28600 + -15903 * -457 - -27266 / -4414 + -24901 + 27957 - 5394 + -17184 / -21433 + ((29733 - -6841) / -31696 + 15970 / -12986 + 13784 - -20232 / 24883 / 19509 / 8693 / -868 + 16418 * -7119 * 28477 + (-8462 + 4492)) + 19790) * -27966 / -5808) * -11377 + -30699 / 14156 * 6540 + 9059 / -15631 / 30231)) - -32235 * -20993) - -26080) + 5897 * (-17374 * -32645 * -16860 + 12743 * 14187 - -32343 - 15139 / -13872 / 29192 * -657 - 19424 - -690 / 26687 - (26665 / -14590) * 31449) - -24737 - 828 / -1794) + -21572 * -16033 / -32481 * ((28925 + (6235 * 11185 + -16181 - 15202) + (-17201) * (-7396) / 26930 - -8596) * (-10158)) / -21203 * -5254 * -7008 + 6657 * 26419 + -6620) + 9093 + 13561 / 28806 - -15563 + 30708 - 3595 + 10846 + 15665 - ((15604 - (13308 * -31486 * (-32681 / (-22091 + (-4954 / 28480) - -26081 - -32220 / 11961 / 4181 + 32706 * 6046 * -10875) + -12170 / -10183) * -4044 / 29464 / 23228 / (18570 / 17586 / -32304 + -27627 * 20885 - -30382 - 30227) + 20722 - -29674 - 11405 * -27887 - -6385 / -16042 / -31599 - -14058 / -5140 / -22271 / (-15911 + -24359 / 16114 * -25972) / ((-29732 * 20552 + 2851 * 22246 * -24720 + -24805 * -13930) / 24439 + 32598 * (-2415 * 1851)) + 30931 * 8331) - -3081 - -27283 / (((-15967 / 20142 - (5405 * -11570 - 24467 + 26157 + -4690 - -31091 + (18286 / -12347 + (5606) / -9786 - -16033 / 32519) * 31174 / -27671 * -20148 + -5613) / 30838 / 16540)) + 1) + 7520 - (23949 / 22985) + -271 - -10031 * -3406 / 17309) / -28580 / -11247 / -21893 + 30559 * -17025 - 3259 - (29350 - 14761) - 216 * 24739 / -9932 * -3935 - -19360 / -5960 - 4545 + 2938 - 2264 / 8839 * -6615 + 11773 * 19871 / 6393 * -9760 + -15547 / 22882))) * 5517) / -13195) + 22946) * -31148 * -25178 / -9336 - -16334 * 17679 + (-6169 / -31851 - -6971 / 10237 + 14303 * -29841 + 24053 + -6489 - 32147 - -4835 - -14667) + 27908 + -14784 * -9682) + 1860 * -18524 - -29780) / -8514) * 4346 - (11111 * 1765) + (31143 * 25674 - -21881 * -14345 / -882) / ((-1864 + -3560 / -22622 + -22045 * -25391 / (-9521 - -6860 + -11961 / 32727 * 12244 / -6247 + 1597 / -30440))) + -9838 * 3511 / (24727 + -23685) * 15460 / 19432 * 8432) - 30483 + -11107) / 263 - -15171 - 5066 + -5793 + 996 - 28244 + 478 / (-22672 - -9538) * 2622 - 15301 - -26793 * (-6971 / ((-17080 * 16018 - (-23075 * (-17491 - 12611) / 15861 * 773 - 18048 - (-3585 + (31248 * -5364 + -10042 + -30927 - 30029 + -25746 * 6814 + 26319 + (26008 * -25934) * -4197 + 2614) / 7822 / (-14429 / 22339 - -170 / -19520 - -9491 - -7040 * 8129 * 2458) * 17425 + -11186 / 17468 * (31560 * -12314 / 161 - 21410 * 5635 - -9659)) + -31643 + 12022 / (-18206 / 8400 - -20341 / 23728 / -11155 / (-8219 / -20911 * 30772 / 12218 * 31309 / 23712 - 11183 * -8484) + 26354) + -14614 + 160 + 19123 + (-29937 * 22540 + 26908 - -27186 + -15031 / 12006 - -26441 + 17486 * -19360 - -10497 * 18306) / -22209 / -12777 - -14839 * 1232 / 31134 - -8950 * 24990 + 4445) / -1980 * 4740 + 14585 * ((-3252 + -7113 * -26170 * 26321 / 20274 - 2090 / 13500)) - 31502 - -7455) / 24830 - -2396) - (-4576 - 5115 - 7216 * -13277 * 28699 * 12247 - -3259 - 29518 - 9508 + 2246 / (15612 / -5002 / 12954 + 11472) + 10052 * 15929 * (3035 / 31491 / -24036 - 14846 - 18546 - -28533 * 23637 / -28049 - -25190)) + 896 + -28719 / (20297 * -32678 + 8043 + -31149 + 22395) - -21188 + 21059 - -28107 * -1477 * 2583 + 12951)) * (2531 / -31555 + 24389 * (-31652 * -26051 * -16748 * 15701 * (21362 / -26824 + -11605 * -22227 / 1381) / 6020 - 17017 / 22038 / -9424 * (27429 / -5558 + -21584 + 8458 + 13039 / 86 * 28075 + ((28290 * -30912 / -12874 + (20779 * (-18650 + 13576 / 31435 - -2274 - -19277 / 5243 / (3971 / -20122 - (-12438) - 10687 / 20504 * 4303 + -18607 + -10881 + (-6211 * 26362) / 402 / 4118 / -12160 / ((-23251 * -14084 / 26759 - 6497 * -12444 / 25298 + 8223 / 14839 - (25659 * -1349 - -22232 - -19620) + -6876 / -7343 - -1272 / -9382 + 7589 * -16022) * -10048 + (5051 - -31175 * -1181 / (28855 + -28306 / 30428 + -15400 + -11818 * 15822 - -12181 / 11205 * -22486))) * 25382 / 18391 + 1457) * 12416 + -9949 + -15389))) / -1581 + 6291 / (-28474 * (12115 / 18522 / (-24147 * 4944) * -20685 - 1016) / -26369 / -173 + -24549 * -13960 - 14179 + -26878 + (21571 * 10158 * -30718)) - -18079 + -9889 / 17863 - 32086 + 32327 + 11663) * -17745 + -6516 - -779 * 17692 - 19471 + -2572 + -12362 * 23023) - (25093) / -29527 + 25340 - 29584 + -10494 * -18389 * -15928 + -11535 + -4000 / -25890 - 7829 * 16026 / -19059 - 4920 * -18699)) - 24451 / (30624 / -12710 - 25010) - 9431 + 15793 - 3271 - 8692 - (-21075 - -8370 - -5640 / -29221 / 17570 + -18092 + -26570 + -20505 / 29448 + 10624 + 1081 - -1567 / -28399 - 17087) * -31433 / -13214) + 20247 / -15863 + -22150)) + 13749 / (30321 / ((-7482 - 792 * 18474 - 18964 + -19173 * -27373 + 27925 - 17442 * -25464 / -29461 + 12059 - -3356)) - 23535 * -934 / 30363 / 9074 - 21595 - (6368 + -32667 / 19705 - 11790 - 24074 + 3652 - 22146 - -10199 + 31962 + 4491 - -22451 * 14954) * -27566)) - 10380 - 4835 / -2959) * -26293 / (16020 + -31582 + -31472 / -8078 / (19431)) * -6778 / (32599 - (21966 * -24450 + (-18899 + 10531 + 20639) - (25899 * -30590 - (168) - 19932 + -20418 * 3671 - -30854) + -27286 * -19083 / -25379 * 3327 / -23485 * 28592) * 31837 + 16229 + 856 - -16994 - 10289 - -23864 / -24903 + 6968) / 4150 + -26626 / 2868 + 21167) + -4400 + -28341 * (2331 - 606 + -11654 + -9210 + -1073 * -22392 * -23979 - -15075 - -20431 + 5938 / -18919 / ((8922 / 20887) + 1) - 11581 / -14854 - 26159 + 2036 + 22722 * 770 / 18876) + 8734 * 26266 * (17960 * -12011 * -14475 + 12125 / -29057) / -28190 * 1447 * 17833 * -6749 - 20757 * -15109 / 20656 / 8303) * (13436 - 3576 - 5404 / 4849 / 24929 / 12133) * -28542 / 27539 / 7360) / -24767 - -17772 / 6711) * 21972) - 9923) / ((-11310 + 18894 / -21603 * 21228 * 25893 + -24567 - ((-21973 + -17804 * 12869 - -18223 - 16837 - 32494 * 10523 - -15959 * -6253 / -494 + -19984 + 23266 + -25622 / 20744 - 20914 + (18161 + (-14839) / 20129 - -409 * (-26258 * 16616 * -28364 - 24516 * 31275 / 1025 * -8775 - 9869) + -1261 / 9598 / 25664 * 26046 - 18288) + -6843 / 14906 * 5928) / -5882 * 30) - 18187 + 16130 * -11180 + -19932 * -7683 * 23970 + -11319 / -20168 / 7327 * -7456 - -4400) * 14669 + 15471 * -5260 * -9998 + 19 + -14821 / (-3046 / 8394 / 15497 + -9060) * -8007 + 24905 / -20052 * 7017) - 19864) - 14443 - 31 / 28562 - 7585 - 30125 * -14277 / ((-10555 + 30318 / 18671 * -13231 - 11062 / -17701) / 2480 * 4029 / 3961 + -14720 * 16557) + 16024 + 7063) * (-23044 / -9493 * -4063 - 31543 + 18986) / -4908 - (19926) / 15035 - (-473 + (31299 + -7281 + -8787) * 6568) * -2138) / 20263 + -31324 * 13882 + 9512 - -9995) / (-7128 - -14273 + 31322 + -26769 * 18175) / (28741 - -23027 * -28768) * 5980 - -10074 / ((-4955 / -9134 / (-6007 - -30053 + (-26589) - -16640 * 9850 + 26032 * -23881 / -8705) / -12428 / -56) + 1) - (-21496 - -21387)) - 12912 * 11293 - 6509 + (((10247 / ((31514) / -11535 * -14429 + 4519 + 25061 * (-25300 + -14063 / -27458) + 25832 - 13513 * -23935 / -20546 - 30060) - -13212 / -18032 * (-7217 + 21466 / (9466 * 14948 * -17361 + -30104 * ((21264 + 28738 - 16347 * -8089 / 27467 + -327 / -16975 * (26042 + -8067 / (-9090 / 17958 + 3999 * 26870 / 10682 * 14067 + -19535 * 30661 + 13517 - 8566 / 31363 / 4223 + 5819 * (27734 + 17460 / 10193) + 32314) / 6488 / 7263) / 1467 * -31577) + -29684 + -30909 * 4604 * 13415) * -24530 / -4270 + 16375 * (-16713)) / 21260 / (-2973 - 14306 * 27583 * (-17245 + 25774 - 13258) * 14627 / -9092 - 13381 * 22627 - (27784 + 5731 - -13526 / 24668 - 32005 * 528 * -1323 / 15512)) + -12174 * 14647 / -30764 - 224 / -2975 * -2756) * (6093)) * -12886 - 22538 - -7903 + 22038 * 32686 - -2042 / (21003 + 32248 - (-13346 - 542) * -10089) * 2111 / 4220 - -3974)) * -5254 / 2398 + 25033)) * -9402 * 3216 * 6607 - 1298 * (-15505 - -12731)) * 30659 / 16347 * -4525
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/4371.arith b/chomp-bench/benches/arith/data/4371.arith new file mode 100644 index 0000000..60e07a0 --- /dev/null +++ b/chomp-bench/benches/arith/data/4371.arith @@ -0,0 +1 @@ +(12979 + (298 - 26481 * ((5923 - 6726 + 19168 / -25914 * 13914 * 23609) - -26903 + 3276 + -19404 - 1703 / -25235) / -17437 / (-2842) + -18818 + -16243 / 27336 - 27685 + (-18865 * (-18480 - -17478 - -9375 - 3372 + ((-24167 * -3007 / 5464 + -2137 * 4221 / (-15020 - 10776 + (32357 + 473 - 10821 - -2703 / 4115 / -23982 + -31973 * -30998 * (24811 - -4678 - 28662 + 10412 - -4113 - -3262 - 15999 * 3211 / -3020 * -6464) / 19146 / -4619 - (10771 / 11031 - -25649 - -7294) + (24054 * -12149 / 16568 * -12166 - -26474 - 4943 - 22824) - -22765) - -25755 * -11499 / (18888 - -14928 + 16058 * -4315 + -13126 / 25068 * (32626 + 17867 - 15824 * -1774 + ((-15480 / 19091 * -30564 + -17240) / -9200 / 29188 * -29786 / ((-982) + 14073 + -5634 + -7815 + 29947 / 10520 + 2927 * -8309) / -19134 * (-22986 / 15655 * 29077 * 23443 * 1825 / 23225 - 6852 - 15002 * -23685 - 32055 - 30674 / 986 + -6494) - -17414 * 31020 - (32479 / -28036 * 28599 * (28017 + 29925 - -165) * 28625 + -26315 - -31881 - 21934 + -21972 / (10646 - 26483 / -16697 * 24089 + 11495 - 6621 / -15025 - 2264) * (22670 * (-23759 + -11209 + 32324 + 28251 * 29072 / 11025 + -14724 * 31395 / (27313 / 4137 - 24327 / -30597 * 32152 - -13938 * 27773 / -26771 * ((-27219) / -22901) * -16091 + 5628) + 5655 * -3423 / -30790 * -29574 * 5658 * -24322) * 29173 + 19653 * 9820 - -10342 + 11260 / ((20087 * 29479 - 25646 + -14298)) - 10248) + -4591 - 14790 - 22636 - (19020 / -19470 + -4446 * 7130 - 2792 / 26197 * 4808 / 17490 - (-24149 / 19555 + -26628 + -30998 * -294)) / -7222) * 25697) - 25234) - ((11214 - -31564 + -10569 * (-4725) + (458 - 6879) - -9642 * 9799 / 26368 + 15916 * (-20414 / 5890 + 18922 * -9200 - 9208 * -8747 * (-9368 * -11378 / -7692 * 29902 * 29046 / -16717 + -26066 - 18115 + -18655 * 31486 * 20675 * 5649 - -8691) * 18040 + -19577 * ((-19713 + 10607 * ((9940 + -22331 / -7784 - -7728) * -31226 - -25168 - -26834) - -30717 - -21378 / -15243) + 22146) + -12430 - 30571 / (14939 * 24736)) - 23495 + -32181) / (11070 - -18373 * -20704 / 27354 - -14691 / -5124 * 138 * (9555 + -1883 - -28082 + -16267) / 11533 * -9131 - -22290 / -21173) - 8241 * -22064) - -20958 * -27858 * ((((465 * -26923 - -6191 - 32129 / -1975 + -11590 / 13945 / -10407 / 5364 - -15271 + -25231 + -26030 + 149 * 27863 * 24846 - 10876 * -4830) + 11095 - 14985 - 14794 * -7514 / -18341 + 15650 + (-17855) * 5609 + -14090 - 15229 / -6822 * 8778 / -26898 - 23536 + 9570 * -10457 + 30425 / (7749 * -942) * 872 - -4219 - -12045 + -22119 + -26592 - (3684 * 30521) / -30462 * -7894 + -13625 / 31285 * 11306 / -1579 * 27867 * 25023 * 27415)) * 7677 * (4351 / 1900) - -6939 * -23160)) / 16987 + -6719 / -23373 / (2642) * 28444 + -19212 * -11699 - 27354 / 32706 - -11474 * -10886) + -4212 - (29297 * 23971 / -7597) + -1913 + -24005 / -14712 * 18366 * -12986 / -13173 * (18126 + -23610 * -20339 * 32318 - 14749 * 19735 + -10451 / -27794 - 23756 / 2209 - 6534 * -2505) - 7498 / 8931) - 22490 + 10622 - 7610 * (-17030 * -21501 * (-11016 - 1621 * (-18097) - 12156 + 6527 - -4665 - -17944 * 29826 / -25521 / 29923)) + -29062 * (-3788 / -1915 + (-12670) - 5482 / 7055 + -3398 * (-10656 - 653) * 10720 * 19085 + 20268 * -10871 * 20253 * 15558) / 29909 + 20958 / -19165 * -22428 + 10859 * -5280 / -14587 - (6866 - 18222 / -29698 - 15291 - 14540 - -29608 * -29165 + 14193 / (-28121 + -4893 / 19775 - 10147 * (5616 * -23200) * 3640 * 1237 * -13558 * -1763 + (-8178) / 11790 + (17429 - 21854 * -3927 / 23656 + 12348 * 5137 / 14309 * -18488 * 13020) - 10561) / 29765 + -13417 * 2810 + (-28366 / 29629 - (14959 / 18167 * 286 - 18116 + 7058 - 10855 + 4562 * 11602 / 23425) - -2778 * -14207 / 3758 / -11312 * 6178 - ((8997 * 11541)) / -5691 * -31585 - (-24515 / (-30755) + -7348 + 27659) + -15052) / -7756 * -26870 / -2390 + 1451 / -4749 - 21657 + 30323 - 3963 / -27057 - ((9329 * -161 + -24823 + 4302 + (-28999 / 28055 * -30801 * -21663 / -31240 / -8237 * -19504 - -25665 * 14154 - -23326 / -3055 * -19901) + 8918 - -28896 / -16208 + -22354 / 22638 - 3948 * 25715 - -14005 + 1308 * 30051 * 32473 / -26979 - -25371 / 6007) / 9961 * -29370 / -22262 * 16101 / (-15091) + -14525 - 1190 / -18352 * 23841 * 21697) - 10379 - 19122 - -16478 - -24285 * ((19493 / 11580 * -32162 / 21522 - -7116 * 31276 - 17760 / -1269) + 17912 - -31889 / -2570) + 11872 - 29767) + -3577 * -25613) + -28246 / -25575 - 21962 + 20271) * 20671 + -12290 * 13347) * -32599) + 17055 - 14648 * -32470)
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/556.arith b/chomp-bench/benches/arith/data/556.arith new file mode 100644 index 0000000..88af1e8 --- /dev/null +++ b/chomp-bench/benches/arith/data/556.arith @@ -0,0 +1 @@ +(-5484 + -23384 / -3161 + -1805 / -6004 - (-21715 + (-17356 + 2879 + 27860) / -20820 + 5682 + (-17408) + -21260 - 16358 - 18313 - 5048 + -12706 - -23282 + -26554 / 29632 / 9642 / 5996 * 1932 / -31535 + -32754 / -8790 - 27069 + 19436 * -2950) * 29752 / (16375) + -31464 / -21004 * 32160 / -20038 - 23328 - 26015 + 18631 - 9077 / 13306 - 26883 - 15513 - (((-28818) / 26778) + 18091 * -1042 + 28644 / 6517) / 29645 - -29958 + 7762 / -14898 - -22849 + -10827 * -227 * -4135 - 6441 - ((8618) + -16510 * (27909 - 3712 - 27794)) + -9878 + (3237) * 13258 - -11441)
\ No newline at end of file diff --git a/chomp-bench/benches/arith/data/8380.arith b/chomp-bench/benches/arith/data/8380.arith new file mode 100644 index 0000000..dcfdbb0 --- /dev/null +++ b/chomp-bench/benches/arith/data/8380.arith @@ -0,0 +1 @@ +(28462 * -19651 / 14247 * (-22278 + 31250 + -29638 - 20753 + 10762 / 23112) * -14880 / 1803 * 18420 + (6655 * 29648 * -16937 + (-19159) * (-16866 + 25053 / 13685 + (-21958 + ((-8545 - -29613 + (-29393 * 21756) / (-15243 - -14766 + 401) * (-4207 + -19496 / (12759 / (22387 * 27329 / -4872) + -3266 - -7146))) + (-28530 / 31456 - -11453 + (-3203 * 19331 * 11378) - -4934) / -26221 * 7444 - -9611 - 2548 / (-4291) * (19939 - 17652 * -18490 - 15995 + 4129 + -25847)) * 26035 / -19909 * 21891 * -29365 - 12112) * 19406 * (16237 / -27233 + -18666) + 6023 * 12428 + -8146) * (-26919 / 5986 - -23079 + -17427 + 26955 / 25529 - -3493 / -19973 / -5188 * -178 * 12666 - 10876 - -1104 - -16470 - 7404 * 16638 / 7795) * 32620 * 4219 + -12201 * -25468 / -10335 * -26289 * 22428 * 17147 * 28204 + -15740 + 27963 / -1834 * 15208 + -20840 + -8853 / 23186 * 7171 * -21657 + -20720 - 9329 * (-26887 * 22084 - -12873 + 14025 * 9647 / (6956 * 14729 - -13212 / -25456 - 9886 * -21250 / -32208 * 12626 + 20415 - ((-18900 + 8569 - 1942 * -32150 + 31472 - 8534 + 21717 / 23736 + -8792 * -14601 * 12316 / -26682 * -30443 + (-8043 + 27691) + -32371 * (-5165 - -12477 + 3784 * 9705 + 24978 - 10177 + -17478) - -7147) / 30314 - -24951 + 10044 / -9919 / -13876 + 5888 / -28922 / (((((-26902 + -19740 * -24995) + 13186) * -7154 / 30316) / (-24064 - -20599 + 21904 * -7256 * (-24952 * -22194 / -11802 * (-21696 * -20290 * 21468 * -26168 * -12670 / 18807) - -18314 - 23253 * -11039 + 12155 * 28824 * 25373) + -11994 / 24611 + 21380 + 3066 - -9185 + 32075 * 26763)) + 1) + 13061 + 2497 + 10266 - -14752 / (-12724 / -18497 * 3560 - (2570 * -32489 + (-17883 * 15731 + -148 - 6593 * -19281 * 30045 / (15485 + 13293 - 7376)))) / -8664 / -1924) / -27667 * 15227 * 9103 - 1680 + -6672 - -30674 / (5082) - 107 - -11851 - -23245 / 2878 * 23651 * 10331 * -25412 * (-4459 + -24946 / -12944 / -25999 / -9036 / 26759 / -26419 - (-17456 - -24842 / 15026 - -19527 * (-24341 + -7206 / -11939 * -6351 + 3295 * (8699 / 3412 * -24409) / 15346 + -25676 - -9769 * (1572) + -20114 + -3716 + -21737 + -26454 / -26739 * 13205 - 879 - -20534 + -379 * -16468 + 4484 / 29022 * 15923 * -32022 + -4182) - 5414 * 18687 * (12500 + -11723 + (8288 / -3582 - -17302 * 23659 - 9002 * -4682 * -17414 / -30736 + -4073 + (-31141 / -5598 - 2150 + (28506 - -2484 - -7130 * -15410 / 28934 - -18383 / 10809 * 9650 / -22147 * -32006 * (-16674 * 23473) * 7100 - -23655 / 9090) / -28516 * 8471 + (3694 * -4919 / (-20655 + -5183 * 16791 + 19881) / (18140 + -26423 * 16806 - -22668 + 1777 / 21754 + -18878) * -6449 - 14936 * (-24531 / -10600) - -14260 / 28127 * 1095 - 14801 - 15039 * -31901 + -13969))) + 13278 / (8779 * 15547 - (23721 / -9873 / -30249 + -27235 + -3544 / 11662 + -8432 + 19145 - 27139) * (6015 / -16724 / -12829 * (26219 - -14395 + 28730 + -13143 - 5090 + 31404 - (-27231 * 10096) * -10098 * 19477 * 10445 * -28760 * -13340 / 15930 / 21714 + -17955 + 9378 * 16735 / -6281 + ((8100 / ((-17190 / -17949 + 4195 / -6935) + 1) / -16276) * 22775 + 29745 / 25889 * -14752 * 4104 / 4356) / 29073 * -16027 * -24395) * -7582) + 23766 - -25543 - (-30710 - 27673 * 14662 / -8878) - 9033 * -23921 * -29245 * 22642) / 20640) * -9821 + (9658) * -22591 * 7039 - 16308) / 3753 - -5640 * 6706 * 3420 / (-12651 - 29070 / 7389 / -416) * -24146 + (24212 / -7269 - -15208 / (32374 + 3650 - 10270 - 13418 - -31936 - 4969 + 5789 + -14896 * 1016 * -30805 + -32114 - 9443 / -3861 - 10760 * 16873 * 9567 * -22575 / 3484 / 9264) * 4807 / -19576) * 2130 + 19164 / -13610 + (12094 + 20212 / -10778 * 17763 / 15774 + 14254 * 31964 + 6091 / 5415 * 23144 / 29713 - -190 / -16128 * 23355 + 1331 - 27410 * -8901 - 27400 * -31355 + (17858 + -3190 + (-28964 / 18078 / -22396 + 12658 + 20360 + 22201 - (8492) * 14591 / (-31717 - 17009 * 18308 - 4910 * -23924 + 15675 * 3266 / -19555 - -20738) * 4645 * -3003 - (-23343 * (-4959 * (-4007 + -26454 - 29358 + 32346) / -21456 + -13990 + 11037 / -30702 * 1255 - 17499 / ((-27881 / 273 / (1328 + 14728 * -24734 / -19357 / 17496 + 32493) * -30769 * -1881 / -22200) + 1) * -5573 - (3732)) - 23892 / -31091 / -19865 - 18541 + -3308 * -31674 - 21768 / 21992 * (-2490 + -11642)) - 32226 / 5733 - -1842) / ((-4402 + (31243 + 20545 * -18947 * 15553 - 32185 - -15544 + 25570 / ((8209) / -31126 + 21064 + (-28673) + 25436 - 32078) - 13511 + 12125 * -16064 + 10661 / 28882 / 23420 / 10943) / 22054 * -22324 / -9347 / 22211) * 25765 - (-10589 / (20779 - -30851 * 3179 + 20719 * -24539 + -16354 / ((11410 / -15728 * -10628 * -9592 / 16142 * -25936 / (-28291 / -28041 * 11289 + -15627 - -9905 / 14402 + 17454 * -1568 * -24993 - -8953 + (-20670 - 5689 + 3737 * -7806 * -15294 * (-22763 - -8644 - -18758 / -25395 / -24370) * -30225) - 19673 / -15422 + -22593 - 59 + -11421 - ((-16077) - -21202 * 11773 / -4253 - (-20771 - -7582) + 5817 / -13935 - -10357) - -10102 + 25273 / 25914 - 24427 / 13902 - -28815 / 28383 - 27352 + 13656 + 14325 / -27638 * -27603 - 26080)) + 1) + 19594 - 9216 * (-31885 + 20832) + -20354 / 10756 + -5099) / (-31719 / -3525 + -12835 / -20234 - 15296 / 3642) + -18943 + -19426 / 24352 / 18293 * -24762 / -5512) / 12874 + -12099 / -32683 + (-26388 * -14529 + 21577 - -15395 + -796 - -22443 - -11281 - 1928 - -18449 * 19981 / -5746) * -18522 - 17341 * -3211 - -23896 / -4177 / -25970 / (-30811 + 9854 - 17067 / -1603 / 8715) - 9197 * -21185 / 2705 / 6728 * 15796 / -4025) + 21068 + 31455) + (4592 + 18183 + 8485 + -6834 / ((31550 / -32486) + 1)) * 28650 + -18347 * -14764) / (29109 + -29128 / -10152 - 10049 / 18626 - -23978 - -17114 * (-28591 * (26372 + -9209 + 29665) / 18096 + (-25007 - 26405 + 2996 / -28644 / 22814 / 13099) * 15043 + (28348) * -18072 + -10367 * 1771 / 20767) - -24017 / 10878 * -1658 / 5767 + -25479 - (-5300 * -17914 * -11689 / -24778 / 3109 / -30376 / -25381 * (-1069 / 25019 - 12288) * -25054 / 30116 + 3501 / 31526 / -7494 / 26226 / 16679 + (19633 - 24208 / 19295 + -17123 * 29034 - -10379 / -24282 * 9729 + -23687) / 8950 + 22610 / -238 + 7183 + -29038 - ((-5881)) - 8362 + 30766 * 12443 / 32745 + -441 / (5460 * -23905 * 32496 * -5503 / 9272 * 5890 / -8810 + 23444 + 8086 * 27276 + -31230 * 5656 * (-6672 + -8951 / 3548 - (15119) + (14038 + -32637 * (-30436 / 11796) - -6623 / (-27982 - 9243) * 6963 * 2961 / -2786 * 6306 / -31983 * 6966 - -18227 + (7107 / 27364 - (-30275 + 4739) * -6810) / 6625 * (-29555 * -19537 + (-32373 * (13809 / 686 * -14557) / 357 - 21501 + -30131 + -19297 - -12785 + 11836 + (-10698 + -2929 * (15103 - -27188 + -14376 - 28657) * 28073 - -21094 - -25321 - -22172 / ((-840 / 32399 / -2257) + 1) / 25178 + 19291 + -16804 - 2938 + -28256 - -19067 * -14804 - 10724 - 6717 * 12219 + 19278) * 384 + -18730 + -9643 * 1331 / 23274 * (-10492 * -11180 * 19068)) + 16943 - 32751 * 1054 / (605 / 18718 + -11299 * 29842 - 5193 + -23968 * 11870 + -32105) - 3308 / -5889 * 6248 - -22294 * -21184 / 31344) * 18097) + 11440 / ((23191 / -26096) + 1) / -25113 + 6796 + 17250 - -31137 * -6509 * -610 - -19131 - 12374) + -20499 * 23889 - -26401 / 28304 * -25631 * (-16212 * 25857 - -6960 - 4366 / -24739 * 11222 - -5898 * -7364 / (-9867 + ((-29863 * -13611 + 4931)) / -13053 - -2209 - (27458 + 5485 * -22927 - -17665 * -20021 - 6715 * (13821 + -6425) + 16803 - -2899 - 27223 + -9177) - -25226 / -16241 / 10111) / ((-31648 - -20677 + (-2572 / 31132 + (14093 - 4965) - 19833 * 30076 / -19279 + 15683 - (21462 + (-8251) * -2644 * -9052 * 26161 - 14665 + -21187 / 31738 - -3840 + -10100 + -18593 + -6362) / -11208 * 21530 - -23546) * (30363 / -12584 - -11088 * -5164 + -529 - 21777 - 15128 + 21018 / 32234 + 15428 / -14602 / 12522 + 26310 / 13965 * -21449 * -7531 - 20189 - 22347 + -17069 - 1050 + -8729 + -19101 / -27233 * 29316 / -11437 - -24375) - 18027 - -19182) / 18901 + 21595 * -31271) * 13036) * -12539 + 27475 * 5519) * -15957 * 17245 / -24888) + -20948 * -13385 * 23184 - 22017 / -14560 * ((30439) * 10384 + 26933) + 17764 - 30726 + -3558 / 615 / 20488 - -18229 * 12421 + -15135 / -28381 / 2158 * -27046 - -6818 - -10587 * -12195 + -3681) * -15614 + -22720) * -2670 * -16706)) + (15170 * 8216 / -18642 * (-9876 - 27928 + (-30264 / -1973 + 6299 / -3430 / -25858 + 22029 / -8165 / ((18535 - -30010 * 10248 * -23549 / 12952 / -9431) * 24519 - 23149) / 1066) + -29652 * -1597 - -25446 + -20246 + -15988) * 25322 - 17820 * -28963 * 29767 + -10944) / 29361 / 15068 / 12230) + (27836 - 20174 + -30371 + 8256 + 18864 - -31742) / (29065 / -32083 * -24616 / 17626 + -22890) / -22123 / (-17594 + -2420))
\ No newline at end of file diff --git a/chomp-bench/benches/arith/main.rs b/chomp-bench/benches/arith/main.rs new file mode 100644 index 0000000..0e4e3f4 --- /dev/null +++ b/chomp-bench/benches/arith/main.rs @@ -0,0 +1,55 @@ +use chewed::{IterWrapper, Parser}; +use chomp_bench::arith::*; +use criterion::{ + criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, + Throughput, +}; + +const INPUTS: &[&str] = &[ + include_str!("data/134.arith"), + include_str!("data/262.arith"), + include_str!("data/556.arith"), + include_str!("data/1066.arith"), + include_str!("data/2180.arith"), + include_str!("data/4371.arith"), + include_str!("data/8380.arith"), + include_str!("data/17850.arith"), + include_str!("data/35389.arith"), +]; + +fn parse_chewed(input: &str) -> i64 { + IterWrapper::new(input.chars()) + .parse::<nibble::Ast>() + .unwrap() + .into() +} + +fn parse_handwritten(input: &str) -> i64 { + parse_expr(&mut IterWrapper::new(input.chars())).unwrap() +} + +fn parse_lalrpop(parser: &lalr::ExpressionParser, input: &str) -> i64 { + parser.parse(input).unwrap() +} + +fn bench_parse(c: &mut Criterion) { + let lalr_parser = lalr::ExpressionParser::new(); + let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); + let mut group = c.benchmark_group("Arith"); + group.plot_config(plot_config); + for (i, input) in INPUTS.iter().enumerate() { + group.throughput(Throughput::Bytes(input.len() as u64)); + group.bench_with_input(BenchmarkId::new("Chewed", i), *input, |b, i| { + b.iter(|| parse_chewed(i)) + }); + group.bench_with_input(BenchmarkId::new("Handwritten", i), *input, |b, i| { + b.iter(|| parse_handwritten(i)) + }); + group.bench_with_input(BenchmarkId::new("LALRPOP", i), *input, |b, i| { + b.iter(|| parse_lalrpop(&lalr_parser, i)) + }); + } +} + +criterion_group!(benches, bench_parse); +criterion_main!(benches); diff --git a/chomp-bench/benches/json/data/111.json b/chomp-bench/benches/json/data/111.json new file mode 100644 index 0000000..c0a1d85 --- /dev/null +++ b/chomp-bench/benches/json/data/111.json @@ -0,0 +1,9 @@ +[ + { + "dt": 10, + "main": { + "temp": 273.520, + "temp_min": 273.170 + } + } +] diff --git a/chomp-bench/benches/json/data/14181.json b/chomp-bench/benches/json/data/14181.json new file mode 100644 index 0000000..64961cb --- /dev/null +++ b/chomp-bench/benches/json/data/14181.json @@ -0,0 +1,719 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 1612882800, + "main": { + "temp": 273.52, + "feels_like": 266.68, + "temp_min": 273.17, + "temp_max": 273.52, + "pressure": 1009, + "sea_level": 1009, + "grnd_level": 997, + "humidity": 81, + "temp_kf": 0.35 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 67 + }, + "wind": { + "speed": 6.45, + "deg": 78 + }, + "visibility": 10000, + "pop": 0.12, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-09 15:00:00" + }, + { + "dt": 1612893600, + "main": { + "temp": 271.54, + "feels_like": 264.77, + "temp_min": 270.9, + "temp_max": 271.54, + "pressure": 1007, + "sea_level": 1007, + "grnd_level": 996, + "humidity": 91, + "temp_kf": 0.64 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 86 + }, + "wind": { + "speed": 6.29, + "deg": 63 + }, + "visibility": 10000, + "pop": 0.08, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 18:00:00" + }, + { + "dt": 1612904400, + "main": { + "temp": 270.28, + "feels_like": 263.77, + "temp_min": 270.03, + "temp_max": 270.28, + "pressure": 1008, + "sea_level": 1008, + "grnd_level": 998, + "humidity": 96, + "temp_kf": 0.25 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 41 + }, + "wind": { + "speed": 5.83, + "deg": 65 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 21:00:00" + }, + { + "dt": 1612915200, + "main": { + "temp": 270.06, + "feels_like": 263.35, + "temp_min": 270.03, + "temp_max": 270.06, + "pressure": 1010, + "sea_level": 1010, + "grnd_level": 999, + "humidity": 97, + "temp_kf": 0.03 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 44 + }, + "wind": { + "speed": 6.09, + "deg": 56 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 00:00:00" + }, + { + "dt": 1612926000, + "main": { + "temp": 269.06, + "feels_like": 262.65, + "temp_min": 269.06, + "temp_max": 269.06, + "pressure": 1010, + "sea_level": 1010, + "grnd_level": 999, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02n" + } + ], + "clouds": { + "all": 18 + }, + "wind": { + "speed": 5.51, + "deg": 44 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 03:00:00" + }, + { + "dt": 1612936800, + "main": { + "temp": 268.96, + "feels_like": 263.1, + "temp_min": 268.96, + "temp_max": 268.96, + "pressure": 1012, + "sea_level": 1012, + "grnd_level": 1001, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02n" + } + ], + "clouds": { + "all": 13 + }, + "wind": { + "speed": 4.7, + "deg": 36 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 06:00:00" + }, + { + "dt": 1612947600, + "main": { + "temp": 270.73, + "feels_like": 264.69, + "temp_min": 270.73, + "temp_max": 270.73, + "pressure": 1015, + "sea_level": 1015, + "grnd_level": 1004, + "humidity": 95, + "temp_kf": 0 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03d" + } + ], + "clouds": { + "all": 41 + }, + "wind": { + "speed": 5.2, + "deg": 42 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-10 09:00:00" + }, + { + "dt": 1612958400, + "main": { + "temp": 273.21, + "feels_like": 267.19, + "temp_min": 273.21, + "temp_max": 273.21, + "pressure": 1017, + "sea_level": 1017, + "grnd_level": 1007, + "humidity": 91, + "temp_kf": 0 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03d" + } + ], + "clouds": { + "all": 30 + }, + "wind": { + "speed": 5.51, + "deg": 40 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-10 12:00:00" + }, + { + "dt": 1612969200, + "main": { + "temp": 273.22, + "feels_like": 267.49, + "temp_min": 273.22, + "temp_max": 273.22, + "pressure": 1018, + "sea_level": 1018, + "grnd_level": 1007, + "humidity": 91, + "temp_kf": 0 + }, + "weather": [ + { + "id": 600, + "main": "Snow", + "description": "light snow", + "icon": "13d" + } + ], + "clouds": { + "all": 62 + }, + "wind": { + "speed": 5.11, + "deg": 35 + }, + "visibility": 10000, + "pop": 0.2, + "snow": { + "3h": 0.13 + }, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-10 15:00:00" + }, + { + "dt": 1612980000, + "main": { + "temp": 269.17, + "feels_like": 264.29, + "temp_min": 269.17, + "temp_max": 269.17, + "pressure": 1021, + "sea_level": 1021, + "grnd_level": 1010, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 31 + }, + "wind": { + "speed": 3.34, + "deg": 21 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 18:00:00" + }, + { + "dt": 1612990800, + "main": { + "temp": 268.37, + "feels_like": 263.59, + "temp_min": 268.37, + "temp_max": 268.37, + "pressure": 1023, + "sea_level": 1023, + "grnd_level": 1012, + "humidity": 96, + "temp_kf": 0 + }, + "weather": [ + { + "id": 800, + "main": "Clear", + "description": "clear sky", + "icon": "01n" + } + ], + "clouds": { + "all": 0 + }, + "wind": { + "speed": 3.05, + "deg": 34 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 21:00:00" + }, + { + "dt": 1613001600, + "main": { + "temp": 267.89, + "feels_like": 263.1, + "temp_min": 267.89, + "temp_max": 267.89, + "pressure": 1024, + "sea_level": 1024, + "grnd_level": 1013, + "humidity": 96, + "temp_kf": 0 + }, + "weather": [ + { + "id": 800, + "main": "Clear", + "description": "clear sky", + "icon": "01n" + } + ], + "clouds": { + "all": 0 + }, + "wind": { + "speed": 3, + "deg": 45 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-11 00:00:00" + }, + { + "dt": 1613012400, + "main": { + "temp": 267.84, + "feels_like": 262.92, + "temp_min": 267.84, + "temp_max": 267.84, + "pressure": 1025, + "sea_level": 1025, + "grnd_level": 1014, + "humidity": 96, + "temp_kf": 0 + }, + "weather": [ + { + "id": 800, + "main": "Clear", + "description": "clear sky", + "icon": "01n" + } + ], + "clouds": { + "all": 0 + }, + "wind": { + "speed": 3.17, + "deg": 58 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-11 03:00:00" + }, + { + "dt": 1613023200, + "main": { + "temp": 267.92, + "feels_like": 263.14, + "temp_min": 267.92, + "temp_max": 267.92, + "pressure": 1026, + "sea_level": 1026, + "grnd_level": 1015, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02n" + } + ], + "clouds": { + "all": 20 + }, + "wind": { + "speed": 3.01, + "deg": 88 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-11 06:00:00" + }, + { + "dt": 1613034000, + "main": { + "temp": 269.92, + "feels_like": 264.79, + "temp_min": 269.92, + "temp_max": 269.92, + "pressure": 1027, + "sea_level": 1027, + "grnd_level": 1016, + "humidity": 96, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02d" + } + ], + "clouds": { + "all": 18 + }, + "wind": { + "speed": 3.79, + "deg": 118 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-11 09:00:00" + }, + { + "dt": 1613044800, + "main": { + "temp": 272.78, + "feels_like": 266.21, + "temp_min": 272.78, + "temp_max": 272.78, + "pressure": 1028, + "sea_level": 1028, + "grnd_level": 1017, + "humidity": 93, + "temp_kf": 0 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 56 + }, + "wind": { + "speed": 6.28, + "deg": 123 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-11 12:00:00" + }, + { + "dt": 1613055600, + "main": { + "temp": 272.43, + "feels_like": 265.67, + "temp_min": 272.43, + "temp_max": 272.43, + "pressure": 1027, + "sea_level": 1027, + "grnd_level": 1016, + "humidity": 89, + "temp_kf": 0 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 100 + }, + "wind": { + "speed": 6.38, + "deg": 124 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-11 15:00:00" + }, + { + "dt": 1613066400, + "main": { + "temp": 269.8, + "feels_like": 263.76, + "temp_min": 269.8, + "temp_max": 269.8, + "pressure": 1027, + "sea_level": 1027, + "grnd_level": 1015, + "humidity": 93, + "temp_kf": 0 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 98 + }, + "wind": { + "speed": 5, + "deg": 106 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-11 18:00:00" + }, + { + "dt": 1613077200, + "main": { + "temp": 270.12, + "feels_like": 263.78, + "temp_min": 270.12, + "temp_max": 270.12, + "pressure": 1026, + "sea_level": 1026, + "grnd_level": 1015, + "humidity": 93, + "temp_kf": 0 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 97 + }, + "wind": { + "speed": 5.48, + "deg": 113 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-11 21:00:00" + }, + { + "dt": 1613088000, + "main": { + "temp": 270.55, + "feels_like": 263.21, + "temp_min": 270.55, + "temp_max": 270.55, + "pressure": 1026, + "sea_level": 1026, + "grnd_level": 1015, + "humidity": 91, + "temp_kf": 0 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 99 + }, + "wind": { + "speed": 6.93, + "deg": 116 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-12 00:00:00" + }, + { + "dt": 16130988000, + "main": { + "temp": 270.4, + "feels_like": 263, + "min": 270.4, + "max": 270.4 + } + } + ] +} diff --git a/chomp-bench/benches/json/data/1773.json b/chomp-bench/benches/json/data/1773.json new file mode 100644 index 0000000..a91ff00 --- /dev/null +++ b/chomp-bench/benches/json/data/1773.json @@ -0,0 +1,91 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 1612882800, + "main": { + "temp": 273.52, + "feels_like": 266.68, + "temp_min": 273.17, + "temp_max": 273.52, + "pressure": 1009, + "sea_level": 1009, + "grnd_level": 997, + "humidity": 81, + "temp_kf": 0.35 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 67 + }, + "wind": { + "speed": 6.45, + "deg": 78 + }, + "visibility": 10000, + "pop": 0.12, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-09 15:00:00" + }, + { + "dt": 1612893600, + "main": { + "temp": 271.54, + "feels_like": 264.77, + "temp_min": 270.9, + "temp_max": 271.54, + "pressure": 1007, + "sea_level": 1007, + "grnd_level": 996, + "humidity": 91, + "temp_kf": 0.64 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 86 + }, + "wind": { + "speed": 6.29, + "deg": 63 + }, + "visibility": 10000, + "pop": 0.08, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 18:00:00" + }, + { + "dt": 1612904400, + "main": { + "temp": 270.28, + "feels_like": 263.77, + "temp_min": 270.03, + "temp_max": 270.28, + "pressure": 1008, + "sea_level": 1008, + "grnd_level": 998, + "humidity": 9 + }, + "weather": [{"id": 802}] + } + ] +} diff --git a/chomp-bench/benches/json/data/222.json b/chomp-bench/benches/json/data/222.json new file mode 100644 index 0000000..a7facd5 --- /dev/null +++ b/chomp-bench/benches/json/data/222.json @@ -0,0 +1,14 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 10, + "main": { + "temp": 273.520, + "temp_min": 273.170 + } + } + ] +} diff --git a/chomp-bench/benches/json.rs b/chomp-bench/benches/json/data/28362.json index c6c73ef..a02dc96 100644 --- a/chomp-bench/benches/json.rs +++ b/chomp-bench/benches/json/data/28362.json @@ -1,1286 +1,4 @@ -use chewed::{IterWrapper, Parser}; -use chomp_bench::json::*; -use criterion::{ - criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, - Throughput, -}; - -const INPUTS: &[&str] = &[ - r#"{ - "id": 803, - "main": "Clouds" -}"#, - r#"{ - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" -}"#, - r#"{ - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 -}"#, - r#"{ - "dt": 1612882800, - "main": { - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ] -}"#, - r#"{ - "cod": "200", - "message": 0, - "cnt": 40, - "list": [ - { - "dt": 1612882800, - "main": { - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 67 - }, - "wind": { - "speed": 6.45, - "deg": 78 - }, - "visibility": 10000, - "pop": 0.12, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-09 15:00:00" - } - ] -}"#, - r#"{ - "cod": "200", - "message": 0, - "cnt": 40, - "list": [ - { - "dt": 1612882800, - "main": { - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 67 - }, - "wind": { - "speed": 6.45, - "deg": 78 - }, - "visibility": 10000, - "pop": 0.12, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-09 15:00:00" - }, - { - "dt": 1612893600, - "main": { - "temp": 271.54, - "feels_like": 264.77, - "temp_min": 270.9, - "temp_max": 271.54, - "pressure": 1007, - "sea_level": 1007, - "grnd_level": 996, - "humidity": 91, - "temp_kf": 0.64 - }, - "weather": [ - { - "id": 804, - "main": "Clouds", - "description": "overcast clouds", - "icon": "04n" - } - ], - "clouds": { - "all": 86 - }, - "wind": { - "speed": 6.29, - "deg": 63 - } - } - ], - "city": { - "id": 2654410, - "name": "Buckingham", - "coord": { - "lat": 52, - "lon": -1 - }, - "country": "GB", - "population": 12791, - "timezone": 0, - "sunrise": 1612855819, - "sunset": 1612890374 - } -}"#, - r#"{ - "cod": "200", - "message": 0, - "cnt": 40, - "list": [ - { - "dt": 1612882800, - "main": { - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 67 - }, - "wind": { - "speed": 6.45, - "deg": 78 - }, - "visibility": 10000, - "pop": 0.12, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-09 15:00:00" - }, - { - "dt": 1612893600, - "main": { - "temp": 271.54, - "feels_like": 264.77, - "temp_min": 270.9, - "temp_max": 271.54, - "pressure": 1007, - "sea_level": 1007, - "grnd_level": 996, - "humidity": 91, - "temp_kf": 0.64 - }, - "weather": [ - { - "id": 804, - "main": "Clouds", - "description": "overcast clouds", - "icon": "04n" - } - ], - "clouds": { - "all": 86 - }, - "wind": { - "speed": 6.29, - "deg": 63 - }, - "visibility": 10000, - "pop": 0.08, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-09 18:00:00" - }, - { - "dt": 1612904400, - "main": { - "temp": 270.28, - "feels_like": 263.77, - "temp_min": 270.03, - "temp_max": 270.28, - "pressure": 1008, - "sea_level": 1008, - "grnd_level": 998, - "humidity": 96, - "temp_kf": 0.25 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 41 - }, - "wind": { - "speed": 5.83, - "deg": 65 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-09 21:00:00" - }, - { - "dt": 1612915200, - "main": { - "temp": 270.06, - "feels_like": 263.35, - "temp_min": 270.03, - "temp_max": 270.06, - "pressure": 1010, - "sea_level": 1010, - "grnd_level": 999, - "humidity": 97, - "temp_kf": 0.03 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 44 - }, - "wind": { - "speed": 6.09, - "deg": 56 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 00:00:00" - } - ], - "city": { - "id": 2654410, - "name": "Buckingham", - "coord": { - "lat": 52, - "lon": -1 - }, - "country": "GB", - "population": 12791, - "timezone": 0, - "sunrise": 1612855819, - "sunset": 1612890374 - } -}"#, - r#"{ - "cod": "200", - "message": 0, - "cnt": 40, - "list": [ - { - "dt": 1612882800, - "main": { - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 67 - }, - "wind": { - "speed": 6.45, - "deg": 78 - }, - "visibility": 10000, - "pop": 0.12, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-09 15:00:00" - }, - { - "dt": 1612893600, - "main": { - "temp": 271.54, - "feels_like": 264.77, - "temp_min": 270.9, - "temp_max": 271.54, - "pressure": 1007, - "sea_level": 1007, - "grnd_level": 996, - "humidity": 91, - "temp_kf": 0.64 - }, - "weather": [ - { - "id": 804, - "main": "Clouds", - "description": "overcast clouds", - "icon": "04n" - } - ], - "clouds": { - "all": 86 - }, - "wind": { - "speed": 6.29, - "deg": 63 - }, - "visibility": 10000, - "pop": 0.08, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-09 18:00:00" - }, - { - "dt": 1612904400, - "main": { - "temp": 270.28, - "feels_like": 263.77, - "temp_min": 270.03, - "temp_max": 270.28, - "pressure": 1008, - "sea_level": 1008, - "grnd_level": 998, - "humidity": 96, - "temp_kf": 0.25 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 41 - }, - "wind": { - "speed": 5.83, - "deg": 65 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-09 21:00:00" - }, - { - "dt": 1612915200, - "main": { - "temp": 270.06, - "feels_like": 263.35, - "temp_min": 270.03, - "temp_max": 270.06, - "pressure": 1010, - "sea_level": 1010, - "grnd_level": 999, - "humidity": 97, - "temp_kf": 0.03 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 44 - }, - "wind": { - "speed": 6.09, - "deg": 56 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 00:00:00" - }, - { - "dt": 1612926000, - "main": { - "temp": 269.06, - "feels_like": 262.65, - "temp_min": 269.06, - "temp_max": 269.06, - "pressure": 1010, - "sea_level": 1010, - "grnd_level": 999, - "humidity": 97, - "temp_kf": 0 - }, - "weather": [ - { - "id": 801, - "main": "Clouds", - "description": "few clouds", - "icon": "02n" - } - ], - "clouds": { - "all": 18 - }, - "wind": { - "speed": 5.51, - "deg": 44 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 03:00:00" - }, - { - "dt": 1612936800, - "main": { - "temp": 268.96, - "feels_like": 263.1, - "temp_min": 268.96, - "temp_max": 268.96, - "pressure": 1012, - "sea_level": 1012, - "grnd_level": 1001, - "humidity": 97, - "temp_kf": 0 - }, - "weather": [ - { - "id": 801, - "main": "Clouds", - "description": "few clouds", - "icon": "02n" - } - ], - "clouds": { - "all": 13 - }, - "wind": { - "speed": 4.7, - "deg": 36 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 06:00:00" - }, - { - "dt": 1612947600, - "main": { - "temp": 270.73, - "feels_like": 264.69, - "temp_min": 270.73, - "temp_max": 270.73, - "pressure": 1015, - "sea_level": 1015, - "grnd_level": 1004, - "humidity": 95, - "temp_kf": 0 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03d" - } - ], - "clouds": { - "all": 41 - }, - "wind": { - "speed": 5.2, - "deg": 42 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-10 09:00:00" - }, - { - "dt": 1612958400, - "main": { - "temp": 273.21, - "feels_like": 267.19, - "temp_min": 273.21, - "temp_max": 273.21, - "pressure": 1017, - "sea_level": 1017, - "grnd_level": 1007, - "humidity": 91, - "temp_kf": 0 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03d" - } - ], - "clouds": { - "all": 30 - }, - "wind": { - "speed": 5.51, - "deg": 40 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-10 12:00:00" - }, - { - "dt": 1612969200, - "main": { - "temp": 273.22, - "feels_like": 267.49, - "temp_min": 273.22, - "temp_max": 273.22, - "pressure": 1018, - "sea_level": 1018, - "grnd_level": 1007, - "humidity": 91, - "temp_kf": 0 - } - } - ], - "city": { - "id": 2654410, - "name": "Buckingham", - "coord": { - "lat": 52, - "lon": -1 - }, - "country": "GB", - "population": 12791, - "timezone": 0, - "sunrise": 1612855819, - "sunset": 1612890374 - } -}"#, - r#"{ - "cod": "200", - "message": 0, - "cnt": 40, - "list": [ - { - "dt": 1612882800, - "main": { - "temp": 273.52, - "feels_like": 266.68, - "temp_min": 273.17, - "temp_max": 273.52, - "pressure": 1009, - "sea_level": 1009, - "grnd_level": 997, - "humidity": 81, - "temp_kf": 0.35 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 67 - }, - "wind": { - "speed": 6.45, - "deg": 78 - }, - "visibility": 10000, - "pop": 0.12, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-09 15:00:00" - }, - { - "dt": 1612893600, - "main": { - "temp": 271.54, - "feels_like": 264.77, - "temp_min": 270.9, - "temp_max": 271.54, - "pressure": 1007, - "sea_level": 1007, - "grnd_level": 996, - "humidity": 91, - "temp_kf": 0.64 - }, - "weather": [ - { - "id": 804, - "main": "Clouds", - "description": "overcast clouds", - "icon": "04n" - } - ], - "clouds": { - "all": 86 - }, - "wind": { - "speed": 6.29, - "deg": 63 - }, - "visibility": 10000, - "pop": 0.08, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-09 18:00:00" - }, - { - "dt": 1612904400, - "main": { - "temp": 270.28, - "feels_like": 263.77, - "temp_min": 270.03, - "temp_max": 270.28, - "pressure": 1008, - "sea_level": 1008, - "grnd_level": 998, - "humidity": 96, - "temp_kf": 0.25 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 41 - }, - "wind": { - "speed": 5.83, - "deg": 65 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-09 21:00:00" - }, - { - "dt": 1612915200, - "main": { - "temp": 270.06, - "feels_like": 263.35, - "temp_min": 270.03, - "temp_max": 270.06, - "pressure": 1010, - "sea_level": 1010, - "grnd_level": 999, - "humidity": 97, - "temp_kf": 0.03 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 44 - }, - "wind": { - "speed": 6.09, - "deg": 56 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 00:00:00" - }, - { - "dt": 1612926000, - "main": { - "temp": 269.06, - "feels_like": 262.65, - "temp_min": 269.06, - "temp_max": 269.06, - "pressure": 1010, - "sea_level": 1010, - "grnd_level": 999, - "humidity": 97, - "temp_kf": 0 - }, - "weather": [ - { - "id": 801, - "main": "Clouds", - "description": "few clouds", - "icon": "02n" - } - ], - "clouds": { - "all": 18 - }, - "wind": { - "speed": 5.51, - "deg": 44 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 03:00:00" - }, - { - "dt": 1612936800, - "main": { - "temp": 268.96, - "feels_like": 263.1, - "temp_min": 268.96, - "temp_max": 268.96, - "pressure": 1012, - "sea_level": 1012, - "grnd_level": 1001, - "humidity": 97, - "temp_kf": 0 - }, - "weather": [ - { - "id": 801, - "main": "Clouds", - "description": "few clouds", - "icon": "02n" - } - ], - "clouds": { - "all": 13 - }, - "wind": { - "speed": 4.7, - "deg": 36 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 06:00:00" - }, - { - "dt": 1612947600, - "main": { - "temp": 270.73, - "feels_like": 264.69, - "temp_min": 270.73, - "temp_max": 270.73, - "pressure": 1015, - "sea_level": 1015, - "grnd_level": 1004, - "humidity": 95, - "temp_kf": 0 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03d" - } - ], - "clouds": { - "all": 41 - }, - "wind": { - "speed": 5.2, - "deg": 42 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-10 09:00:00" - }, - { - "dt": 1612958400, - "main": { - "temp": 273.21, - "feels_like": 267.19, - "temp_min": 273.21, - "temp_max": 273.21, - "pressure": 1017, - "sea_level": 1017, - "grnd_level": 1007, - "humidity": 91, - "temp_kf": 0 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03d" - } - ], - "clouds": { - "all": 30 - }, - "wind": { - "speed": 5.51, - "deg": 40 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-10 12:00:00" - }, - { - "dt": 1612969200, - "main": { - "temp": 273.22, - "feels_like": 267.49, - "temp_min": 273.22, - "temp_max": 273.22, - "pressure": 1018, - "sea_level": 1018, - "grnd_level": 1007, - "humidity": 91, - "temp_kf": 0 - }, - "weather": [ - { - "id": 600, - "main": "Snow", - "description": "light snow", - "icon": "13d" - } - ], - "clouds": { - "all": 62 - }, - "wind": { - "speed": 5.11, - "deg": 35 - }, - "visibility": 10000, - "pop": 0.2, - "snow": { - "3h": 0.13 - }, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-10 15:00:00" - }, - { - "dt": 1612980000, - "main": { - "temp": 269.17, - "feels_like": 264.29, - "temp_min": 269.17, - "temp_max": 269.17, - "pressure": 1021, - "sea_level": 1021, - "grnd_level": 1010, - "humidity": 97, - "temp_kf": 0 - }, - "weather": [ - { - "id": 802, - "main": "Clouds", - "description": "scattered clouds", - "icon": "03n" - } - ], - "clouds": { - "all": 31 - }, - "wind": { - "speed": 3.34, - "deg": 21 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 18:00:00" - }, - { - "dt": 1612990800, - "main": { - "temp": 268.37, - "feels_like": 263.59, - "temp_min": 268.37, - "temp_max": 268.37, - "pressure": 1023, - "sea_level": 1023, - "grnd_level": 1012, - "humidity": 96, - "temp_kf": 0 - }, - "weather": [ - { - "id": 800, - "main": "Clear", - "description": "clear sky", - "icon": "01n" - } - ], - "clouds": { - "all": 0 - }, - "wind": { - "speed": 3.05, - "deg": 34 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-10 21:00:00" - }, - { - "dt": 1613001600, - "main": { - "temp": 267.89, - "feels_like": 263.1, - "temp_min": 267.89, - "temp_max": 267.89, - "pressure": 1024, - "sea_level": 1024, - "grnd_level": 1013, - "humidity": 96, - "temp_kf": 0 - }, - "weather": [ - { - "id": 800, - "main": "Clear", - "description": "clear sky", - "icon": "01n" - } - ], - "clouds": { - "all": 0 - }, - "wind": { - "speed": 3, - "deg": 45 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-11 00:00:00" - }, - { - "dt": 1613012400, - "main": { - "temp": 267.84, - "feels_like": 262.92, - "temp_min": 267.84, - "temp_max": 267.84, - "pressure": 1025, - "sea_level": 1025, - "grnd_level": 1014, - "humidity": 96, - "temp_kf": 0 - }, - "weather": [ - { - "id": 800, - "main": "Clear", - "description": "clear sky", - "icon": "01n" - } - ], - "clouds": { - "all": 0 - }, - "wind": { - "speed": 3.17, - "deg": 58 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-11 03:00:00" - }, - { - "dt": 1613023200, - "main": { - "temp": 267.92, - "feels_like": 263.14, - "temp_min": 267.92, - "temp_max": 267.92, - "pressure": 1026, - "sea_level": 1026, - "grnd_level": 1015, - "humidity": 97, - "temp_kf": 0 - }, - "weather": [ - { - "id": 801, - "main": "Clouds", - "description": "few clouds", - "icon": "02n" - } - ], - "clouds": { - "all": 20 - }, - "wind": { - "speed": 3.01, - "deg": 88 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "n" - }, - "dt_txt": "2021-02-11 06:00:00" - }, - { - "dt": 1613034000, - "main": { - "temp": 269.92, - "feels_like": 264.79, - "temp_min": 269.92, - "temp_max": 269.92, - "pressure": 1027, - "sea_level": 1027, - "grnd_level": 1016, - "humidity": 96, - "temp_kf": 0 - }, - "weather": [ - { - "id": 801, - "main": "Clouds", - "description": "few clouds", - "icon": "02d" - } - ], - "clouds": { - "all": 18 - }, - "wind": { - "speed": 3.79, - "deg": 118 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-11 09:00:00" - }, - { - "dt": 1613044800, - "main": { - "temp": 272.78, - "feels_like": 266.21, - "temp_min": 272.78, - "temp_max": 272.78, - "pressure": 1028, - "sea_level": 1028, - "grnd_level": 1017, - "humidity": 93, - "temp_kf": 0 - }, - "weather": [ - { - "id": 803, - "main": "Clouds", - "description": "broken clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 56 - }, - "wind": { - "speed": 6.28, - "deg": 123 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-11 12:00:00" - }, - { - "dt": 1613055600, - "main": { - "temp": 272.43, - "feels_like": 265.67, - "temp_min": 272.43, - "temp_max": 272.43, - "pressure": 1027, - "sea_level": 1027, - "grnd_level": 1016, - "humidity": 89, - "temp_kf": 0 - }, - "weather": [ - { - "id": 804, - "main": "Clouds", - "description": "overcast clouds", - "icon": "04d" - } - ], - "clouds": { - "all": 100 - }, - "wind": { - "speed": 6.38, - "deg": 124 - }, - "visibility": 10000, - "pop": 0, - "sys": { - "pod": "d" - }, - "dt_txt": "2021-02-11 15:00:00" - }, - { - "dt": 1613066400, - "main": { - "temp": 269.8, - "feels_like": 263.76, - "temp_min": 269.8, - "temp_max": 269.8, - "pressure": 1027, - "sea_level": 1027, - "grnd_level": 1015, - "humidity": 93 - } - } - ], - "city": { - "id": 2654410, - "name": "Buckingham", - "coord": { - "lat": 52, - "lon": -1 - }, - "country": "GB", - "population": 12791, - "timezone": 0, - "sunrise": 1612855819, - "sunset": 1612890374 - } -}"#, - r#"{ +{ "cod": "200", "message": 0, "cnt": 40, @@ -2711,42 +1429,4 @@ const INPUTS: &[&str] = &[ "sunrise": 1612855819, "sunset": 1612890374 } -}"#, -]; - -fn parse_chewed(input: &str) -> Value { - IterWrapper::new(input.chars()) - .parse::<nibble::Ast>() - .unwrap() - .into() -} - -fn parse_handwritten(input: &str) -> Value { - IterWrapper::new(input.chars()).parse().unwrap() -} - -fn parse_lalrpop(parser: &lalr::ValueParser, input: &str) -> Value { - parser.parse(input).unwrap() -} - -fn bench_parse(c: &mut Criterion) { - let lalr_parser = lalr::ValueParser::new(); - let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); - let mut group = c.benchmark_group("JSON"); - group.plot_config(plot_config); - for (i, input) in INPUTS.iter().enumerate() { - group.throughput(Throughput::Bytes(input.len() as u64)); - group.bench_with_input(BenchmarkId::new("Chewed", i), *input, |b, i| { - b.iter(|| parse_chewed(i)) - }); - group.bench_with_input(BenchmarkId::new("Handwritten", i), *input, |b, i| { - b.iter(|| parse_handwritten(i)) - }); - group.bench_with_input(BenchmarkId::new("LALRPOP", i), *input, |b, i| { - b.iter(|| parse_lalrpop(&lalr_parser, i)) - }); - } } - -criterion_group!(benches, bench_parse); -criterion_main!(benches); diff --git a/chomp-bench/benches/json/data/3545.json b/chomp-bench/benches/json/data/3545.json new file mode 100644 index 0000000..258f759 --- /dev/null +++ b/chomp-bench/benches/json/data/3545.json @@ -0,0 +1,182 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 1612882800, + "main": { + "temp": 273.52, + "feels_like": 266.68, + "temp_min": 273.17, + "temp_max": 273.52, + "pressure": 1009, + "sea_level": 1009, + "grnd_level": 997, + "humidity": 81, + "temp_kf": 0.35 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 67 + }, + "wind": { + "speed": 6.45, + "deg": 78 + }, + "visibility": 10000, + "pop": 0.12, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-09 15:00:00" + }, + { + "dt": 1612893600, + "main": { + "temp": 271.54, + "feels_like": 264.77, + "temp_min": 270.9, + "temp_max": 271.54, + "pressure": 1007, + "sea_level": 1007, + "grnd_level": 996, + "humidity": 91, + "temp_kf": 0.64 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 86 + }, + "wind": { + "speed": 6.29, + "deg": 63 + }, + "visibility": 10000, + "pop": 0.08, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 18:00:00" + }, + { + "dt": 1612904400, + "main": { + "temp": 270.28, + "feels_like": 263.77, + "temp_min": 270.03, + "temp_max": 270.28, + "pressure": 1008, + "sea_level": 1008, + "grnd_level": 998, + "humidity": 96, + "temp_kf": 0.25 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 41 + }, + "wind": { + "speed": 5.83, + "deg": 65 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 21:00:00" + }, + { + "dt": 1612915200, + "main": { + "temp": 270.06, + "feels_like": 263.35, + "temp_min": 270.03, + "temp_max": 270.06, + "pressure": 1010, + "sea_level": 1010, + "grnd_level": 999, + "humidity": 97, + "temp_kf": 0.03 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 44 + }, + "wind": { + "speed": 6.09, + "deg": 56 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 00:00:00" + }, + { + "dt": 1612926000, + "main": { + "temp": 269.06, + "feels_like": 262.65, + "temp_min": 269.06, + "temp_max": 269.06, + "pressure": 1010, + "sea_level": 1010, + "grnd_level": 999, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02n" + } + ], + "clouds": { + "all": 18 + }, + "wind": { + "speed": 5.51, + "deg": 44 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "200" + } + ] +} diff --git a/chomp-bench/benches/json/data/443.json b/chomp-bench/benches/json/data/443.json new file mode 100644 index 0000000..28cc43d --- /dev/null +++ b/chomp-bench/benches/json/data/443.json @@ -0,0 +1,20 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 1612882800, + "main": { + "temp": 273.520, + "feels_like": 266.680, + "temp_min": 273.170, + "temp_max": 273.520, + "pressure": 1009, + "sea_level": 1009, + "grnd_level": 997, + "humidity": 81 + } + } + ] +} diff --git a/chomp-bench/benches/json/data/55.json b/chomp-bench/benches/json/data/55.json new file mode 100644 index 0000000..d28f6c9 --- /dev/null +++ b/chomp-bench/benches/json/data/55.json @@ -0,0 +1,4 @@ +{ + "temp": 273.520123, + "temp_min": 273.170456 +} diff --git a/chomp-bench/benches/json/data/7091.json b/chomp-bench/benches/json/data/7091.json new file mode 100644 index 0000000..675dc3e --- /dev/null +++ b/chomp-bench/benches/json/data/7091.json @@ -0,0 +1,360 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 1612882800, + "main": { + "temp": 273.52, + "feels_like": 266.68, + "temp_min": 273.17, + "temp_max": 273.52, + "pressure": 1009, + "sea_level": 1009, + "grnd_level": 997, + "humidity": 81, + "temp_kf": 0.35 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 67 + }, + "wind": { + "speed": 6.45, + "deg": 78 + }, + "visibility": 10000, + "pop": 0.12, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-09 15:00:00" + }, + { + "dt": 1612893600, + "main": { + "temp": 271.54, + "feels_like": 264.77, + "temp_min": 270.9, + "temp_max": 271.54, + "pressure": 1007, + "sea_level": 1007, + "grnd_level": 996, + "humidity": 91, + "temp_kf": 0.64 + }, + "weather": [ + { + "id": 804, + "main": "Clouds", + "description": "overcast clouds", + "icon": "04n" + } + ], + "clouds": { + "all": 86 + }, + "wind": { + "speed": 6.29, + "deg": 63 + }, + "visibility": 10000, + "pop": 0.08, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 18:00:00" + }, + { + "dt": 1612904400, + "main": { + "temp": 270.28, + "feels_like": 263.77, + "temp_min": 270.03, + "temp_max": 270.28, + "pressure": 1008, + "sea_level": 1008, + "grnd_level": 998, + "humidity": 96, + "temp_kf": 0.25 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 41 + }, + "wind": { + "speed": 5.83, + "deg": 65 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-09 21:00:00" + }, + { + "dt": 1612915200, + "main": { + "temp": 270.06, + "feels_like": 263.35, + "temp_min": 270.03, + "temp_max": 270.06, + "pressure": 1010, + "sea_level": 1010, + "grnd_level": 999, + "humidity": 97, + "temp_kf": 0.03 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 44 + }, + "wind": { + "speed": 6.09, + "deg": 56 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 00:00:00" + }, + { + "dt": 1612926000, + "main": { + "temp": 269.06, + "feels_like": 262.65, + "temp_min": 269.06, + "temp_max": 269.06, + "pressure": 1010, + "sea_level": 1010, + "grnd_level": 999, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02n" + } + ], + "clouds": { + "all": 18 + }, + "wind": { + "speed": 5.51, + "deg": 44 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 03:00:00" + }, + { + "dt": 1612936800, + "main": { + "temp": 268.96, + "feels_like": 263.1, + "temp_min": 268.96, + "temp_max": 268.96, + "pressure": 1012, + "sea_level": 1012, + "grnd_level": 1001, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 801, + "main": "Clouds", + "description": "few clouds", + "icon": "02n" + } + ], + "clouds": { + "all": 13 + }, + "wind": { + "speed": 4.7, + "deg": 36 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 06:00:00" + }, + { + "dt": 1612947600, + "main": { + "temp": 270.73, + "feels_like": 264.69, + "temp_min": 270.73, + "temp_max": 270.73, + "pressure": 1015, + "sea_level": 1015, + "grnd_level": 1004, + "humidity": 95, + "temp_kf": 0 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03d" + } + ], + "clouds": { + "all": 41 + }, + "wind": { + "speed": 5.2, + "deg": 42 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-10 09:00:00" + }, + { + "dt": 1612958400, + "main": { + "temp": 273.21, + "feels_like": 267.19, + "temp_min": 273.21, + "temp_max": 273.21, + "pressure": 1017, + "sea_level": 1017, + "grnd_level": 1007, + "humidity": 91, + "temp_kf": 0 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03d" + } + ], + "clouds": { + "all": 30 + }, + "wind": { + "speed": 5.51, + "deg": 40 + }, + "visibility": 10000, + "pop": 0, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-10 12:00:00" + }, + { + "dt": 1612969200, + "main": { + "temp": 273.22, + "feels_like": 267.49, + "temp_min": 273.22, + "temp_max": 273.22, + "pressure": 1018, + "sea_level": 1018, + "grnd_level": 1007, + "humidity": 91, + "temp_kf": 0 + }, + "weather": [ + { + "id": 600, + "main": "Snow", + "description": "light snow", + "icon": "13d" + } + ], + "clouds": { + "all": 62 + }, + "wind": { + "speed": 5.11, + "deg": 35 + }, + "visibility": 10000, + "pop": 0.2, + "snow": { + "3h": 0.13 + }, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-10 15:00:00" + }, + { + "dt": 1612980000, + "main": { + "temp": 269.17, + "feels_like": 264.29, + "temp_min": 269.17, + "temp_max": 269.17, + "pressure": 1021, + "sea_level": 1021, + "grnd_level": 1010, + "humidity": 97, + "temp_kf": 0 + }, + "weather": [ + { + "id": 802, + "main": "Clouds", + "description": "scattered clouds", + "icon": "03n" + } + ], + "clouds": { + "all": 31 + }, + "wind": { + "speed": 3.34, + "deg": 2100 + }, + "visibility": 100000000, + "pop": 0, + "sys": { + "pod": "n" + }, + "dt_txt": "2021-02-10 18:00:00" + } + ] +} diff --git a/chomp-bench/benches/json/data/886.json b/chomp-bench/benches/json/data/886.json new file mode 100644 index 0000000..ade01fa --- /dev/null +++ b/chomp-bench/benches/json/data/886.json @@ -0,0 +1,50 @@ +{ + "cod": "200", + "message": 0, + "cnt": 40, + "list": [ + { + "dt": 1612882800, + "main": { + "temp": 273.52, + "feels_like": 266.68, + "temp_min": 273.17, + "temp_max": 273.52, + "pressure": 1009, + "sea_level": 1009, + "grnd_level": 997, + "humidity": 81, + "temp_kf": 0.35 + }, + "weather": [ + { + "id": 803, + "main": "Clouds", + "description": "broken clouds", + "icon": "04d" + } + ], + "clouds": { + "all": 67 + }, + "wind": { + "speed": 6.45, + "deg": 78 + }, + "visibility": 10000, + "pop": 0.12, + "sys": { + "pod": "d" + }, + "dt_txt": "2021-02-09 15:00:00" + }, + { + "dt": 161289360, + "main": { + "temp": 271, + "like": 264, + "min": 270 + } + } + ] +} diff --git a/chomp-bench/benches/json/main.rs b/chomp-bench/benches/json/main.rs new file mode 100644 index 0000000..8086b80 --- /dev/null +++ b/chomp-bench/benches/json/main.rs @@ -0,0 +1,56 @@ +use chewed::{IterWrapper, Parser}; +use chomp_bench::json::*; +use criterion::{ + criterion_group, criterion_main, AxisScale, BenchmarkId, Criterion, PlotConfiguration, + Throughput, +}; + +const INPUTS: &[&str] = &[ + include_str!("data/55.json"), + include_str!("data/111.json"), + include_str!("data/222.json"), + include_str!("data/443.json"), + include_str!("data/886.json"), + include_str!("data/1773.json"), + include_str!("data/3545.json"), + include_str!("data/7091.json"), + include_str!("data/14181.json"), + include_str!("data/28362.json"), +]; + +fn parse_chewed(input: &str) -> Value { + IterWrapper::new(input.chars()) + .parse::<nibble::Ast>() + .unwrap() + .into() +} + +fn parse_handwritten(input: &str) -> Value { + IterWrapper::new(input.chars()).parse().unwrap() +} + +fn parse_lalrpop(parser: &lalr::ValueParser, input: &str) -> Value { + parser.parse(input).unwrap() +} + +fn bench_parse(c: &mut Criterion) { + let lalr_parser = lalr::ValueParser::new(); + let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic); + let mut group = c.benchmark_group("JSON"); + group.plot_config(plot_config); + for (i, input) in INPUTS.iter().enumerate() { + group.throughput(Throughput::Bytes(input.len() as u64)); + group.bench_with_input(BenchmarkId::new("Chewed", i), *input, |b, i| { + b.iter(|| parse_chewed(i)) + }); + group.bench_with_input(BenchmarkId::new("Handwritten", i), *input, |b, i| { + b.iter(|| parse_handwritten(i)) + }); + group.bench_with_input(BenchmarkId::new("LALRPOP", i), *input, |b, i| { + b.iter(|| parse_lalrpop(&lalr_parser, i)) + }); + } +} + +criterion_group!(benches, bench_parse); +criterion_main!(benches); diff --git a/chomp-bench/src/arith/nibble.rs b/chomp-bench/src/arith/nibble.rs index 54d9223..9feab51 100644 --- a/chomp-bench/src/arith/nibble.rs +++ b/chomp-bench/src/arith/nibble.rs @@ -1,26 +1,32 @@ +use std::mem; + chomp_macro::nibble! { - let opt(x) = _ : None | x : Some; - let star(x) = [rec](opt(x.rec)); - let plus(x) = (x : First).(star(x) : Rest); + let opt some = _ : None | some; + let plus iter = !(/plus/ iter . (opt plus)); + let star iter = opt (plus iter); - let ws = star(" "); - let list(x, p) = (x : First).(star(p.ws.x) : Rest); + let ws = star " "; + let list inner p = !(/list/ inner . opt (p . ws . list)); - let number = plus("0" | "1" | "2"| "3" | "4" | "5" | "6" | "7" | "8" | "9"); - let term(e) = ((number : Pos | "-".ws.number : Neg | "(".ws.(e : Inner).")" : Parens) : RawTerm).ws; - let prod(e) = list(term(e), "*"|"/"); - let expr(e) = list(prod(e), "+"|"-"); - let arith = [e](expr(e)); + let digit = "0" | "1" | "2"| "3" | "4" | "5" | "6" | "7" | "8" | "9"; + let number = plus digit; + let term expr = + (( number : Pos + | "-" . ws . number : Neg + | "(" . ws . expr . ")" : Parens + ) : RawTerm) . ws; + let prod expr = list (term expr) ("*"|"/"); + let arith expr = list (prod expr) ("+"|"-"); - match [rec]((" ".rec : Base | arith) : Ast); + match !(/rec/ " ".rec | !arith); } impl From<Ast> for i64 { fn from(mut a: Ast) -> Self { loop { - match a.0 { - Ast1::Base1(b) => a = *b.rec1, - Ast1::Arith1(a) => return a.into(), + match a { + Ast::Branch1(cat) => a = *cat.rec1, + Ast::Branch2(arith) => return arith.into(), } } } @@ -28,67 +34,28 @@ impl From<Ast> for i64 { impl From<Arith1> for i64 { fn from(a: Arith1) -> Self { - a.0.into() - } -} - -impl From<Expr1> for i64 { - fn from(l: Expr1) -> Self { - let mut acc = l.prod1.into(); - let mut rest = l.rest1; - loop { - match rest.0 { - Opt5::None1(_) => return acc, - Opt5::Some1(s) => { - let v: i64 = s.x1.prod1.into(); - match s.x1.p1 { - P2::Branch1(_) => acc += v, - P2::Branch2(_) => acc -= v, - } - rest = *s.rec1; - }, + let acc = a.prod1.into(); + a.opt1.into_iter().fold(acc, |acc, (p, prod)| { + let v: i64 = prod.into(); + match p { + P2::Branch1(_) => acc + v, + P2::Branch2(_) => acc - v, } - } + }) } } impl From<Prod1> for i64 { - fn from(l: Prod1) -> Self { - let mut acc = l.term1.into(); - let mut rest = l.rest1; - loop { - match rest.0 { - Opt3::None1(_) => return acc, - Opt3::Some1(s) => { - let v: i64 = s.x1.term1.into(); - match s.x1.p1 { - P1::Branch1(_) => acc *= v, - P1::Branch2(_) => acc /= v, - } - rest = *s.rec1; - } + fn from(p: Prod1) -> Self { + let acc = p.term1.into(); + p.opt1.into_iter().fold(acc, |acc, (p, term)| { + let v: i64 = term.into(); + match p { + P1::Branch1(_) => acc * v, + P1::Branch2(_) => acc / v, } - } - } -} + }) -impl From<Prod2> for i64 { - fn from(l: Prod2) -> Self { - let mut acc = l.term1.into(); - let mut rest = l.rest1; - loop { - match rest.0 { - Opt4::None1(_) => return acc, - Opt4::Some1(s) => { - let v: i64 = s.x1.term1.into(); - match s.x1.p1 { - P1::Branch1(_) => acc *= v, - P1::Branch2(_) => acc /= v, - } - rest = *s.rec1; - } - } - } } } @@ -97,7 +64,7 @@ impl From<Term1> for i64 { match t.raw_term1 { RawTerm1::Pos1(n) => n.into(), RawTerm1::Neg1(n) => -i64::from(n.number1), - RawTerm1::Parens1(p) => (*p.e1).into(), + RawTerm1::Parens1(p) => (*p.expr1).into(), } } } @@ -107,3 +74,39 @@ impl From<Pos1> for i64 { p.to_string().parse().unwrap() } } + +impl From<Number1> for i64 { + fn from(p: Number1) -> Self { + p.to_string().parse().unwrap() + } +} + +impl Iterator for Opt5 { + type Item = (P2 , Prod1); + + fn next(&mut self) -> Option<Self::Item> { + let orig = mem::replace(self, Self::None1(Epsilon)); + match orig { + Self::None1(_) => None, + Self::Some1(some) => { + *self = some.list1.opt1; + Some((some.p1, some.list1.prod1)) + } + } + } +} + +impl Iterator for Opt4 { + type Item = (P1 , Term1); + + fn next(&mut self) -> Option<Self::Item> { + let orig = mem::replace(self, Self::None1(Epsilon)); + match orig { + Self::None1(_) => None, + Self::Some1(some) => { + *self = some.list1.opt1; + Some((some.p1, some.list1.term1)) + } + } + } +} diff --git a/chomp-bench/src/json/nibble.rs b/chomp-bench/src/json/nibble.rs index 9c0cdb7..a27ccff 100644 --- a/chomp-bench/src/json/nibble.rs +++ b/chomp-bench/src/json/nibble.rs @@ -1,25 +1,30 @@ use super::{decode_pair, Value}; -use std::{collections::HashMap, convert::TryInto, ops::RangeInclusive}; +use std::{collections::HashMap, convert::TryInto, mem, ops::RangeInclusive}; use chomp_macro::nibble; // Note: this is only an ASCII subset. Need to add character sets. nibble! { - let opt(x) = _ : None | x : Some; - let plus(x) = [rec](x . opt(rec)); - let star(x) = [rec](opt(x . rec)); - let sep(x, p) = [rec](x . opt(p . rec)); + let opt some = _ : None | some; + let plus iter = !(/rec/ iter . opt rec); + let star iter = !(/rec/ opt (iter . rec)); let ws_char = " " | "\t" | "\n" | "\r"; - let ws = star(ws_char); + let ws = star ws_char; + + let sep iter = !(/rec/ iter . opt ("," . ws . rec)); + let digit_1_9 = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; - let digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; + let digit = "0" | digit_1_9; - let unsigned_number = (("0" | digit_1_9 . star(digit)) : Int) - . (opt("." . plus(digit)) : Frac) - . (opt(("e" | "E") . opt("+" | "-") . plus(digit)) : Exp); - let number = unsigned_number : Positive | "-" . unsigned_number : Negative; + let unsigned_number = + (("0" | digit_1_9 . star digit) : Int) + . (opt ("." . plus digit) : Frac) + . (opt (("e" | "E") . opt ("+" | "-") . plus digit) : Exp); + let number = + unsigned_number : Positive + | "-" . unsigned_number : Negative; let hex = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | @@ -37,38 +42,39 @@ nibble! { "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | - "x" | "y" | "z" | "{" | "|" | "}" | "~") : Literal | - "\\" . ( - ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") : Ascii | - "u" . hex . hex . hex . hex : Unicode - ) : Escape; - - let string = "\"" . star(char) . "\""; - - let member(value) = (string : Key) . ws . ":" . ws . (value : Value) . ws; - let object(value) = "{" . ws . opt(sep(member(value), "," . ws)) . "}"; - - let array(value) = "[" . ws . opt(sep(value . ws, "," . ws)) . "]"; - - let value = [value]( - "true" : True | - "false" : False | - "null" : Null | - number : Number | - string : String | - object(value) : Object | - array(value) : Array + "x" | "y" | "z" | "{" | "|" | "}" | "~" + ) : Literal | + "\\" . ( + ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") : Ascii | + "u" . hex . hex . hex . hex : Unicode + ) : Escape; + + let string = "\"" . star char . "\""; + + let member value = (string : Key) . ws . ":" . ws . value . ws; + let object value = "{" . ws . opt (sep (member value)) . "}"; + + let array value = "[" . ws . opt (sep (value . ws)) . "]"; + + let value = !(/value/ + "true" : True + | "false" : False + | "null" : Null + | number : Number + | string : String + | object value : Object + | array value : Array ); - match [rec](ws_char . rec | value . ws); + match !(/rec/ ws_char . rec | value . ws); } impl From<Ast> for Value { fn from(mut ast: Ast) -> Self { loop { - match ast.0 { - Alt184::Branch1(cat) => ast = *cat.rec1, - Alt184::Branch2(cat) => return cat.value1.into(), + match ast { + Ast::Branch1(cat) => ast = *cat.rec1, + Ast::Branch2(cat) => return cat.value1.into(), } } } @@ -76,14 +82,14 @@ impl From<Ast> for Value { impl From<Value1> for Value { fn from(value: Value1) -> Self { - match value.0 { - Alt182::Null1(_) => Self::Null, - Alt182::True1(_) => Self::Bool(true), - Alt182::False1(_) => Self::Bool(false), - Alt182::Number1(n) => Self::Number(n.into()), - Alt182::String1(s) => Self::String(s.into()), - Alt182::Object1(o) => Self::Object(o.into()), - Alt182::Array1(a) => Self::Array(a.into()), + match value { + Value1::Null1(_) => Self::Null, + Value1::True1(_) => Self::Bool(true), + Value1::False1(_) => Self::Bool(false), + Value1::Number1(n) => Self::Number(n.into()), + Value1::String1(s) => Self::String(s.into()), + Value1::Object1(o) => Self::Object(o.into()), + Value1::Array1(a) => Self::Array(a.into()), } } } @@ -100,16 +106,16 @@ impl From<String1> for String { } } -impl Iterator for Star2 { +impl Iterator for Opt5 { type Item = char; fn next(&mut self) -> Option<Self::Item> { - fn next(star: &mut Star2) -> Option<Char1> { - match std::mem::replace(star, Star2(Opt5::None1(Epsilon))).0 { + fn next(star: &mut Opt5) -> Option<Char1> { + match std::mem::replace(star, Opt5::None1(Epsilon)) { Opt5::None1(_) => None, - Opt5::Some1(s) => { - *star = *s.rec1; - Some(s.char1) + Opt5::Some1(some) => { + *star = *some.rec1; + Some(some.char1) } } } @@ -161,73 +167,102 @@ impl Iterator for Star2 { impl From<Object1> for HashMap<String, Value> { fn from(object: Object1) -> Self { - match object.opt1 { - Opt8::None1(_) => HashMap::new(), - Opt8::Sep1(s) => s - .into_iter() - .map(|m| (m.key1.into(), (*m.value1).into())) - .collect(), - } + object + .opt1 + .into_iter() + .map(|m| (m.key1.into(), (*m.value1).into())) + .collect() } } -impl IntoIterator for Sep1 { +impl IntoIterator for Opt8 { type Item = Member1; - type IntoIter = Sep1Iter; + type IntoIter = Opt7; fn into_iter(self) -> Self::IntoIter { - Sep1Iter(Some(self)) + match self { + Self::None1(_) => Opt7::None1(Epsilon), + Self::Sep1(sep) => Opt7::Some1(Some8 { + part1: Lit75, + ws1: Ws1::None1(Epsilon), + rec1: Box::new(sep), + }), + } } } -pub struct Sep1Iter(Option<Sep1>); - -impl Iterator for Sep1Iter { +impl Iterator for Opt7 { type Item = Member1; fn next(&mut self) -> Option<Self::Item> { - let inner = self.0.take()?.0; - let res = inner.member1; - self.0 = match inner.opt1 { + let orig = mem::replace(self, Self::None1(Epsilon)); + match orig { Opt7::None1(_) => None, - Opt7::Some1(s) => Some(*s.rec1), - }; - Some(res) + Opt7::Some1(some) => { + *self = some.rec1.opt1; + Some(some.rec1.member1) + } + } } } impl From<Array1> for Vec<Value> { fn from(array: Array1) -> Self { - match array.opt1 { - Opt10::None1(_) => Vec::new(), - Opt10::Sep1(s) => s.into_iter().map(|x| (*x.value1).into()).collect(), - } + array.opt1.into_iter().map(Value::from).collect() } } -impl IntoIterator for Sep2 { - type Item = X1; +impl IntoIterator for Opt10 { + type Item = Value1; - type IntoIter = Sep2Iter; + type IntoIter = Opt9; fn into_iter(self) -> Self::IntoIter { - Sep2Iter(Some(self)) + match self { + Self::None1(_) => Opt9::None1(Epsilon), + Self::Sep1(sep) => Opt9::Some1(Some9 { part1: Lit75, ws1: Ws1::None1(Epsilon), rec1: Box::new(sep)}) + } } } -pub struct Sep2Iter(Option<Sep2>); - -impl Iterator for Sep2Iter { - type Item = X1; +impl Iterator for Opt9 { + type Item = Value1; fn next(&mut self) -> Option<Self::Item> { - let inner = self.0.take()?.0; - let res = inner.x1; - self.0 = match inner.opt1 { + let orig = mem::replace(self, Self::None1(Epsilon)); + match orig { Opt9::None1(_) => None, - Opt9::Some1(s) => Some(*s.rec1), - }; - Some(res) + Opt9::Some1(some) => { + *self = some.rec1.opt1; + Some(*some.rec1.iter1.value1) + } + } } } + +// impl IntoIterator for Sep2 { +// type Item = X1; + +// type IntoIter = Sep2Iter; + +// fn into_iter(self) -> Self::IntoIter { +// Sep2Iter(Some(self)) +// } +// } + +// pub struct Sep2Iter(Option<Sep2>); + +// impl Iterator for Sep2Iter { +// type Item = X1; + +// fn next(&mut self) -> Option<Self::Item> { +// let inner = self.0.take()?.0; +// let res = inner.x1; +// self.0 = match inner.opt1 { +// Opt9::None1(_) => None, +// Opt9::Some1(s) => Some(*s.rec1), +// }; +// Some(res) +// } +// } diff --git a/chomp-macro/src/lib.rs b/chomp-macro/src/lib.rs index 67964ec..a8e4782 100644 --- a/chomp-macro/src/lib.rs +++ b/chomp-macro/src/lib.rs @@ -1,6 +1,6 @@ use chomp::{ chomp::{ - ast::substitute::InlineCalls, + ast::substitute::Reduce, typed::{ context::Context, lower::{Backend, GenerateCode}, @@ -9,20 +9,21 @@ use chomp::{ visit::Visitable, }, lower::RustBackend, - nibble::File, + nibble::{convert::{self, Convert}, Statement}, }; -use proc_macro::TokenStream; +use proc_macro::{Span, TokenStream}; use syn::Error; #[proc_macro] pub fn nibble(item: TokenStream) -> TokenStream { syn::parse(item) - .and_then(|nibble: File| nibble.convert().map_err(Error::from)) - .and_then(|(funs, goal)| { - funs.into_iter() - .try_rfold(goal, |goal, function| { - goal.fold(&mut InlineCalls { function }) - }) + .and_then(|nibble: Statement| { + nibble + .convert(&mut convert::Context::default()) + .map_err(Error::from) + }) + .and_then(|expr| { + expr.fold(&mut Reduce) .map_err(Error::from) }) .and_then(|expr| { @@ -35,7 +36,7 @@ pub fn nibble(item: TokenStream) -> TokenStream { .map(|typed| { let mut backend = RustBackend::default(); let id = typed.gen(&mut backend); - backend.emit_code(None, None, id) + backend.emit_code(None, Span::call_site().into(), id) }) .unwrap_or_else(Error::into_compile_error) .into() diff --git a/chomp-macro/tests/nibble_exp.rs b/chomp-macro/tests/nibble_exp.rs deleted file mode 100644 index 7e31e6a..0000000 --- a/chomp-macro/tests/nibble_exp.rs +++ /dev/null @@ -1,81 +0,0 @@ -chomp_macro::nibble! { - let opt(x) = _ | x; - let plus(x) = [plus](x . opt(plus)); - let star(x) = [star](opt(x . star)); - - let Pattern_Whitespace = "\n"|" "; - - let XID_Start = - "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | - "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | - "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | - "y" | "z" | - "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | - "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | - "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | - "Y" | "Z" ; - let XID_Continue = - XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; - - let literal_char = XID_Continue; - - let ws = star(Pattern_Whitespace); - let must_ws = plus(Pattern_Whitespace); - - let punctuated(x, p) = [rec](x . opt(p . ws . rec)); - let list(x) = "(" . ws . [rec](x . opt("," . ws . opt(rec))) . ")"; - - let epsilon = "_"; - let ident = XID_Start . star(XID_Continue); - let literal = "\"" . plus(literal_char) . "\""; - let parens(expr) = "(" . ws . expr . ")"; - let fix(expr) = "[" . ws . ident . ws . "]" . ws . parens(expr); - - let term(expr) = - epsilon . ws - | literal . ws - | parens(expr) . ws - | fix(expr) . ws - | ident . ws . opt(list(expr) . ws) - ; - - let cat(expr) = punctuated(term(expr), "."); - let alt(expr) = punctuated(cat(expr), "|"); - let expr = [expr](alt(expr)); - match expr; -} - -#[test] -fn exp_epsilon() { - Ast::parse_str("_").unwrap(); -} - -#[test] -fn exp_literal() { - Ast::parse_str(r#""foo""#).unwrap(); -} - -#[test] -fn exp_cat() { - Ast::parse_str(r#""a" . "b""#).unwrap(); -} - -#[test] -fn exp_alt() { - Ast::parse_str(r#""a" | "b""#).unwrap(); -} - -#[test] -fn exp_ident() { - Ast::parse_str("foo").unwrap(); -} - -#[test] -fn exp_call() { - Ast::parse_str(r#"opt("foo")"#).unwrap(); -} - -#[test] -fn exp_fix() { - Ast::parse_str(r#"[rec](_ | "a" . rec)"#).unwrap(); -} diff --git a/chomp-macro/tests/ratata.rs b/chomp-macro/tests/ratata.rs deleted file mode 100644 index 869ad61..0000000 --- a/chomp-macro/tests/ratata.rs +++ /dev/null @@ -1,15 +0,0 @@ -chomp_macro::nibble! { - let opt(x) = _ | x; - let plus(x) = [rec](x . opt(rec)); - match plus(("r" | "t") . "a"); -} - -#[test] -fn ratata_ratata() { - Ast::parse_str("ratata").unwrap(); -} - -#[test] -fn ratata_ratarataratatata() { - Ast::parse_str("ratarataratatata").unwrap(); -} diff --git a/chomp-macro/tests/regex.rs b/chomp-macro/tests/regex.rs deleted file mode 100644 index 1e831b4..0000000 --- a/chomp-macro/tests/regex.rs +++ /dev/null @@ -1,27 +0,0 @@ -chomp_macro::nibble! { - let opt(x) = _ | x; - let plus(x) = [plus](x . opt(plus)); - let star(x) = [star](opt(x . star)); - - match plus("a") . star("b"); -} - -#[test] -fn regex_a() { - Ast::parse_str("a").unwrap(); -} - -#[test] -fn regex_ab() { - Ast::parse_str("ab").unwrap(); -} - -#[test] -fn regex_aa() { - Ast::parse_str("aa").unwrap(); -} - -#[test] -fn regex_aaaabbb() { - Ast::parse_str("aaaabbb").unwrap(); -} diff --git a/chomp-macro/tests/regex_fix.rs b/chomp-macro/tests/regex_fix.rs deleted file mode 100644 index 9842484..0000000 --- a/chomp-macro/tests/regex_fix.rs +++ /dev/null @@ -1,11 +0,0 @@ -chomp_macro::nibble! { - let opt(x) = _ | x; - let ws = [star](opt(" " . star)); - - match [rec]("a" . opt("." . ws . rec)); -} - -#[test] -fn regex_fix_cat() { - Ast::parse_str(r#"a. a"#).unwrap(); -} diff --git a/chomp-macro/tests/sheep.rs b/chomp-macro/tests/sheep.rs deleted file mode 100644 index 862e810..0000000 --- a/chomp-macro/tests/sheep.rs +++ /dev/null @@ -1,15 +0,0 @@ -chomp_macro::nibble! { - let opt(x) = _ | x; - let plus(x) = [rec](x . opt(rec)); - match "ba" . plus("a"); -} - -#[test] -fn baa() { - Ast::parse_str("baa").unwrap(); -} - -#[test] -fn baaaaaaaaaaaaaaa() { - Ast::parse_str("baaaaaaaaaaaaaaa").unwrap(); -} diff --git a/src/chomp/ast/error.rs b/src/chomp/ast/error.rs index 9057ec3..ea145a7 100644 --- a/src/chomp/ast/error.rs +++ b/src/chomp/ast/error.rs @@ -6,31 +6,31 @@ use std::{ }; #[derive(Debug)] -pub enum TranslateError { +pub enum ReductionError { CallNotAFunction { on: Expression, - span: Option<Span>, + span: Span, }, WrongArgCount { lambda: Lambda, args: Vec<NamedExpression>, - span: Option<Span>, + span: Span, }, } -impl From<TranslateError> for syn::Error { - fn from(e: TranslateError) -> Self { +impl From<ReductionError> for syn::Error { + fn from(e: ReductionError) -> Self { let msg = e.to_string(); let span = match e { - TranslateError::CallNotAFunction { span, .. } - | TranslateError::WrongArgCount { span, .. } => span, + ReductionError::CallNotAFunction { span, .. } + | ReductionError::WrongArgCount { span, .. } => span, }; - Self::new(span.unwrap_or_else(Span::call_site), msg) + Self::new(span, msg) } } -impl Display for TranslateError { +impl Display for ReductionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::CallNotAFunction { .. } => { @@ -38,7 +38,7 @@ impl Display for TranslateError { } Self::WrongArgCount { lambda, args, .. } => match (lambda.args.len(), args.len()) { (1, n) => write!(f, "this function takes 1 argument but {} were supplied", n), - (m, _) => write!(f, "this function takes {} arguments but 1 was supplied", m), + (m, 1) => write!(f, "this function takes {} arguments but 1 was supplied", m), (m, n) => write!( f, "this function takes {} arguments but {} were supplied", @@ -49,4 +49,4 @@ impl Display for TranslateError { } } -impl Error for TranslateError {} +impl Error for ReductionError {} diff --git a/src/chomp/ast/mod.rs b/src/chomp/ast/mod.rs index 232381a..7b3ea16 100644 --- a/src/chomp/ast/mod.rs +++ b/src/chomp/ast/mod.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Display}; use proc_macro2::Span; -use super::Name; +use super::name::Name; pub mod error; pub mod substitute; @@ -15,7 +15,7 @@ pub type Literal = String; #[derive(Clone, Debug)] pub struct Cat { pub first: Box<NamedExpression>, - pub rest: Vec<(Option<Span>, NamedExpression)>, + pub rest: Vec<(Span, NamedExpression)>, } impl Display for Cat { @@ -45,7 +45,7 @@ impl Eq for Cat {} #[derive(Clone, Debug)] pub struct Alt { pub first: Box<NamedExpression>, - pub rest: Vec<(Option<Span>, NamedExpression)> + pub rest: Vec<(Span, NamedExpression)> } impl Display for Alt { @@ -105,7 +105,7 @@ impl Display for Call { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "({}", self.on)?; - for arg in self.args { + for arg in &self.args { write!(f, " {}", arg)?; } @@ -135,7 +135,21 @@ impl Display for Lambda { } } -#[derive(Clone, Debug)] +/// A let statement. +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct Let { + pub name: Name, + pub bound: Box<NamedExpression>, + pub body: Box<NamedExpression>, +} + +impl Display for Let { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "let {} = {}; {}", self.name, self.bound, self.body) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] pub enum Expression { /// Matches the empty string. Epsilon(Epsilon), @@ -153,6 +167,8 @@ pub enum Expression { Call(Call), /// A function abstraction. Lambda(Lambda), + /// A let statement + Let(Let), } impl Expression { @@ -176,69 +192,11 @@ impl Display for Expression { Self::Variable(v) => v.fmt(f), Self::Lambda(p) => p.fmt(f), Self::Call(c) => c.fmt(f), + Self::Let(l) => l.fmt(f), } } } -impl PartialEq for Expression { - fn eq(&self, other: &Self) -> bool { - match self { - Self::Epsilon(_) => matches!(other, Self::Epsilon(_)), - Self::Literal(l) => { - if let Self::Literal(them) = other { - l == them - } else { - false - } - } - Self::Cat(c) => { - if let Self::Cat(them) = other { - c == them - } else { - false - } - } - Self::Alt(a) => { - if let Self::Alt(them) = other { - a == them - } else { - false - } - } - Self::Fix(f) => { - if let Self::Fix(them) = other { - f == them - } else { - false - } - } - Self::Variable(v) => { - if let Self::Variable(them) = other { - v == them - } else { - false - } - } - Self::Lambda(p) => { - if let Self::Lambda(them) = other { - p == them - } else { - false - } - } - Self::Call(c) => { - if let Self::Call(them) = other { - c == them - } else { - false - } - } - } - } -} - -impl Eq for Expression {} - impl From<Epsilon> for Expression { fn from(eps: Epsilon) -> Self { Self::Epsilon(eps) @@ -287,17 +245,29 @@ impl From<Call> for Expression { } } +impl From<Let> for Expression { + fn from(stmt: Let) -> Self { + Self::Let(stmt) + } +} + #[derive(Clone, Debug)] pub struct NamedExpression { pub name: Option<Name>, + pub span: Span, pub expr: Expression, - pub span: Option<Span>, } impl Display for NamedExpression { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.name { - Some(name) => write!(f, "({} : {})", self.expr, name), + Some(name) => { + if let Expression::Variable(_) = self.expr { + write!(f, "{}", name) + } else { + write!(f, "({} : {})", self.expr, name) + } + }, None => self.expr.fmt(f), } } @@ -310,16 +280,3 @@ impl PartialEq for NamedExpression { } impl Eq for NamedExpression {} - -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct Let { - pub name: Name, - pub val: NamedExpression, - pub inner: Box<TopLevel>, -} - -#[derive(Clone, Debug, Eq, PartialEq)] -pub enum TopLevel { - Let(Let), - Goal(NamedExpression), -} diff --git a/src/chomp/ast/substitute.rs b/src/chomp/ast/substitute.rs index 80df588..c6d3ef6 100644 --- a/src/chomp/ast/substitute.rs +++ b/src/chomp/ast/substitute.rs @@ -1,24 +1,32 @@ +use std::array; + use super::{ - error::TranslateError, Alt, Call, Cat, Epsilon, Fix, Lambda, Literal, NamedExpression, Variable, + error::ReductionError, Alt, Call, Cat, Epsilon, Expression, Fix, Lambda, Let, Literal, + NamedExpression, Variable, }; use crate::chomp::{ + name::Name, visit::{Folder, Mapper, Visitable}, - Name, }; use proc_macro2::Span; -struct Deepen { - pub depth: usize, - pub by: usize, +enum Direction { + Deepen, + Shallow, +} +struct RenameVars { + depth: usize, + by: usize, + direction: Direction, } -impl Mapper for Deepen { +impl Mapper for RenameVars { type Out = (); fn map_epsilon( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, _eps: &mut Epsilon, ) -> Self::Out { } @@ -26,7 +34,7 @@ impl Mapper for Deepen { fn map_literal( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, _lit: &mut Literal, ) -> Self::Out { } @@ -34,7 +42,7 @@ impl Mapper for Deepen { fn map_cat( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, cat: &mut Cat, ) -> Self::Out { cat.first.map(self); @@ -46,7 +54,7 @@ impl Mapper for Deepen { fn map_alt( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, alt: &mut Alt, ) -> Self::Out { alt.first.map(self); @@ -58,7 +66,7 @@ impl Mapper for Deepen { fn map_fix( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, fix: &mut Fix, ) -> Self::Out { fix.inner.map(self); @@ -67,18 +75,21 @@ impl Mapper for Deepen { fn map_variable( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, var: &mut Variable, ) -> Self::Out { if var.index >= self.depth { - var.index += self.by; + match self.direction { + Direction::Deepen => var.index += self.by, + Direction::Shallow => var.index -= self.by, + } } } fn map_call( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, call: &mut Call, ) -> Self::Out { call.on.map(self); @@ -90,24 +101,56 @@ impl Mapper for Deepen { fn map_lambda( &mut self, _name: &mut Option<Name>, - _span: Option<Span>, + _span: Span, lambda: &mut Lambda, ) -> Self::Out { self.depth += lambda.args.len(); lambda.inner.map(self); self.depth -= lambda.args.len(); } + + fn map_let( + &mut self, + _name: &mut Option<Name>, + _span: Span, + stmt: &mut Let, + ) -> Self::Out { + stmt.bound.map(self); + self.depth += 1; + stmt.body.map(self); + self.depth -= 1; + } } +#[derive(Debug)] pub struct Substitute { pub index: usize, pub expr: NamedExpression, } +impl Substitute { + fn with_args<V: Visitable>(&mut self, args: usize, visitable: V) -> <Self as Folder>::Out { + self.index += args; + self.expr.map(&mut RenameVars { + depth: 0, + by: args, + direction: Direction::Deepen, + }); + let out = visitable.fold(self); + self.expr.map(&mut RenameVars { + depth: 0, + by: args, + direction: Direction::Shallow, + }); + self.index -= args; + out + } +} + impl Folder for Substitute { type Out = NamedExpression; - fn fold_epsilon(&mut self, name: Option<Name>, span: Option<Span>, eps: Epsilon) -> Self::Out { + fn fold_epsilon(&mut self, name: Option<Name>, span: Span, eps: Epsilon) -> Self::Out { NamedExpression { name, expr: eps.into(), @@ -115,7 +158,7 @@ impl Folder for Substitute { } } - fn fold_literal(&mut self, name: Option<Name>, span: Option<Span>, lit: Literal) -> Self::Out { + fn fold_literal(&mut self, name: Option<Name>, span: Span, lit: Literal) -> Self::Out { NamedExpression { name, expr: lit.into(), @@ -123,7 +166,7 @@ impl Folder for Substitute { } } - fn fold_cat(&mut self, name: Option<Name>, span: Option<Span>, mut cat: Cat) -> Self::Out { + fn fold_cat(&mut self, name: Option<Name>, span: Span, mut cat: Cat) -> Self::Out { cat.first = Box::new(cat.first.fold(self)); cat.rest = cat .rest @@ -137,7 +180,7 @@ impl Folder for Substitute { } } - fn fold_alt(&mut self, name: Option<Name>, span: Option<Span>, mut alt: Alt) -> Self::Out { + fn fold_alt(&mut self, name: Option<Name>, span: Span, mut alt: Alt) -> Self::Out { alt.first = Box::new(alt.first.fold(self)); alt.rest = alt .rest @@ -151,7 +194,7 @@ impl Folder for Substitute { } } - fn fold_fix(&mut self, name: Option<Name>, span: Option<Span>, mut fix: Fix) -> Self::Out { + fn fold_fix(&mut self, name: Option<Name>, span: Span, mut fix: Fix) -> Self::Out { fix.inner = Box::new(fix.inner.fold(self)); NamedExpression { name, @@ -163,11 +206,13 @@ impl Folder for Substitute { fn fold_variable( &mut self, name: Option<Name>, - span: Option<Span>, + span: Span, var: Variable, ) -> Self::Out { if var.index == self.index { - self.expr.clone() + let mut out = self.expr.clone(); + out.name = Name::merge(out.name, name); + out } else { NamedExpression { name, @@ -184,7 +229,7 @@ impl Folder for Substitute { } } - fn fold_call(&mut self, name: Option<Name>, span: Option<Span>, mut call: Call) -> Self::Out { + fn fold_call(&mut self, name: Option<Name>, span: Span, mut call: Call) -> Self::Out { call.on = Box::new(call.on.fold(self)); call.args = call.args.into_iter().map(|e| e.fold(self)).collect(); NamedExpression { @@ -197,40 +242,36 @@ impl Folder for Substitute { fn fold_lambda( &mut self, name: Option<Name>, - span: Option<Span>, + span: Span, mut lambda: Lambda, ) -> Self::Out { - self.index += lambda.args.len(); - lambda.inner = Box::new(lambda.inner.fold(self)); - self.index -= lambda.args.len(); + let depth = lambda.args.len(); + lambda.inner = Box::new(self.with_args(depth, lambda.inner)); NamedExpression { name, expr: lambda.into(), span, } } -} -pub struct Translate { - changed: bool, -} - -impl Translate { - pub fn new() -> Self { - Self { changed: false } + fn fold_let(&mut self, name: Option<Name>, span: Span, mut stmt: Let) -> Self::Out { + stmt.bound = Box::new(stmt.bound.fold(self)); + stmt.body = Box::new(self.with_args(1, stmt.body)); + NamedExpression { + name, + expr: stmt.into(), + span, + } } } -impl Default for Translate { - fn default() -> Self { - Self::new() - } -} +#[derive(Copy, Clone, Debug)] +pub struct Reduce; -impl Folder for Translate { - type Out = Result<NamedExpression, TranslateError>; +impl Folder for Reduce { + type Out = Result<NamedExpression, ReductionError>; - fn fold_epsilon(&mut self, name: Option<Name>, span: Option<Span>, eps: Epsilon) -> Self::Out { + fn fold_epsilon(&mut self, name: Option<Name>, span: Span, eps: Epsilon) -> Self::Out { Ok(NamedExpression { name, expr: eps.into(), @@ -238,7 +279,7 @@ impl Folder for Translate { }) } - fn fold_literal(&mut self, name: Option<Name>, span: Option<Span>, lit: Literal) -> Self::Out { + fn fold_literal(&mut self, name: Option<Name>, span: Span, lit: Literal) -> Self::Out { Ok(NamedExpression { name, expr: lit.into(), @@ -246,7 +287,13 @@ impl Folder for Translate { }) } - fn fold_cat(&mut self, name: Option<Name>, span: Option<Span>, cat: Cat) -> Self::Out { + fn fold_cat(&mut self, name: Option<Name>, span: Span, mut cat: Cat) -> Self::Out { + cat.first = Box::new(cat.first.fold(self)?); + cat.rest = cat + .rest + .into_iter() + .map(|(p, e)| Ok((p, e.fold(self)?))) + .collect::<Result<_, _>>()?; Ok(NamedExpression { name, expr: cat.into(), @@ -254,7 +301,13 @@ impl Folder for Translate { }) } - fn fold_alt(&mut self, name: Option<Name>, span: Option<Span>, alt: Alt) -> Self::Out { + fn fold_alt(&mut self, name: Option<Name>, span: Span, mut alt: Alt) -> Self::Out { + alt.first = Box::new(alt.first.fold(self)?); + alt.rest = alt + .rest + .into_iter() + .map(|(p, e)| Ok((p, e.fold(self)?))) + .collect::<Result<_, _>>()?; Ok(NamedExpression { name, expr: alt.into(), @@ -262,7 +315,13 @@ impl Folder for Translate { }) } - fn fold_fix(&mut self, name: Option<Name>, span: Option<Span>, fix: Fix) -> Self::Out { + fn fold_fix(&mut self, name: Option<Name>, span: Span, mut fix: Fix) -> Self::Out { + let mut inner = fix.inner.fold(self)?; + if let Expression::Lambda(mut l) = inner.expr { + l.inner = Box::new(l.inner.fold(self)?); + inner.expr = Expression::Lambda(l); + } + fix.inner = Box::new(inner); Ok(NamedExpression { name, expr: fix.into(), @@ -273,7 +332,7 @@ impl Folder for Translate { fn fold_variable( &mut self, name: Option<Name>, - span: Option<Span>, + span: Span, var: Variable, ) -> Self::Out { Ok(NamedExpression { @@ -283,21 +342,16 @@ impl Folder for Translate { }) } - fn fold_call(&mut self, name: Option<Name>, span: Option<Span>, call: Call) -> Self::Out { - let mut on = *call.on; - self.changed = true; - while self.changed { - self.changed = false; - on = on.fold(self)?; - } + fn fold_call(&mut self, name: Option<Name>, span: Span, call: Call) -> Self::Out { + let on = call.on.fold(self)?; let lambda = on .expr .try_into_lambda() - .map_err(|on| TranslateError::CallNotAFunction { on, span })?; + .map_err(|on| ReductionError::CallNotAFunction { on, span })?; if lambda.args.len() != call.args.len() { - return Err(TranslateError::WrongArgCount { + return Err(ReductionError::WrongArgCount { lambda, args: call.args, span, @@ -307,33 +361,44 @@ impl Folder for Translate { let mut out = *lambda.inner; for ((i, mut arg), name) in call.args.into_iter().enumerate().zip(lambda.args).rev() { - arg.name = arg.name.or(Some(name)); - arg.map(&mut Deepen { depth: 0, by: i }); + arg.name = Name::merge(arg.name, Some(name)); + arg.map(&mut RenameVars { + depth: 0, + by: i, + direction: Direction::Deepen, + }); out = out.fold(&mut Substitute { index: 0, expr: arg, }); } - self.changed = true; - while self.changed { - self.changed = false; - out = out.fold(self)?; - } - - self.changed = true; - out.name = name.or(out.name); - out.span = span.or(out.span); + out = out.fold(self)?; + out.name = Name::merge_all(array::IntoIter::new([name, on.name, out.name])); + out.span = span; Ok(out) } - fn fold_lambda(&mut self, name: Option<Name>, span: Option<Span>, lambda: Lambda) -> Self::Out { + fn fold_lambda(&mut self, name: Option<Name>, span: Span, lambda: Lambda) -> Self::Out { Ok(NamedExpression { name, expr: lambda.into(), span, }) } + + fn fold_let(&mut self, name: Option<Name>, span: Span, stmt: Let) -> Self::Out { + let mut out = stmt + .body + .fold(&mut Substitute { + index: 0, + expr: *stmt.bound, + }) + .fold(self)?; + out.name = Name::merge(out.name, name); + out.span = span; + Ok(out) + } } #[cfg(test)] @@ -345,23 +410,23 @@ mod tests { let var = NamedExpression { name: None, expr: Variable { index: 0 }.into(), - span: None, + span: Span::call_site(), }; let lambda = NamedExpression { name: None, expr: Lambda { - args: vec!["x".to_owned().into()], + args: vec![Name::new_variable("x".to_owned())], inner: Box::new(var), } .into(), - span: None, + span: Span::call_site(), }; let var = NamedExpression { name: None, expr: Variable { index }.into(), - span: None, + span: Span::call_site(), }; NamedExpression { @@ -371,14 +436,18 @@ mod tests { args: vec![var], } .into(), - span: None, + span: Span::call_site(), } } #[test] fn deepen_lambda() { let mut expr = make_expr(0); - expr.map(&mut Deepen { depth: 0, by: 1 }); + expr.map(&mut RenameVars { + depth: 0, + by: 1, + direction: Direction::Deepen, + }); assert_eq!(expr, make_expr(1)) } @@ -390,22 +459,22 @@ mod tests { expr: NamedExpression { name: None, expr: Epsilon.into(), - span: None, + span: Span::call_site(), }, }); assert_eq!(expr, make_expr(0)) } #[test] - fn translate_lambda() { + fn reduce_lambda() { let expr = make_expr(1); - let expr = expr.fold(&mut Translate::new()).unwrap(); + let expr = expr.fold(&mut Reduce).unwrap(); assert_eq!( expr, NamedExpression { - name: Some("x".to_owned().into()), + name: Some(Name::new_variable("x".to_owned())), expr: Variable { index: 1 }.into(), - span: None + span: Span::call_site(), } ) } diff --git a/src/chomp/mod.rs b/src/chomp/mod.rs index 79b4fac..029c10f 100644 --- a/src/chomp/mod.rs +++ b/src/chomp/mod.rs @@ -1,114 +1,7 @@ -use std::{fmt, hash}; - -use heck::{CamelCase, SnakeCase}; -use proc_macro2::{Ident, Span}; -use syn::ext::IdentExt; +use proc_macro2::Span; pub mod ast; +pub mod name; pub mod set; pub mod typed; pub mod visit; - -#[derive(Clone, Debug)] -pub enum Name { - Spanned(Ident), - Spanless(String), -} - -impl Name { - pub fn span(&self) -> Option<Span> { - match self { - Self::Spanned(i) => Some(i.span()), - Self::Spanless(_) => None, - } - } - - pub fn into_ident(self, span: Span) -> Ident { - match self { - Self::Spanned(i) => i, - Self::Spanless(s) => Ident::new(&s, span), - } - } -} - -impl CamelCase for Name { - fn to_camel_case(&self) -> Self::Owned { - match self { - Self::Spanned(ident) => { - let span = ident.span(); - let name = ident.unraw().to_string(); - Ident::new(&name.to_camel_case(), span).into() - } - Name::Spanless(name) => { - name.to_camel_case().into() - } - } - } -} - -impl SnakeCase for Name { - fn to_snake_case(&self) -> Self::Owned { - match self { - Self::Spanned(ident) => { - let span = ident.span(); - let name = ident.unraw().to_string(); - Ident::new(&name.to_snake_case(), span).into() - } - Name::Spanless(name) => { - name.to_snake_case().into() - } - } - } -} - -impl PartialEq for Name { - fn eq(&self, other: &Self) -> bool { - match (self, other) { - (Self::Spanned(me), Self::Spanned(them)) => me == them, - (Self::Spanned(me), Self::Spanless(them)) => me.unraw() == them, - (Self::Spanless(me), Self::Spanned(them)) => them.unraw() == me, - (Self::Spanless(me), Self::Spanless(them)) => me == them, - } - } -} - -impl<T: AsRef<str>> PartialEq<T> for Name { - fn eq(&self, other: &T) -> bool { - match self { - Name::Spanned(me) => me.unraw() == other, - Name::Spanless(me) => me == other.as_ref(), - } - } -} - -impl Eq for Name {} - -impl hash::Hash for Name { - fn hash<H: hash::Hasher>(&self, state: &mut H) { - match self { - Self::Spanned(i) => i.unraw().to_string().hash(state), - Self::Spanless(s) => s.hash(state), - } - } -} - -impl fmt::Display for Name { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Name::Spanned(i) => i.fmt(f), - Name::Spanless(s) => s.fmt(f), - } - } -} - -impl From<Ident> for Name { - fn from(ident: Ident) -> Self { - Self::Spanned(ident) - } -} - -impl From<String> for Name { - fn from(string: String) -> Self { - Self::Spanless(string) - } -} diff --git a/src/chomp/name.rs b/src/chomp/name.rs new file mode 100644 index 0000000..450b6e9 --- /dev/null +++ b/src/chomp/name.rs @@ -0,0 +1,217 @@ +use std::{ + array::IntoIter, + cmp::{self, Ordering}, + fmt, hash, +}; + +use heck::{CamelCase, SnakeCase}; +use proc_macro2::{Ident, Span}; +use syn::{ext::IdentExt, spanned::Spanned}; + +#[derive(Clone, Debug)] +pub enum Content { + Spanned(Ident), + Spanless(String), +} + +impl Spanned for Content { + fn span(&self) -> Span { + match self { + Content::Spanned(i) => i.span(), + Content::Spanless(_) => Span::call_site(), + } + } +} + +impl From<Content> for Ident { + fn from(content: Content) -> Self { + match content { + Content::Spanned(i) => i, + Content::Spanless(s) => Ident::new(&s, Span::call_site()), + } + } +} + +impl CamelCase for Content { + fn to_camel_case(&self) -> Self::Owned { + match self { + Self::Spanned(ident) => { + let span = ident.span(); + let name = ident.unraw().to_string(); + Ident::new(&name.to_camel_case(), span).into() + } + Self::Spanless(name) => name.to_camel_case().into(), + } + } +} + +impl SnakeCase for Content { + fn to_snake_case(&self) -> Self::Owned { + match self { + Self::Spanned(ident) => { + let span = ident.span(); + let name = ident.unraw().to_string(); + Ident::new(&name.to_snake_case(), span).into() + } + Self::Spanless(name) => name.to_snake_case().into(), + } + } +} + +impl PartialEq for Content { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (Self::Spanned(me), Self::Spanned(them)) => me == them, + (Self::Spanned(me), Self::Spanless(them)) => me.unraw() == them, + (Self::Spanless(me), Self::Spanned(them)) => them.unraw() == me, + (Self::Spanless(me), Self::Spanless(them)) => me == them, + } + } +} + +impl<T: AsRef<str>> PartialEq<T> for Content { + fn eq(&self, other: &T) -> bool { + match self { + Self::Spanned(me) => me.unraw() == other, + Self::Spanless(me) => me == other.as_ref(), + } + } +} + +impl Eq for Content {} + +impl hash::Hash for Content { + fn hash<H: hash::Hasher>(&self, state: &mut H) { + match self { + Self::Spanned(i) => i.unraw().to_string().hash(state), + Self::Spanless(s) => s.hash(state), + } + } +} + +impl fmt::Display for Content { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Spanned(i) => i.fmt(f), + Self::Spanless(s) => s.fmt(f), + } + } +} + +impl From<Ident> for Content { + fn from(ident: Ident) -> Self { + Self::Spanned(ident) + } +} + +impl From<String> for Content { + fn from(string: String) -> Self { + Self::Spanless(string) + } +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum Kind { + Label, + Let, + Variable, +} + +impl PartialOrd for Kind { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(match (self, other) { + (Kind::Label, Kind::Label) + | (Kind::Let, Kind::Let) + | (Kind::Variable, Kind::Variable) => Ordering::Equal, + (Kind::Label, Kind::Let) + | (Kind::Label, Kind::Variable) + | (Kind::Let, Kind::Variable) => Ordering::Greater, + (Kind::Let, Kind::Label) + | (Kind::Variable, Kind::Label) + | (Kind::Variable, Kind::Let) => Ordering::Less, + }) + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct Name { + pub content: Content, + kind: Kind, +} + +impl Name { + pub fn new_variable<T: Into<Content>>(content: T) -> Self { + Self { + content: content.into(), + kind: Kind::Variable, + } + } + + pub fn new_let<T: Into<Content>>(content: T) -> Self { + Self { + content: content.into(), + kind: Kind::Let, + } + } + + pub fn new_label<T: Into<Content>>(content: T) -> Self { + Self { + content: content.into(), + kind: Kind::Label, + } + } + + pub fn merge(this: Option<Self>, that: Option<Self>) -> Option<Self> { + match (this, that) { + (None, that) => that, + (Some(this), None) => Some(this), + (Some(this), Some(that)) => { + if this.kind >= that.kind { + Some(this) + } else { + Some(that) + } + } + } + } + + pub fn merge_all<I: IntoIterator<Item = Option<Self>>>(iter: I) -> Option<Self> { + iter.into_iter().fold(None, Self::merge) + } +} + +impl Spanned for Name { + fn span(&self) -> Span { + self.content.span() + } +} + +impl From<Name> for Ident { + fn from(name: Name) -> Self { + name.content.into() + } +} + +impl CamelCase for Name { + fn to_camel_case(&self) -> Self::Owned { + Self { + content: self.content.to_camel_case(), + kind: self.kind, + } + } +} + +impl SnakeCase for Name { + fn to_snake_case(&self) -> Self::Owned { + Self { + content: self.content.to_snake_case(), + kind: self.kind, + } + } +} + +impl fmt::Display for Name { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.content.fmt(f) + } +} diff --git a/src/chomp/set.rs b/src/chomp/set.rs index 0661ab6..db533da 100644 --- a/src/chomp/set.rs +++ b/src/chomp/set.rs @@ -21,15 +21,12 @@ impl FirstSet { self.inner.is_empty() } - pub fn union(mut self, mut other: Self) -> Self { + pub fn union(&mut self, mut other: Self) { self.inner.append(&mut other.inner); - self } - pub fn intersect(&self, other: &Self) -> Self { - Self { - inner: self.inner.intersection(&other.inner).copied().collect(), - } + pub fn disjoint(&self, other: &Self) -> bool { + self.inner.intersection(&other.inner).next().is_none() } } @@ -57,26 +54,16 @@ impl FlastSet { self.inner.is_empty() } - pub fn union_first(mut self, mut other: FirstSet) -> Self { + pub fn union_first(&mut self, mut other: FirstSet) { self.inner.append(&mut other.inner); - self } - pub fn union(mut self, mut other: Self) -> Self { + pub fn union(&mut self, mut other: Self) { self.inner.append(&mut other.inner); - self } - pub fn intersect_first(&self, other: &FirstSet) -> Self { - Self { - inner: self.inner.intersection(&other.inner).copied().collect(), - } - } - - pub fn intersect(&self, other: &Self) -> Self { - Self { - inner: self.inner.intersection(&other.inner).copied().collect(), - } + pub fn disjoint(&self, other: &FirstSet) -> bool { + self.inner.intersection(&other.inner).next().is_none() } } diff --git a/src/chomp/typed/context.rs b/src/chomp/typed/context.rs index f3263ce..7ac4ae0 100644 --- a/src/chomp/typed/context.rs +++ b/src/chomp/typed/context.rs @@ -30,16 +30,11 @@ impl Context { .nth_back(var.index) .ok_or(GetVariableError::FreeVariable) .and_then(|ty| { - self.unguard_points - .last() - .and_then(|point| { - if point + var.index >= self.vars.len() { - Some(ty) - } else { - None - } - }) - .ok_or(GetVariableError::GuardedVariable) + if self.unguard_points.last().unwrap_or(&0) + var.index >= self.vars.len() { + Ok(ty) + } else { + Err(GetVariableError::GuardedVariable) + } }) } diff --git a/src/chomp/typed/error.rs b/src/chomp/typed/error.rs index 5c1e21e..48bfa25 100644 --- a/src/chomp/typed/error.rs +++ b/src/chomp/typed/error.rs @@ -5,27 +5,19 @@ use std::{ use proc_macro2::Span; -use crate::chomp::{ast::Variable, Name}; +use crate::chomp::{name::Name, ast::{Call, Fix, Lambda, Let, Variable}}; -use super::{context::GetVariableError, TypedExpression}; +use super::{Type, TypedExpression, context::GetVariableError}; /// A type error when using a fix point variable. #[derive(Debug)] pub struct VariableError { pub inner: GetVariableError, pub var: Variable, - pub span: Option<Span>, + pub span: Span, pub name: Option<Name>, } -impl From<VariableError> for syn::Error { - fn from(other: VariableError) -> Self { - let msg = other.to_string(); - let span = other.span; - Self::new(span.unwrap_or_else(Span::call_site), msg) - } -} - impl Display for VariableError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match &self.inner { @@ -47,24 +39,20 @@ impl Error for VariableError {} pub enum CatError { FirstNullable { expr: TypedExpression, - punct: Option<Span>, + punct: Span, }, FirstFlastOverlap { - first: Vec<TypedExpression>, - punct: Option<Span>, + front_ty: Type, + punct: Span, next: TypedExpression, }, } -impl From<CatError> for syn::Error { - fn from(other: CatError) -> Self { - let msg = other.to_string(); - let span = match other { - CatError::FirstNullable { punct, .. } | CatError::FirstFlastOverlap { punct, .. } => { - punct - } - }; - Self::new(span.unwrap_or_else(Span::call_site), msg) +impl CatError { + pub fn span(&self) -> Span { + match self { + Self::FirstNullable { punct, .. } | Self::FirstFlastOverlap { punct, .. } => *punct, + } } } @@ -84,24 +72,22 @@ impl Error for CatError {} #[derive(Debug)] pub enum AltError { BothNullable { - left: Vec<TypedExpression>, - punct: Option<Span>, + left_ty: Type, + punct: Span, right: TypedExpression, }, FirstOverlap { - left: Vec<TypedExpression>, - punct: Option<Span>, + left_ty: Type, + punct: Span, right: TypedExpression, }, } -impl From<AltError> for syn::Error { - fn from(other: AltError) -> Self { - let msg = other.to_string(); - let span = match other { - AltError::BothNullable { punct, .. } | AltError::FirstOverlap { punct, .. } => punct, - }; - Self::new(span.unwrap_or_else(Span::call_site), msg) +impl AltError { + pub fn span(&self) -> Span { + match self { + Self::BothNullable { punct, .. } | Self::FirstOverlap { punct, .. } => *punct, + } } } @@ -121,6 +107,24 @@ pub enum TypeError { Cat(CatError), Alt(AltError), Variable(VariableError), + UnexpectedCall { span: Span, call: Call }, + UnexpectedLambda { span: Span, lambda: Lambda }, + UnexpectedLet { span: Span, stmt: Let }, + ExpectedLambda {span: Span, fix: Fix }, +} + +impl TypeError { + pub fn span(&self) -> Span { + match self { + TypeError::Cat(c) => c.span(), + TypeError::Alt(a) => a.span(), + TypeError::Variable(v) => v.span, + TypeError::UnexpectedCall { span, .. } + | TypeError::UnexpectedLambda { span, .. } + | TypeError::UnexpectedLet { span, .. } + | TypeError::ExpectedLambda { span, .. } => *span, + } + } } impl From<CatError> for TypeError { @@ -143,11 +147,9 @@ impl From<VariableError> for TypeError { impl From<TypeError> for syn::Error { fn from(other: TypeError) -> Self { - match other { - TypeError::Cat(e) => e.into(), - TypeError::Alt(e) => e.into(), - TypeError::Variable(e) => e.into(), - } + let span = other.span(); + let msg = format!("{}", other); + Self::new(span, msg) } } @@ -157,6 +159,19 @@ impl Display for TypeError { Self::Cat(e) => e.fmt(f), Self::Alt(e) => e.fmt(f), Self::Variable(e) => e.fmt(f), + + Self::UnexpectedCall { .. } => { + write!(f, "unexpected call") + } + Self::UnexpectedLambda { .. } => { + write!(f, "unexpected lambda") + } + Self::UnexpectedLet { .. } => { + write!(f, "unexpected let") + } + Self::ExpectedLambda { .. } => { + write!(f, "expected a lambda expression") + } } } } diff --git a/src/chomp/typed/infer.rs b/src/chomp/typed/infer.rs index e2c2198..bc2baea 100644 --- a/src/chomp/typed/infer.rs +++ b/src/chomp/typed/infer.rs @@ -1,8 +1,18 @@ +use std::{array, iter}; + use proc_macro2::Span; -use crate::chomp::{Name, ast::{Alt, Call, Cat, Epsilon, Fix, Lambda, Literal, NamedExpression, Variable, substitute::Translate}, visit::{Folder, Visitable}}; +use crate::chomp::{ + ast::{Alt, Call, Cat, Epsilon, Expression, Fix, Lambda, Let, Literal, Variable}, + name::Name, + visit::{Folder, Visitable}, +}; -use super::{Type, Typed, TypedExpression, context::Context, error::{TypeError, VariableError}}; +use super::{ + context::Context, + error::{AltError, CatError, TypeError, VariableError}, + Type, Typed, TypedExpression, +}; #[derive(Debug)] pub struct TypeInfer<'a> { @@ -12,7 +22,7 @@ pub struct TypeInfer<'a> { impl Folder for TypeInfer<'_> { type Out = Result<TypedExpression, TypeError>; - fn fold_epsilon(&mut self, name: Option<Name>, span: Option<Span>, eps: Epsilon) -> Self::Out { + fn fold_epsilon(&mut self, name: Option<Name>, span: Span, eps: Epsilon) -> Self::Out { Ok(TypedExpression { inner: super::Epsilon::from(eps).into(), name, @@ -20,7 +30,7 @@ impl Folder for TypeInfer<'_> { }) } - fn fold_literal(&mut self, name: Option<Name>, span: Option<Span>, lit: Literal) -> Self::Out { + fn fold_literal(&mut self, name: Option<Name>, span: Span, lit: Literal) -> Self::Out { Ok(TypedExpression { inner: super::Literal::from(lit).into(), name, @@ -28,47 +38,99 @@ impl Folder for TypeInfer<'_> { }) } - fn fold_cat(&mut self, name: Option<Name>, span: Option<Span>, cat: Cat) -> Self::Out { + fn fold_cat(&mut self, name: Option<Name>, span: Span, cat: Cat) -> Self::Out { let first = cat.first.fold(self)?; + + if first.get_type().nullable() { + let punct = cat.rest.into_iter().next().map(|(p, _)| p).unwrap_or_else(Span::call_site); + return Err(CatError::FirstNullable { expr: first, punct }.into()); + } + let rest = cat.rest; - self.context - .with_unguard(|context| -> Result<TypedExpression, TypeError> { - let mut infer = TypeInfer { context }; - let rest = rest - .into_iter() - .map(|(punct, term)| -> Result<_, TypeError> { - Ok((punct, term.fold(&mut infer)?)) - }) - .collect::<Result<Vec<_>, _>>()?; - Ok(TypedExpression { - inner: super::Cat::new(first, rest)?.into(), - name, - span, + let mut ty = first.get_type().clone(); + let terms = self.context.with_unguard(|context| { + let mut infer = TypeInfer { context }; + rest.into_iter() + .map(|(punct, right)| { + let right = right.fold(&mut infer)?; + if ty.flast_set().disjoint(right.get_type().first_set()) { + ty.cat(right.get_type().clone()); + Ok(right) + } else { + Err(CatError::FirstFlastOverlap { + front_ty: ty.clone(), + punct, + next: right, + } + .into()) + } }) - }) + .collect::<Result<Vec<_>, TypeError>>() + })?; + Ok(TypedExpression { + inner: super::Cat { + terms: iter::once(first).chain(terms).collect(), + ty, + } + .into(), + name, + span, + }) } - fn fold_alt(&mut self, name: Option<Name>, span: Option<Span>, alt: Alt) -> Self::Out { + fn fold_alt(&mut self, name: Option<Name>, span: Span, alt: Alt) -> Self::Out { let first = alt.first.fold(self)?; - let rest = alt + let mut ty = first.get_type().clone(); + let terms = alt .rest .into_iter() - .map(|(punct, term)| -> Result<_, TypeError> { Ok((punct, term.fold(self)?)) }) - .collect::<Result<Vec<_>, _>>()?; + .map(|(punct, right)| { + let right = right.fold(self)?; + if ty.nullable() && right.get_type().nullable() { + Err(AltError::BothNullable { + left_ty: ty.clone(), + punct, + right, + } + .into()) + } else if ty.first_set().disjoint(right.get_type().first_set()) { + ty.alt(right.get_type().clone()); + Ok(right) + } else { + Err(AltError::FirstOverlap { + left_ty: ty.clone(), + punct, + right, + } + .into()) + } + }) + .collect::<Result<Vec<_>, TypeError>>()?; Ok(TypedExpression { - inner: super::Alt::new(first, rest)?.into(), + inner: super::Alt { + terms: iter::once(first).chain(terms).collect(), + ty, + } + .into(), name, span, }) } - fn fold_fix(&mut self, name: Option<Name>, span: Option<Span>, fix: Fix) -> Self::Out { + fn fold_fix(&mut self, name: Option<Name>, span: Span, fix: Fix) -> Self::Out { let mut ty = Type::default(); + let body = if let Expression::Lambda(l) = fix.inner.expr { + let mut body = *l.inner; + body.name = Name::merge_all(array::IntoIter::new([fix.inner.name, body.name, name.clone()])); + body + } else { + return Err(TypeError::ExpectedLambda { span, fix }); + }; loop { let last = ty; let res = self.context.with_variable_type(last.clone(), |context| { - fix.inner.clone().fold(&mut TypeInfer { context }) + body.clone().fold(&mut TypeInfer { context }) })?; ty = res.get_type().clone(); @@ -88,7 +150,7 @@ impl Folder for TypeInfer<'_> { fn fold_variable( &mut self, name: Option<Name>, - span: Option<Span>, + span: Span, var: Variable, ) -> Self::Out { let ty = match self.context.get_variable_type(var) { @@ -110,18 +172,101 @@ impl Folder for TypeInfer<'_> { }) } - fn fold_call(&mut self, name: Option<Name>, span: Option<Span>, call: Call) -> Self::Out { - let translated = NamedExpression { name, expr: call.into(), span}.fold(&mut Translate::new())?; - let inner = translated.fold(self)?; - todo!() + fn fold_call(&mut self, _name: Option<Name>, span: Span, call: Call) -> Self::Out { + Err(TypeError::UnexpectedCall { span, call }) } fn fold_lambda( &mut self, _name: Option<Name>, - _span: Option<Span>, - _lambda: Lambda, + span: Span, + lambda: Lambda, ) -> Self::Out { - unimplemented!() + Err(TypeError::UnexpectedLambda { span, lambda }) + } + + fn fold_let(&mut self, _name: Option<Name>, span: Span, stmt: Let) -> Self::Out { + Err(TypeError::UnexpectedLet { span, stmt }) + } +} + +#[cfg(test)] +mod tests { + use crate::chomp::{ast::NamedExpression, typed::RawTypedExpression}; + + use super::*; + + #[test] + fn cat_uses_all() { + let ast = Cat { + first: Box::new(NamedExpression { + name: None, + expr: "a".to_owned().into(), + span: Span::call_site(), + }), + rest: vec![( + Span::call_site(), + NamedExpression { + name: None, + expr: "b".to_owned().into(), + span: Span::call_site(), + }, + )], + }; + + let typed = NamedExpression { + name: None, + expr: ast.into(), + span: Span::call_site(), + } + .fold(&mut TypeInfer { + context: &mut Context::default(), + }) + .unwrap(); + match typed.inner { + RawTypedExpression::Cat(super::super::Cat { terms, .. }) => assert_eq!(terms.len(), 2), + RawTypedExpression::Epsilon(_) + | RawTypedExpression::Literal(_) + | RawTypedExpression::Alt(_) + | RawTypedExpression::Fix(_) + | RawTypedExpression::Variable(_) => panic!("Cat should type check to Cat"), + }; + } + + #[test] + fn alt_uses_all() { + let ast = Alt { + first: Box::new(NamedExpression { + name: None, + expr: "a".to_owned().into(), + span: Span::call_site(), + }), + rest: vec![( + Span::call_site(), + NamedExpression { + name: None, + expr: "b".to_owned().into(), + span: Span::call_site(), + }, + )], + }; + + let typed = NamedExpression { + name: None, + expr: ast.into(), + span: Span::call_site(), + } + .fold(&mut TypeInfer { + context: &mut Context::default(), + }) + .unwrap(); + match typed.inner { + RawTypedExpression::Alt(super::super::Alt { terms, .. }) => assert_eq!(terms.len(), 2), + RawTypedExpression::Epsilon(_) + | RawTypedExpression::Literal(_) + | RawTypedExpression::Cat(_) + | RawTypedExpression::Fix(_) + | RawTypedExpression::Variable(_) => panic!("Alt should type check to Alt"), + }; } } diff --git a/src/chomp/typed/lower.rs b/src/chomp/typed/lower.rs index 37589a1..03237de 100644 --- a/src/chomp/typed/lower.rs +++ b/src/chomp/typed/lower.rs @@ -1,6 +1,6 @@ use proc_macro2::Span; -use crate::chomp::Name; +use crate::chomp::name::Name; use super::{Alt, Cat, Epsilon, Fix, Literal, RawTypedExpression, TypedExpression, Variable}; @@ -8,19 +8,19 @@ pub trait Backend: Default { type Id; type Code; - fn gen_epsilon(&mut self, name: Option<Name>, span: Option<Span>, eps: Epsilon) -> Self::Id; + fn gen_epsilon(&mut self, name: Option<Name>, span: Span, eps: Epsilon) -> Self::Id; - fn gen_literal(&mut self, name: Option<Name>, span: Option<Span>, lit: Literal) -> Self::Id; + fn gen_literal(&mut self, name: Option<Name>, span: Span, lit: Literal) -> Self::Id; - fn gen_cat(&mut self, name: Option<Name>, span: Option<Span>, cat: Cat) -> Self::Id; + fn gen_cat(&mut self, name: Option<Name>, span: Span, cat: Cat) -> Self::Id; - fn gen_alt(&mut self, name: Option<Name>, span: Option<Span>, alt: Alt) -> Self::Id; + fn gen_alt(&mut self, name: Option<Name>, span: Span, alt: Alt) -> Self::Id; - fn gen_fix(&mut self, name: Option<Name>, span: Option<Span>, fix: Fix) -> Self::Id; + fn gen_fix(&mut self, name: Option<Name>, span: Span, fix: Fix) -> Self::Id; - fn gen_variable(&mut self, name: Option<Name>, span: Option<Span>, var: Variable) -> Self::Id; + fn gen_variable(&mut self, name: Option<Name>, span: Span, var: Variable) -> Self::Id; - fn emit_code(self, name: Option<Name>, span: Option<Span>, id: Self::Id) -> Self::Code; + fn emit_code(self, name: Option<Name>, span: Span, id: Self::Id) -> Self::Code; } pub trait GenerateCode { diff --git a/src/chomp/typed/mod.rs b/src/chomp/typed/mod.rs index cddb05a..f1f6967 100644 --- a/src/chomp/typed/mod.rs +++ b/src/chomp/typed/mod.rs @@ -5,7 +5,7 @@ use proc_macro2::Span; use super::{ ast, set::{FirstSet, FlastSet}, - Name, + name::Name, }; pub mod context; @@ -14,7 +14,6 @@ pub mod lower; mod infer; -use self::error::{AltError, CatError}; pub use self::infer::TypeInfer; #[derive(Debug, Default, Clone, Eq, Hash, PartialEq)] @@ -53,28 +52,25 @@ impl Type { &self.flast_set } - pub fn cat(self, other: Self) -> Self { - Self { - nullable: self.nullable && other.nullable, - first_set: self.first_set.union(if self.nullable { - other.first_set.clone() - } else { - FirstSet::default() - }), - flast_set: other.flast_set.union(if other.nullable { - self.flast_set.union_first(other.first_set) - } else { - FlastSet::default() - }), + pub fn cat(&mut self, other: Self) { + if self.nullable { + self.first_set.union(other.first_set.clone()) } - } - pub fn alt(self, other: Self) -> Self { - Self { - nullable: self.nullable || other.nullable, - first_set: self.first_set.union(other.first_set), - flast_set: self.flast_set.union(other.flast_set), + if other.nullable { + self.flast_set.union_first(other.first_set); + self.flast_set.union(other.flast_set); + } else { + self.flast_set = other.flast_set; } + + self.nullable &= other.nullable; + } + + pub fn alt(&mut self, other: Self) { + self.nullable |= other.nullable; + self.first_set.union(other.first_set); + self.flast_set.union(other.flast_set); } } @@ -122,43 +118,6 @@ pub struct Cat { ty: Type, } -impl Cat { - fn new<I: IntoIterator<Item = (Option<Span>, TypedExpression)>>( - first: TypedExpression, - rest: I, - ) -> Result<Self, CatError> { - if first.get_type().nullable() { - return Err(CatError::FirstNullable { - expr: first, - punct: todo!(), - }); - } - - rest.into_iter() - .try_fold( - (first.get_type().clone(), vec![first]), - |(ty, mut terms), (punct, right)| { - if ty - .flast_set() - .intersect_first(right.get_type().first_set()) - .is_empty() - { - let ty = ty.cat(right.get_type().clone()); - terms.push(right); - Ok((ty, terms)) - } else { - Err(CatError::FirstFlastOverlap { - first: terms, - punct, - next: right, - }) - } - }, - ) - .map(|(ty, terms)| Self { ty, terms }) - } -} - impl IntoIterator for Cat { type Item = TypedExpression; @@ -175,42 +134,6 @@ pub struct Alt { ty: Type, } -impl Alt { - pub fn new<I: IntoIterator<Item = (Option<Span>, TypedExpression)>>( - first: TypedExpression, - rest: I, - ) -> Result<Self, AltError> { - rest.into_iter() - .try_fold( - (first.get_type().clone(), vec![first]), - |(ty, mut terms), (punct, right)| { - if ty.nullable() && right.get_type().nullable() { - Err(AltError::BothNullable { - left: terms, - punct, - right, - }) - } else if ty - .first_set() - .intersect(right.get_type().first_set()) - .is_empty() - { - let ty = ty.alt(right.get_type().clone()); - terms.push(right); - Ok((ty, terms)) - } else { - Err(AltError::FirstOverlap { - left: terms, - punct, - right, - }) - } - }, - ) - .map(|(ty, terms)| Self { ty, terms }) - } -} - impl IntoIterator for Alt { type Item = TypedExpression; @@ -245,14 +168,6 @@ impl Variable { } #[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct Call { - ty: Type, -} - -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct Lambda {} - -#[derive(Clone, Debug, Eq, Hash, PartialEq)] enum RawTypedExpression { Epsilon(Epsilon), Literal(Literal), @@ -260,8 +175,6 @@ enum RawTypedExpression { Alt(Alt), Fix(Fix), Variable(Variable), - Call(Call), - Lambda(Lambda), } impl From<Epsilon> for RawTypedExpression { @@ -304,7 +217,7 @@ impl From<Variable> for RawTypedExpression { pub struct TypedExpression { inner: RawTypedExpression, pub name: Option<Name>, - pub span: Option<Span>, + pub span: Span, } impl PartialEq for TypedExpression { @@ -360,3 +273,20 @@ impl Typed for TypedExpression { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn cat_right() { + let epsilon = Type { nullable: true, ..Type::default()}; + let mut x = Type::of_str("a"); + x.cat(Type::of_str("b")); + assert_eq!(x, Type::of_str("a")); + x.cat(Type::default()); + assert_eq!(x, Type::of_str("a")); + x.cat(epsilon); + assert_eq!(x, Type::of_str("a")); + } +} diff --git a/src/chomp/visit.rs b/src/chomp/visit.rs index 7e716d3..b37909d 100644 --- a/src/chomp/visit.rs +++ b/src/chomp/visit.rs @@ -1,113 +1,81 @@ use proc_macro2::Span; use super::{ - ast::{Alt, Call, Cat, Epsilon, Expression, Fix, Lambda, Literal, NamedExpression, Variable}, - Name, + ast::{ + Alt, Call, Cat, Epsilon, Expression, Fix, Lambda, Let, Literal, NamedExpression, Variable, + }, + name::Name, }; pub trait Visitor { type Out; - fn visit_epsilon( - &mut self, - name: Option<&Name>, - span: Option<Span>, - eps: &Epsilon, - ) -> Self::Out; + fn visit_epsilon(&mut self, name: Option<&Name>, span: Span, eps: &Epsilon) -> Self::Out; - fn visit_literal( - &mut self, - name: Option<&Name>, - span: Option<Span>, - lit: &Literal, - ) -> Self::Out; + fn visit_literal(&mut self, name: Option<&Name>, span: Span, lit: &Literal) -> Self::Out; - fn visit_cat(&mut self, name: Option<&Name>, span: Option<Span>, cat: &Cat) -> Self::Out; + fn visit_cat(&mut self, name: Option<&Name>, span: Span, cat: &Cat) -> Self::Out; - fn visit_alt(&mut self, name: Option<&Name>, span: Option<Span>, alt: &Alt) -> Self::Out; + fn visit_alt(&mut self, name: Option<&Name>, span: Span, alt: &Alt) -> Self::Out; - fn visit_fix(&mut self, name: Option<&Name>, span: Option<Span>, fix: &Fix) -> Self::Out; + fn visit_fix(&mut self, name: Option<&Name>, span: Span, fix: &Fix) -> Self::Out; - fn visit_variable( - &mut self, - name: Option<&Name>, - span: Option<Span>, - var: &Variable, - ) -> Self::Out; + fn visit_variable(&mut self, name: Option<&Name>, span: Span, var: &Variable) -> Self::Out; - fn visit_call(&mut self, name: Option<&Name>, span: Option<Span>, call: &Call) -> Self::Out; + fn visit_call(&mut self, name: Option<&Name>, span: Span, call: &Call) -> Self::Out; - fn visit_lambda( - &mut self, - name: Option<&Name>, - span: Option<Span>, - lambda: &Lambda, - ) -> Self::Out; + fn visit_lambda(&mut self, name: Option<&Name>, span: Span, lambda: &Lambda) -> Self::Out; + + fn visit_let(&mut self, name: Option<&Name>, span: Span, stmt: &Let) -> Self::Out; } pub trait Mapper { type Out; - fn map_epsilon( - &mut self, - name: &mut Option<Name>, - span: Option<Span>, - eps: &mut Epsilon, - ) -> Self::Out; + fn map_epsilon(&mut self, name: &mut Option<Name>, span: Span, eps: &mut Epsilon) -> Self::Out; - fn map_literal( - &mut self, - name: &mut Option<Name>, - span: Option<Span>, - lit: &mut Literal, - ) -> Self::Out; + fn map_literal(&mut self, name: &mut Option<Name>, span: Span, lit: &mut Literal) -> Self::Out; - fn map_cat(&mut self, name: &mut Option<Name>, span: Option<Span>, cat: &mut Cat) -> Self::Out; + fn map_cat(&mut self, name: &mut Option<Name>, span: Span, cat: &mut Cat) -> Self::Out; - fn map_alt(&mut self, name: &mut Option<Name>, span: Option<Span>, alt: &mut Alt) -> Self::Out; + fn map_alt(&mut self, name: &mut Option<Name>, span: Span, alt: &mut Alt) -> Self::Out; - fn map_fix(&mut self, name: &mut Option<Name>, span: Option<Span>, fix: &mut Fix) -> Self::Out; + fn map_fix(&mut self, name: &mut Option<Name>, span: Span, fix: &mut Fix) -> Self::Out; fn map_variable( &mut self, name: &mut Option<Name>, - span: Option<Span>, + span: Span, var: &mut Variable, ) -> Self::Out; - fn map_call( - &mut self, - name: &mut Option<Name>, - span: Option<Span>, - call: &mut Call, - ) -> Self::Out; + fn map_call(&mut self, name: &mut Option<Name>, span: Span, call: &mut Call) -> Self::Out; - fn map_lambda( - &mut self, - name: &mut Option<Name>, - span: Option<Span>, - lambda: &mut Lambda, - ) -> Self::Out; + fn map_lambda(&mut self, name: &mut Option<Name>, span: Span, lambda: &mut Lambda) + -> Self::Out; + + fn map_let(&mut self, name: &mut Option<Name>, span: Span, stmt: &mut Let) -> Self::Out; } pub trait Folder { type Out; - fn fold_epsilon(&mut self, name: Option<Name>, span: Option<Span>, eps: Epsilon) -> Self::Out; + fn fold_epsilon(&mut self, name: Option<Name>, span: Span, eps: Epsilon) -> Self::Out; - fn fold_literal(&mut self, name: Option<Name>, span: Option<Span>, lit: Literal) -> Self::Out; + fn fold_literal(&mut self, name: Option<Name>, span: Span, lit: Literal) -> Self::Out; - fn fold_cat(&mut self, name: Option<Name>, span: Option<Span>, cat: Cat) -> Self::Out; + fn fold_cat(&mut self, name: Option<Name>, span: Span, cat: Cat) -> Self::Out; - fn fold_alt(&mut self, name: Option<Name>, span: Option<Span>, alt: Alt) -> Self::Out; + fn fold_alt(&mut self, name: Option<Name>, span: Span, alt: Alt) -> Self::Out; - fn fold_fix(&mut self, name: Option<Name>, span: Option<Span>, fix: Fix) -> Self::Out; + fn fold_fix(&mut self, name: Option<Name>, span: Span, fix: Fix) -> Self::Out; - fn fold_variable(&mut self, name: Option<Name>, span: Option<Span>, var: Variable) - -> Self::Out; + fn fold_variable(&mut self, name: Option<Name>, span: Span, var: Variable) -> Self::Out; + + fn fold_call(&mut self, name: Option<Name>, span: Span, call: Call) -> Self::Out; - fn fold_call(&mut self, name: Option<Name>, span: Option<Span>, call: Call) -> Self::Out; + fn fold_lambda(&mut self, name: Option<Name>, span: Span, lambda: Lambda) -> Self::Out; - fn fold_lambda(&mut self, name: Option<Name>, span: Option<Span>, lambda: Lambda) -> Self::Out; + fn fold_let(&mut self, name: Option<Name>, span: Span, stmt: Let) -> Self::Out; } pub trait Visitable { @@ -118,6 +86,20 @@ pub trait Visitable { fn fold<F: Folder>(self, folder: &mut F) -> <F as Folder>::Out; } +impl<T: Visitable> Visitable for Box<T> { + fn visit<V: Visitor>(&self, visitor: &mut V) -> <V as Visitor>::Out { + self.as_ref().visit(visitor) + } + + fn map<M: Mapper>(&mut self, mapper: &mut M) -> <M as Mapper>::Out { + self.as_mut().map(mapper) + } + + fn fold<F: Folder>(self, folder: &mut F) -> <F as Folder>::Out { + (*self).fold(folder) + } +} + impl Visitable for NamedExpression { fn visit<V: Visitor>(&self, visitor: &mut V) -> <V as Visitor>::Out { match &self.expr { @@ -129,6 +111,7 @@ impl Visitable for NamedExpression { Expression::Variable(v) => visitor.visit_variable(self.name.as_ref(), self.span, v), Expression::Call(c) => visitor.visit_call(self.name.as_ref(), self.span, c), Expression::Lambda(l) => visitor.visit_lambda(self.name.as_ref(), self.span, l), + Expression::Let(l) => visitor.visit_let(self.name.as_ref(), self.span, l), } } @@ -142,6 +125,7 @@ impl Visitable for NamedExpression { Expression::Variable(v) => mapper.map_variable(&mut self.name, self.span, v), Expression::Call(c) => mapper.map_call(&mut self.name, self.span, c), Expression::Lambda(l) => mapper.map_lambda(&mut self.name, self.span, l), + Expression::Let(l) => mapper.map_let(&mut self.name, self.span, l), } } @@ -155,6 +139,7 @@ impl Visitable for NamedExpression { Expression::Variable(v) => folder.fold_variable(self.name, self.span, v), Expression::Call(c) => folder.fold_call(self.name, self.span, c), Expression::Lambda(l) => folder.fold_lambda(self.name, self.span, l), + Expression::Let(l) => folder.fold_let(self.name, self.span, l), } } } diff --git a/src/lower/mod.rs b/src/lower/mod.rs index dcd0f1f..e74f86a 100644 --- a/src/lower/mod.rs +++ b/src/lower/mod.rs @@ -8,10 +8,15 @@ use proc_macro2::{Ident, Span, TokenStream, TokenTree}; use quote::{format_ident, quote, quote_spanned}; use syn::{Index, LitStr}; -use crate::chomp::{Name, ast, set::FirstSet, typed::{ +use crate::chomp::{ + ast, + name::Name, + set::FirstSet, + typed::{ lower::{Backend, GenerateCode}, Alt, Cat, Epsilon, Fix, Literal, Type, Typed, TypedExpression, Variable, - }}; + }, +}; #[derive(Clone, Debug)] struct Ty { @@ -44,7 +49,7 @@ impl RustBackend { match name { None => (id, format_ident!("{}{}", prefix, id + 1, span = span)), Some(name) => { - let name = name.to_camel_case().into_ident(span); + let name: Ident = name.to_camel_case().into(); let count = self.name_map.entry(name.clone()).or_insert(0); *count += 1; (id, format_ident!("{}{}", name, count)) @@ -60,10 +65,7 @@ impl RustBackend { .into_iter() .map(|e| { ( - ( - e.get_type().clone(), - (e.name.clone(), e.span.unwrap_or_else(Span::call_site)), - ), + (e.get_type().clone(), (e.name.clone(), e.span)), e.gen(self), ) }) @@ -104,7 +106,7 @@ impl RustBackend { .map(move |(index, (name, span))| match name { None => format_ident!("{}{}", default, index + 1, span = span), Some(name) => { - let name = name.to_snake_case().into_ident(span); + let name: Ident = name.to_snake_case().into(); let count = name_map.entry(name.clone()).or_insert(0_usize); *count += 1; format_ident!("{}{}", name, count) @@ -122,7 +124,7 @@ impl RustBackend { .map(move |(index, (name, span))| match name { None => format_ident!("{}{}", default, index + 1, span = span), Some(name) => { - let name = name.to_camel_case().into_ident(span); + let name: Ident = name.to_camel_case().into(); let count = name_map.entry(name.clone()).or_insert(0_usize); *count += 1; format_ident!("{}{}", name, count) @@ -153,7 +155,7 @@ impl Backend for RustBackend { type Code = TokenStream; - fn gen_epsilon(&mut self, _name: Option<Name>, _span: Option<Span>, _eps: Epsilon) -> Self::Id { + fn gen_epsilon(&mut self, _name: Option<Name>, _span: Span, _eps: Epsilon) -> Self::Id { if let Some(id) = self.eps_id { return id; } @@ -167,9 +169,7 @@ impl Backend for RustBackend { id } - fn gen_literal(&mut self, name: Option<Name>, span: Option<Span>, lit: Literal) -> Self::Id { - let span = span.unwrap_or_else(Span::call_site); - + fn gen_literal(&mut self, name: Option<Name>, span: Span, lit: Literal) -> Self::Id { let lit: ast::Literal = lit.into(); if let Some(&id) = self.lit_map.get(&lit) { return id; @@ -218,8 +218,7 @@ impl Backend for RustBackend { id } - fn gen_cat(&mut self, name: Option<Name>, span: Option<Span>, cat: Cat) -> Self::Id { - let span = span.unwrap_or_else(Span::call_site); + fn gen_cat(&mut self, name: Option<Name>, span: Span, cat: Cat) -> Self::Id { let (_, name_spans, ids) = self.recurse_exprs(cat); if let Some(&id) = self.cat_map.get(&ids) { @@ -283,8 +282,7 @@ impl Backend for RustBackend { id } - fn gen_alt(&mut self, name: Option<Name>, span: Option<Span>, alt: Alt) -> Self::Id { - let span = span.unwrap_or_else(Span::call_site); + fn gen_alt(&mut self, name: Option<Name>, span: Span, alt: Alt) -> Self::Id { let (tys, name_spans, ids) = self.recurse_exprs(alt); if let Some(&id) = self.alt_map.get(&ids) { @@ -338,7 +336,7 @@ impl Backend for RustBackend { fn take<P: Parser + ?Sized>(input: &mut P) -> Result<Self, TakeError> { match input.peek() { #(#firsts => Ok(Self::#first_alts(input.take()?)),)* - _ => Ok(Self::#nullable(input.take()?)) + _ => Ok(Self::#nullable(input.take()?)), } } } @@ -379,8 +377,7 @@ impl Backend for RustBackend { id } - fn gen_fix(&mut self, name: Option<Name>, span: Option<Span>, fix: Fix) -> Self::Id { - let span = span.unwrap_or_else(Span::call_site); + fn gen_fix(&mut self, name: Option<Name>, span: Span, fix: Fix) -> Self::Id { let inner = fix.unwrap(); if let Some(&id) = self.fix_map.get(&inner) { @@ -401,29 +398,13 @@ impl Backend for RustBackend { self.context.pop(); let inner_ty = self.data[inner].name.clone(); - let rest = quote_spanned! {span=> - #[derive(Clone, Debug, Eq, Hash, PartialEq)] - pub struct #name(pub #inner_ty); - - impl ::std::fmt::Display for #name { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - self.0.fmt(f) - } - } - - impl Parse for #name { - fn take<P: Parser + ?Sized>(input: &mut P) -> Result<Self, TakeError> { - input.take().map(Self) - } - } - }; + let rest = quote_spanned! {span=> pub type #name = #inner_ty;}; self.data[id].rest = rest; self.data[id].deps = [inner].iter().cloned().collect(); id } - fn gen_variable(&mut self, _name: Option<Name>, span: Option<Span>, var: Variable) -> Self::Id { - let span = span.unwrap_or_else(Span::call_site); + fn gen_variable(&mut self, _name: Option<Name>, span: Span, var: Variable) -> Self::Id { let fix_id = self.context[self.context.len() - var.index() - 1]; if let Some(&id) = self.var_map.get(&fix_id) { @@ -443,9 +424,7 @@ impl Backend for RustBackend { id } - fn emit_code(self, name: Option<Name>, span: Option<Span>, id: Self::Id) -> Self::Code { - let span = span.unwrap_or_else(Span::call_site); - + fn emit_code(self, name: Option<Name>, span: Span, id: Self::Id) -> Self::Code { let mut tokens = quote_spanned! {span=> use ::chewed::*; }; @@ -467,7 +446,7 @@ impl Backend for RustBackend { let root_name = self.data[id].name.clone(); tokens.extend(if let Some(name) = name { - let name = name.into_ident(span); + let name = name.into(); let count = self.name_map.get(&name).copied().unwrap_or_default() + 1; let name = format_ident!("{}{}", name, count); quote_spanned! {span=> diff --git a/src/main.rs b/src/main.rs index 0e7193e..0954074 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::{ use chomp::{ chomp::{ - ast::substitute::InlineCalls, + ast::substitute::Reduce, typed::{ context::Context, lower::{Backend, GenerateCode}, @@ -15,8 +15,12 @@ use chomp::{ visit::Visitable, }, lower::RustBackend, - nibble::File, + nibble::{ + convert::{self, Convert}, + Statement, + }, }; +use proc_macro2::Span; fn main() { let mut input = String::new(); @@ -24,12 +28,13 @@ fn main() { .read_to_string(&mut input) .map_err(|e| Box::new(e) as Box<dyn Error>) .and_then(|_| syn::parse_str(&input).map_err(|e| Box::new(e) as Box<dyn Error>)) - .and_then(|nibble: File| nibble.convert().map_err(|e| Box::new(e) as Box<dyn Error>)) - .and_then(|(funs, goal)| { - funs.into_iter() - .try_rfold(goal, |goal, function| { - goal.fold(&mut InlineCalls { function }) - }) + .and_then(|nibble: Statement| { + nibble + .convert(&mut convert::Context::default()) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) + .and_then(|expr| { + expr.fold(&mut Reduce) .map_err(|e| Box::new(e) as Box<dyn Error>) }) .and_then(|term| { @@ -37,12 +42,12 @@ fn main() { term.fold(&mut TypeInfer { context: &mut context, }) - .map_err(|e| Box::new(e) as Box<dyn Error>) + .map_err(|e| Box::new(e) as Box<dyn Error>) }) .map(|typed| { let mut backend = RustBackend::default(); let id = typed.gen(&mut backend); - backend.emit_code(None, None, id) + backend.emit_code(None, Span::call_site(), id) }) .and_then(|code| { write!(io::stdout(), "{:#}", code).map_err(|e| Box::new(e) as Box<dyn Error>) diff --git a/src/nibble/convert.rs b/src/nibble/convert.rs index e5e8c5d..ca6c95a 100644 --- a/src/nibble/convert.rs +++ b/src/nibble/convert.rs @@ -1,18 +1,18 @@ use std::{fmt, mem}; use proc_macro2::Span; -use syn::{punctuated::Pair, Token}; +use syn::{punctuated::Pair, spanned::Spanned, Token}; -use crate::chomp::{ - ast::{self, NamedExpression}, - Name, -}; +use crate::chomp::{ast::{self, NamedExpression}, name::{Content, Name}}; -use super::{Alt, Call, Cat, Expression, Fix, Ident, Labelled, Lambda, ParenExpression, Term}; +use super::{ + Alt, Call, Cat, Expression, Fix, GoalStatement, Ident, Labelled, Lambda, LetStatement, + ParenExpression, Statement, Term, +}; #[derive(Debug, Default)] pub struct Context { - bindings: Vec<Name>, + bindings: Vec<Content>, } impl Context { @@ -20,20 +20,24 @@ impl Context { Self::default() } + /// Get the De Bruijn index of `name`, if it is defined. pub fn lookup(&self, name: &Name) -> Option<usize> { self.bindings .iter() + .rev() .enumerate() - .rfind(|(_, n)| *n == name) + .find(|(_, n)| *n == &name.content) .map(|(idx, _)| idx) } + /// Permanently add the variable `name` to the top of the stack. pub fn push_variable(&mut self, name: Name) { - self.bindings.push(name); + self.bindings.push(name.content); } + /// Call `f` with the variable `name` pushed to the top of the stack. pub fn with_variable<F: FnOnce(&mut Self) -> R, R>(&mut self, name: Name, f: F) -> R { - self.bindings.push(name); + self.bindings.push(name.content); let res = f(self); self.bindings.pop(); res @@ -45,7 +49,7 @@ impl Context { f: F, ) -> R { let len = self.bindings.len(); - self.bindings.extend(names); + self.bindings.extend(names.into_iter().map(|n| n.content)); let res = f(self); self.bindings.resize_with(len, || unreachable!()); res @@ -55,10 +59,9 @@ impl Context { #[derive(Clone, Debug)] pub enum ConvertError { UndeclaredName(Box<Name>), - EmptyCat(Option<Span>), - EmptyAlt(Option<Span>), - EmptyCall(Option<Span>), - MissingArgs(Option<Span>), + EmptyCat(Span), + EmptyAlt(Span), + EmptyCall(Span), } impl From<ConvertError> for syn::Error { @@ -68,11 +71,10 @@ impl From<ConvertError> for syn::Error { ConvertError::UndeclaredName(name) => name.span(), ConvertError::EmptyCat(span) | ConvertError::EmptyAlt(span) - | ConvertError::EmptyCall(span) - | ConvertError::MissingArgs(span) => span, + | ConvertError::EmptyCall(span) => span, }; - Self::new(span.unwrap_or_else(Span::call_site), msg) + Self::new(span, msg) } } @@ -91,9 +93,6 @@ impl fmt::Display for ConvertError { Self::EmptyCall(_) => { write!(f, "call has no function") } - Self::MissingArgs(_) => { - write!(f, "call has no arguments") - } } } } @@ -106,8 +105,8 @@ pub trait Convert { impl Convert for Ident { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { - let span = Some(self.span()); - let name = self.into(); + let span = self.span(); + let name = Name::new_variable(self); let index = context .lookup(&name) @@ -148,13 +147,13 @@ impl Convert for Term { Self::Epsilon(e) => Ok(NamedExpression { name: None, expr: ast::Epsilon.into(), - span: Some(e.span), + span: e.span, }), Self::Ident(i) => i.convert(context), Self::Literal(l) => Ok(NamedExpression { name: None, expr: l.value().into(), - span: Some(l.span()), + span: l.span(), }), Self::Fix(f) => f.convert(context), Self::Parens(p) => p.convert(context), @@ -168,13 +167,13 @@ impl Convert for Call { let mut iter = self.0.into_iter(); let on = iter .next() - .ok_or_else(|| ConvertError::EmptyCall(span))? + .ok_or(ConvertError::EmptyCall(span))? .convert(context)?; let args = iter .map(|arg| arg.convert(context)) .collect::<Result<Vec<_>, _>>()?; if args.is_empty() { - Err(ConvertError::MissingArgs(span)) + Ok(on) } else { Ok(NamedExpression { name: None, @@ -194,10 +193,10 @@ impl Convert for Cat { fn convert_pair( pair: Pair<Call, Token![.]>, context: &mut Context, - ) -> Result<(NamedExpression, Option<Span>), ConvertError> { + ) -> Result<(NamedExpression, Span), ConvertError> { match pair { - Pair::Punctuated(t, p) => t.convert(context).map(|expr| (expr, Some(p.span))), - Pair::End(t) => t.convert(context).map(|expr| (expr, None)), + Pair::Punctuated(t, p) => t.convert(context).map(|expr| (expr, p.span)), + Pair::End(t) => t.convert(context).map(|expr| (expr, Span::call_site())), } } @@ -215,7 +214,7 @@ impl Convert for Cat { }) .peekable(); - if let Some(_) = rest.peek() { + if rest.peek().is_some() { Ok(NamedExpression { name: None, expr: ast::Cat { @@ -235,7 +234,8 @@ impl Convert for Labelled { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { let span = self.span(); let named = self.cat.convert(context)?; - let name = self.label.map(|l| l.label.into()).or(named.name); + let label = self.label.map(|l| Name::new_label(l.label)); + let name = Name::merge(label, named.name); Ok(NamedExpression { name, @@ -250,10 +250,10 @@ impl Convert for Alt { fn convert_pair( pair: Pair<Labelled, Token![|]>, context: &mut Context, - ) -> Result<(NamedExpression, Option<Span>), ConvertError> { + ) -> Result<(NamedExpression, Span), ConvertError> { match pair { - Pair::Punctuated(t, p) => t.convert(context).map(|expr| (expr, Some(p.span))), - Pair::End(t) => t.convert(context).map(|expr| (expr, None)), + Pair::Punctuated(t, p) => t.convert(context).map(|expr| (expr, p.span)), + Pair::End(t) => t.convert(context).map(|expr| (expr, Span::call_site())), } } @@ -271,7 +271,7 @@ impl Convert for Alt { }) .peekable(); - if let Some(_) = rest.peek() { + if rest.peek().is_some() { Ok(NamedExpression { name: None, expr: ast::Alt { @@ -290,7 +290,7 @@ impl Convert for Alt { impl Convert for Lambda { fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { let span = self.span(); - let mut args: Vec<_> = self.args.into_iter().map(Name::from).collect(); + let args: Vec<_> = self.args.into_iter().map(Name::new_variable).collect(); let expr = self.expr; let inner = context.with_variables(args.clone(), |ctx| expr.convert(ctx))?; Ok(NamedExpression { @@ -313,3 +313,62 @@ impl Convert for Expression { } } } + +impl Convert for GoalStatement { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + let span = self.span(); + let inner = self.expr.convert(context)?; + Ok(NamedExpression { + name: Name::merge(inner.name, Some(Name::new_variable("Ast".to_owned()))), + expr: inner.expr, + span, + }) + } +} + +impl Convert for LetStatement { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + let span = self.span(); + let bound = if self.args.is_empty() { + self.expr.convert(context)? + } else { + let args: Vec<_> = self.args.into_iter().map(Name::new_variable).collect(); + let expr = self.expr; + let inner = context.with_variables(args.clone(), |ctx| expr.convert(ctx))?; + NamedExpression { + name: None, + expr: ast::Lambda { + args, + inner: Box::new(inner), + } + .into(), + span, + } + }; + let name = Name::new_let(self.name); + context.push_variable(name.clone()); + let body = self.next.convert(context)?; + Ok(NamedExpression { + name: None, + expr: ast::Let { + name: name.clone(), + bound: Box::new(NamedExpression { + name: Some(name), + ..bound + }), + body: Box::new(body), + } + .into(), + span, + }) + } +} + +impl Convert for Statement { + fn convert(self, context: &mut Context) -> Result<NamedExpression, ConvertError> { + match self { + Self::Goal(g) => g.convert(context), + Self::Let(l) => l.convert(context), + } + } +} diff --git a/src/nibble/mod.rs b/src/nibble/mod.rs index dbb05b0..f5417db 100644 --- a/src/nibble/mod.rs +++ b/src/nibble/mod.rs @@ -2,21 +2,17 @@ pub mod convert; use std::fmt; -use proc_macro2::Span; +use proc_macro2::TokenStream; +use quote::{ToTokens, TokenStreamExt}; use syn::{ - bracketed, ext::IdentExt, parenthesized, parse::{Parse, ParseStream}, - punctuated::{Pair, Punctuated}, - token::{Bracket, Comma, Let, Match, Paren}, + punctuated::Punctuated, + token::{Let, Match, Paren}, LitStr, Token, }; -use crate::chomp::{Name, ast::{self, TopLevel}}; - -use convert::{Context, Convert, ConvertError}; - pub type Epsilon = Token![_]; pub type Ident = syn::Ident; @@ -24,60 +20,15 @@ pub type Ident = syn::Ident; pub type Literal = LitStr; #[derive(Clone)] -pub struct ArgList<T> { - paren_token: Paren, - args: Punctuated<T, Comma>, -} - -impl<T> ArgList<T> { - pub fn span(&self) -> Span { - self.paren_token.span - } - - pub fn len(&self) -> usize { - self.args.len() - } - - pub fn is_empty(&self) -> bool { - self.args.is_empty() - } -} - -impl<T> IntoIterator for ArgList<T> { - type Item = T; - - type IntoIter = <Punctuated<T, Comma> as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.args.into_iter() - } -} - -impl<T: Parse> Parse for ArgList<T> { - fn parse(input: ParseStream<'_>) -> syn::Result<Self> { - let args; - let paren_token = parenthesized!(args in input); - let args = args.call(Punctuated::parse_terminated)?; - Ok(Self { paren_token, args }) - } -} - -impl<T: fmt::Debug> fmt::Debug for ArgList<T> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "ArgList")?; - f.debug_list().entries(self.args.iter()).finish() - } -} - -#[derive(Clone)] pub struct Fix { bang_token: Token![!], pub expr: Box<Term>, } -impl Fix { - pub fn span(&self) -> Option<Span> { - self.bang_token.span.join(self.expr.span()?) +impl ToTokens for Fix { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.bang_token.to_tokens(tokens); + self.expr.to_tokens(tokens); } } @@ -101,6 +52,12 @@ pub struct ParenExpression { pub expr: Expression, } +impl ToTokens for ParenExpression { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.paren_token.surround(tokens, |tokens| self.expr.to_tokens(tokens)) + } +} + impl Parse for ParenExpression { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { let expr; @@ -127,14 +84,14 @@ pub enum Term { Parens(ParenExpression), } -impl Term { - pub fn span(&self) -> Option<Span> { +impl ToTokens for Term { + fn to_tokens(&self, tokens: &mut TokenStream) { match self { - Self::Epsilon(e) => Some(e.span), - Self::Ident(i) => Some(i.span()), - Self::Literal(l) => Some(l.span()), - Self::Fix(f) => f.span(), - Self::Parens(p) => Some(p.paren_token.span), + Self::Epsilon(e) => e.to_tokens(tokens), + Self::Ident(i) => i.to_tokens(tokens), + Self::Literal(l) => l.to_tokens(tokens), + Self::Fix(f) => f.to_tokens(tokens), + Self::Parens(p) => p.to_tokens(tokens), } } } @@ -174,18 +131,15 @@ impl fmt::Debug for Term { #[derive(Clone, Debug)] pub struct Call(pub Vec<Term>); -impl Call { - pub fn span(&self) -> Option<Span> { - let mut iter = self.0.iter(); - let first = iter.next()?.span()?; - iter.try_fold(first, |span, t| t.span().and_then(|s| span.join(s))) +impl ToTokens for Call { + fn to_tokens(&self, tokens: &mut TokenStream) { + tokens.append_all(&self.0) } } impl Parse for Call { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { - let mut out = Vec::new(); - out.push(input.parse()?); + let mut out = vec![input.parse()?]; loop { let lookahead = input.lookahead1(); if lookahead.peek(Token![_]) @@ -207,34 +161,22 @@ impl Parse for Call { #[derive(Clone)] pub struct Cat(pub Punctuated<Call, Token![.]>); -impl Parse for Cat { - fn parse(input: ParseStream<'_>) -> syn::Result<Self> { - input.call(Punctuated::parse_separated_nonempty).map(Self) +impl ToTokens for Cat { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.0.to_tokens(tokens) } } -impl Cat { - pub fn span(&self) -> Option<Span> { - let mut iter = self.0.pairs(); - let span = match iter.next()? { - Pair::Punctuated(t, p) => t.span().and_then(|s| s.join(p.span)), - Pair::End(t) => t.span(), - }?; - - iter.try_fold(span, |span, pair| match pair { - Pair::Punctuated(t, p) => t - .span() - .and_then(|s| span.join(s)) - .and_then(|s| s.join(p.span)), - Pair::End(t) => t.span().and_then(|s| span.join(s)), - }) +impl Parse for Cat { + fn parse(input: ParseStream<'_>) -> syn::Result<Self> { + input.call(Punctuated::parse_separated_nonempty).map(Self) } } impl fmt::Debug for Cat { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Cat")?; - f.debug_list().entries(self.0.iter()).finish() + f.debug_list().entries(&self.0).finish() } } @@ -244,9 +186,10 @@ pub struct Label { pub label: Ident, } -impl Label { - pub fn span(&self) -> Option<Span> { - self.colon_tok.span.join(self.label.span()) +impl ToTokens for Label { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.colon_tok.to_tokens(tokens); + self.label.to_tokens(tokens); } } @@ -270,13 +213,12 @@ pub struct Labelled { pub label: Option<Label>, } -impl Labelled { - pub fn span(&self) -> Option<Span> { - self.cat.span().and_then(|s| { - self.label - .as_ref() - .and_then(|l| l.span().and_then(|t| s.join(t))) - }) +impl ToTokens for Labelled { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.cat.to_tokens(tokens); + if let Some(label) = &self.label { + label.to_tokens(tokens); + } } } @@ -295,21 +237,9 @@ impl Parse for Labelled { #[derive(Clone)] pub struct Alt(pub Punctuated<Labelled, Token![|]>); -impl Alt { - pub fn span(&self) -> Option<Span> { - let mut iter = self.0.pairs(); - let span = match iter.next()? { - Pair::Punctuated(t, p) => t.span().and_then(|s| s.join(p.span)), - Pair::End(t) => t.span(), - }?; - - iter.try_fold(span, |span, pair| match pair { - Pair::Punctuated(t, p) => t - .span() - .and_then(|s| span.join(s)) - .and_then(|s| s.join(p.span)), - Pair::End(t) => t.span().and_then(|s| span.join(s)), - }) +impl ToTokens for Alt { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.0.to_tokens(tokens) } } @@ -322,27 +252,40 @@ impl Parse for Alt { impl fmt::Debug for Alt { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Alt")?; - f.debug_list().entries(self.0.iter()).finish() + f.debug_list().entries(&self.0).finish() } } #[derive(Clone)] pub struct Lambda { slash_tok_left: Token![/], - pub args: ArgList<Ident>, + pub args: Vec<Ident>, slash_tok_right: Token![/], pub expr: Alt, } -impl Lambda { - pub fn span(&self) -> Option<Span> { - self.slash_tok_left.span.join(self.expr.span()?) +impl ToTokens for Lambda { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.slash_tok_left.to_tokens(tokens); + tokens.append_all(&self.args); + self.slash_tok_right.to_tokens(tokens); + self.expr.to_tokens(tokens); } } impl Parse for Lambda { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { let slash_tok_left = input.parse()?; - let args = input.parse()?; + let mut args = Vec::new(); + loop { + args.push(input.parse()?); + let lookahead = input.lookahead1(); + + if lookahead.peek(Token![/]) { + break; + } else if !lookahead.peek(Ident::peek_any) { + return Err(lookahead.error()); + } + } let slash_tok_right = input.parse()?; let expr = input.parse()?; Ok(Self { @@ -369,6 +312,15 @@ pub enum Expression { Lambda(Lambda), } +impl ToTokens for Expression { + fn to_tokens(&self, tokens: &mut TokenStream) { + match self { + Self::Alt(a) => a.to_tokens(tokens), + Self::Lambda(l) => l.to_tokens(tokens), + } + } +} + impl Parse for Expression { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { if input.peek(Token![/]) { @@ -386,6 +338,14 @@ pub struct GoalStatement { semi_token: Token![;], } +impl ToTokens for GoalStatement { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.match_token.to_tokens(tokens); + self.expr.to_tokens(tokens); + self.semi_token.to_tokens(tokens); + } +} + impl Parse for GoalStatement { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { let match_token = input.parse()?; @@ -412,22 +372,40 @@ impl fmt::Debug for GoalStatement { pub struct LetStatement { let_token: Token![let], name: Ident, - args: Option<ArgList<Ident>>, + args: Vec<Ident>, eq_token: Token![=], expr: Expression, semi_token: Token![;], next: Box<Statement>, } +impl ToTokens for LetStatement { + fn to_tokens(&self, tokens: &mut TokenStream) { + self.let_token.to_tokens(tokens); + self.name.to_tokens(tokens); + tokens.append_all(&self.args); + self.eq_token.to_tokens(tokens); + self.expr.to_tokens(tokens); + self.semi_token.to_tokens(tokens); + self.next.to_tokens(tokens); + } +} + impl Parse for LetStatement { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { let let_token = input.parse()?; let name = input.call(Ident::parse_any)?; - let args = if input.peek(Paren) { - Some(input.parse()?) - } else { - None - }; + let mut args = Vec::new(); + loop { + let lookahead = input.lookahead1(); + if lookahead.peek(Token![=]) { + break; + } else if lookahead.peek(Ident::peek_any) { + args.push(input.parse()?); + } else { + return Err(lookahead.error()); + } + } let eq_token = input.parse()?; let expr = input.parse()?; let semi_token = input.parse()?; @@ -462,43 +440,18 @@ pub enum Statement { Let(LetStatement), } -impl Statement { - pub fn convert(self) -> Result<TopLevel, ConvertError> { - let mut stmt = self; - let mut context = Context::new(); - let mut name_val = Vec::new(); - while let Self::Let(let_stmt) = stmt { - let mut val = match let_stmt.args { - Some(args) => { - todo!() - } - None => let_stmt.expr.convert(&mut context), - }?; - let name: Name = let_stmt.name.into(); - val.name = val.name.or_else(|| Some(name.clone())); - context.push_variable(name.clone()); - name_val.push((name, val)); - stmt = *let_stmt.next; +impl ToTokens for Statement { + fn to_tokens(&self, tokens: &mut TokenStream) { + match self { + Self::Goal(g) => g.to_tokens(tokens), + Self::Let(l) => l.to_tokens(tokens), } - - let goal = match stmt { - Statement::Goal(goal) => TopLevel::Goal(goal.expr.convert(&mut context)?), - Statement::Let(_) => unreachable!(), - }; - - Ok(name_val.into_iter().rfold(goal, |inner, (name, val)| { - TopLevel::Let(ast::Let { - name, - val, - inner: Box::new(inner), - }) - })) } } impl Parse for Statement { fn parse(input: ParseStream<'_>) -> syn::Result<Self> { - let mut lookahead = input.lookahead1(); + let lookahead = input.lookahead1(); if lookahead.peek(Let) { input.parse().map(Self::Let) diff --git a/tests/full/main.rs b/tests/full/main.rs new file mode 100644 index 0000000..95a1f60 --- /dev/null +++ b/tests/full/main.rs @@ -0,0 +1,61 @@ +use std::error::Error; + +use chomp::{ + chomp::{ + ast::substitute::Reduce, + typed::{ + context::Context, + lower::{Backend, GenerateCode}, + TypeInfer, + }, + visit::Visitable, + }, + lower::RustBackend, + nibble::{ + convert::{self, Convert}, + Statement, + }, +}; +use proc_macro2::{Span, TokenStream}; + +fn chomp(input: &str) -> Result<TokenStream, Box<dyn Error>> { + syn::parse_str::<Statement>(&input) + .map_err(|e| Box::new(e) as Box<dyn Error>) + .and_then(|nibble: Statement| { + nibble + .convert(&mut convert::Context::default()) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) + .and_then(|expr| { + expr.fold(&mut Reduce) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) + .and_then(|term| { + let mut context = Context::default(); + term.fold(&mut TypeInfer { + context: &mut context, + }) + .map_err(|e| Box::new(e) as Box<dyn Error>) + }) + .map(|typed| { + let mut backend = RustBackend::default(); + let id = typed.gen(&mut backend); + backend.emit_code(None, Span::call_site(), id) + }) +} + +macro_rules! compile { + ($name:ident, $file:literal) => { + #[test] + fn $name() { + let input = include_str!($file); + chomp(input).unwrap(); + } + }; +} + +compile!(compile_sheep, "nibble/sheep.nb"); +compile!(compile_ratata, "nibble/ratata.nb"); +compile!(compile_regex, "nibble/regex.nb"); +compile!(compile_regex_fix, "nibble/regex_fix.nb"); +compile!(compile_nibble, "nibble/nibble_exp.nb"); diff --git a/tests/full/nibble/nibble_exp.nb b/tests/full/nibble/nibble_exp.nb new file mode 100644 index 0000000..67f2be1 --- /dev/null +++ b/tests/full/nibble/nibble_exp.nb @@ -0,0 +1,42 @@ +let opt x = _ | x; +let plus x = !(/plus/ x . opt plus); +let star x = !(/star/ opt (x . star)); + +let Pattern_Whitespace = "\n"|" "; + +let XID_Start = + "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | + "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | + "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | + "y" | "z" | + "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | + "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | + "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | + "Y" | "Z" ; +let XID_Continue = + XID_Start | "_" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ; + +let literal_char = XID_Continue; + +let ws = star Pattern_Whitespace; + +let punctuated x p = !(/rec/ x . opt (p . ws . rec)); +let list x = "(" . ws . !(/rec/ x . opt ("," . ws . opt rec)) . ")"; + +let epsilon = "_"; +let ident = XID_Start . star XID_Continue; +let literal = "\"" . plus literal_char . "\""; +let parens expr = "(" . ws . expr . ")"; +let fix expr = "[" . ws . ident . ws . "]" . ws . parens expr; + +let term expr = + epsilon . ws + | literal . ws + | parens expr . ws + | fix expr . ws + | ident . ws . opt (list expr . ws) + ; + +let cat expr = punctuated (term expr) "."; +let alt expr = punctuated (cat expr) "|"; +match !alt;
\ No newline at end of file diff --git a/tests/full/nibble/ratata.nb b/tests/full/nibble/ratata.nb new file mode 100644 index 0000000..feeccca --- /dev/null +++ b/tests/full/nibble/ratata.nb @@ -0,0 +1,3 @@ +let opt x = _ | x; +let plus x = !(/rec/ x . opt rec); +match plus (("r" | "t") . "a"); diff --git a/tests/full/nibble/regex.nb b/tests/full/nibble/regex.nb new file mode 100644 index 0000000..4aa98a7 --- /dev/null +++ b/tests/full/nibble/regex.nb @@ -0,0 +1,5 @@ +let opt x = _ | x; +let plus x = !(/plus/ x . opt plus); +let star x = !(/star/ opt (x . star)); + +match plus "a" . star "b"; diff --git a/tests/full/nibble/regex_fix.nb b/tests/full/nibble/regex_fix.nb new file mode 100644 index 0000000..54daf61 --- /dev/null +++ b/tests/full/nibble/regex_fix.nb @@ -0,0 +1,4 @@ +let opt x = _ | x; +let ws = !(/star/ opt (" " . star)); + +match !(/rec/ "a" . opt ("." . ws . rec)); diff --git a/tests/full/nibble/sheep.nb b/tests/full/nibble/sheep.nb new file mode 100644 index 0000000..922ae84 --- /dev/null +++ b/tests/full/nibble/sheep.nb @@ -0,0 +1,3 @@ +let opt x = _ | x; +let plus x = !(/rec/ x . opt rec); +match "ba" . plus "a"; |