matthijsr / til-vhdl

A prototype toolchain for demonstrating and exploring an intermediate representation for defining components using the Tydi interface specification.
Apache License 2.0
3 stars 1 forks source link

Order of operations in generic parameter values #127

Closed matthijsr closed 1 year ago

matthijsr commented 1 year ago

6 - 2 * 3 + 4 / 2 - 1 + 2

Gets interpreted as...

6 - ( 2 * ( 3 + ( 4 / ( ( 2 - 1 ) + 2 ) ) ) ) (Albeit without explicit parentheses)

... by the parser.

Fix this in the parser, or the query system, or both.

The order of operations is:

  1. Multiplication, division or modulo (remainder)
  2. Sum or subtraction
  3. Left to right
matthijsr commented 1 year ago

For clarity:

6 - 2 * 3 + 4 / 2 - 1 + 2 \= 6 - (2 * 3) + (4 / 2) - 1 + 2 \= 3

While 6 - ( 2 * ( 3 + ( 4 / ( ( 2 - 1 ) + 2 ) ) ) ) \= -8/3

matthijsr commented 1 year ago

What's interesting is that the order of operations of equivalent operations is respected (i.e., it's folded left), which suggests there's probably a mistake in the parser configuration w.r.t. how combinations of non-equal operations are folded.