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

不打扰是莪最后的温柔 提交于 2019-12-24 07:47:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!