From 17d21d2d9c7c421202cd692e427ab13bfd01bf60 Mon Sep 17 00:00:00 2001 From: Zhuoxun Yang Date: Tue, 21 Nov 2023 22:05:41 +0800 Subject: [PATCH] expr: check prefix operation --- src/uu/expr/src/syntax_tree.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/uu/expr/src/syntax_tree.rs b/src/uu/expr/src/syntax_tree.rs index c55fb0bdc..119f325a3 100644 --- a/src/uu/expr/src/syntax_tree.rs +++ b/src/uu/expr/src/syntax_tree.rs @@ -332,8 +332,12 @@ fn push_token_to_either_stack( } Token::PrefixOp { .. } | Token::ParOpen => { - op_stack.push((token_idx, token.clone())); - Ok(()) + if out_stack.is_empty() { + op_stack.push((token_idx, token.clone())); + Ok(()) + } else { + Err(String::from("syntax error (operation should be prefix)")) + } } Token::ParClose => move_till_match_paren(out_stack, op_stack),