How to constrain the number of following backslashes to an odd number? to an even number?

时间:2017-11-08 22:09:07

标签: alloy

next is a binary relation.

This string:

A\\\,B

is modeled by this next table:

The "next" table which models <code>A\\\,B</code>

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 个答案:

答案 0 :(得分:0)

我想知道你是否在适当的抽象层面对其进行建模。是否有必要考虑反斜杠序列的结构?如果你有两个令牌,双反斜杠和反斜杠 - 逗号,并且只是说必须使用反斜杠 - 逗号,之后是双反斜杠,然后是非反斜杠,该怎么办?