Skip to content

Commit 22d967d

Browse files
author
Johannes Zeppenfeld
committed
Fix precedence of binary times operator
1 parent 6f285aa commit 22d967d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

vhdl_lang/src/syntax/expression.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ fn kind_to_binary_op(kind: Kind) -> Option<(Binary, usize)> {
5353
Plus => Some((Binary::Plus, 5)),
5454
Minus => Some((Binary::Minus, 5)),
5555
Concat => Some((Binary::Concat, 5)),
56-
Times => Some((Binary::Times, 5)),
5756

57+
Times => Some((Binary::Times, 7)),
5858
Div => Some((Binary::Div, 7)),
5959
Mod => Some((Binary::Mod, 7)),
6060
Rem => Some((Binary::Rem, 7)),
@@ -1140,6 +1140,13 @@ mod tests {
11401140

11411141
assert_expression_is("1-2-3", "((Integer(1) Minus Integer(2)) Minus Integer(3))");
11421142

1143+
assert_expression_is("1+2*3", "(Integer(1) Plus (Integer(2) Times Integer(3)))");
1144+
1145+
assert_expression_is("(1+2)*3", "((Integer(1) Plus Integer(2)) Times Integer(3))");
1146+
1147+
// Multiplication has precedence over negation.
1148+
assert_expression_is("-1 * 2", "(Minus (Integer(1) Times Integer(2)))");
1149+
11431150
assert_expression_is("not 1 + 2", "((Not Integer(1)) Plus Integer(2))");
11441151

11451152
assert_expression_is("abs not 1 + 2", "((Abs (Not Integer(1))) Plus Integer(2))");

0 commit comments

Comments
 (0)