问题
next
is a binary relation.
This string:
A\\\,B
is modeled by this next
table:
Consider the first column of the first row of the table. It's value is A. From A we can get to Backslash0, then Backslash1, then Backslash2, then Backslash3, then Comma0, and then B. So, the number of Backslashes between A and the first reachable non-backslash value (which in this case is Comma0) is an odd number (3). Yea! That is what I want. If the first reachable non-backslash value was a non-comma, then the number of intervening Backslashes must be even (0, 2, 4, ...).
How do I express this constraint in Alloy:
For each non-backslash value c in the first column of the next table: If the first non-backslash value c' reachable from c is a comma, then the number of backslashes between c and c' must be odd (1, 3, 5, ...). If the first non-backslash value c' reachable from c is a non-comma, then the number of backslashes between c and c' must be even (0, 2, 4, ...).
回答1:
I wonder if you're modeling this at the right level of abstraction. Is it necessary to consider the structure of the backslash sequence? What if you had two tokens, the double-backslash and backslash-comma, and just said required backslash-comma to be preceded by double-backslash and followed by non-backslash?
来源:https://stackoverflow.com/questions/47190547/how-to-constrain-the-number-of-following-backslashes-to-an-odd-number-to-an-eve