我要运行“计算机科学中的逻辑”一书的一个例子,Michael Huth和Mark Ryan。该示例在2.7.3节中,它是下一个:
module PDS
open std/ord -- opens specification template for linear order
sig Component {
name: Name,
main: option Service,
export: set Service,
import: set Service,
version: Number
}{ no import & export }
sig PDS {
components: set Component,
schedule: components -> Service ->? components,
requires: components -> components
}{ components.import in components.export }
fact SoundPDSs {
all P : PDS |
all c : components, s : Service | --1
let c' = c.schedule[s] {
(some c' iff s in c.import) && (some c' => s in c'.export)
}
all c : components | c.requieres = c.schedule[Service] --2
}
sig Name, Number, Service {}
fun AddComponent(P, P': PDS, c: Component) {
not c in P.components
P'.components = P.components + c
} run AddComponent for 3 but 2 PDS
fun RemoveComponent(P, P' : PDS, c: Component) {
c in P.components
P'.components = P.components - c
} run RemoveComponents for 3 but 2 PDS
fun HighestVersionPolicy(P: PDS) {
all s : Service, c : components, c' : c.schedule[s],
c'' : components - c' {
s in c''.export && c''.name = c'.name => c''.version in c'version.^(Ord[Number].prev)
}
} run HighestVersionPolicy for 3 but 1 PDS
fun AGuideSimulation(P, P', P'' : PDS, c1, c2 : Component) {
AddComponent(P, P', c1) RemoveComponent(P, P'', c2)
HighestVersionPolicy(P) HigjestVersionPolicy(P') HighestVersionPolicy(P'')
} run AGuideSimulation for 3
assert AddingIsFunctionalForPDSs {
all P, P', P'' : PDS, c : Component {
AddComponent(P, P', c) && AddComponent(P, P'', c) => P' = P''
}
}
check AddingIsFunctionalForPDSs for 3
我要在麻省理工学院的合金分析器(http://alloy.mit.edu/alloy/)上运行它,当我执行此代码时出现以下错误:
第7行第15行的语法错误: 这里可以显示1个可能的令牌: }
我搜索了一些参考书,论坛......我找不到有用的东西。如果有人使用这个工具并知道如何解决这个问题,我将非常感激。
提前致谢。
答案 0 :(得分:3)
你的主要问题是Huth / Ryan书的第二版似乎是在2004年出版并且使用(毫不奇怪)合金分析仪当时接受的语法,这也是(不出所料)不完全的与Alloy Analyzer当前版本接受的语法相同。
因此,要在当前版本的分析器中运行此功能,您将必须了解(a)他们想要说的内容(b)他们试图说出的当时的Alloy语法,以及(c)当前的Alloy语法,足以将模型转换为当前语法。 (或者找到已经完成此操作的人。)幸运的是,Huth和Ryan详细解释了他们使用的Alloy语法,因此对于熟悉Alloy 4的人来说,将模型转化为Alloy并不困难。 4语法。
祝你好运![后记] 关于你的任务的目标是让你熟悉合金分析仪的理论,而不是通过要求旧合金的翻译让你陷入困境在新的Alloy语法的语法中,我将Huth / Ryan PDS模型粗略地翻译成Alloy 4语法,并附有一些散布的注释。 (我说'粗糙'因为我没有花很多时间在上面,我可能已经错过了一些细微差别,特别是在谓词HighestVersionPolicy中,作者有点棘手。)如果你的任务的目标正是迫使你在语法丛林中战斗,只有你的本土聪明才能用作砍刀,然后我为搞乱这种经历而道歉。
在模块的顶部,主要的变化是调用排序库模块的方式。
module PDS
open util/ordering[Number]
在组件中,关键字'选项'被当前关键词“孤独”所取代,我已经转录了一些Huth和Ryan的评论,试图帮助自己了解更好的情况。
sig Component {
name: Name, // name of the component
main: lone Service, // component may have a 'main' service
export: set Service, // services the component exports
import: set Service, // services the component imports
version: Number // version number of the component
}{
no import & export // imports and exports are disjoint
// sets of services
}
在PDS的签名中,主要变化是对基数语法的更改:->?
变为-> lone
。
// Package Dependency System
// components is the set of Component in this PDS
// schedule assigns to each component in the PDS
// and any of its import services
// a component in the PDS that provides that service
// (see SoundPDSs, below)
// requires expresses the component dependencies
// entailed by the schedule
sig PDS {
components: set Component,
schedule: components -> Service -> lone components,
// any component / Service pair maps to at most
// one component
requires: components -> components
}{
// for every component in the system,
// the services it imports are supplied (exported)
// by some (other) component in the system
components.import in components.export
}
在SoundPDSs中,作者使用with P
构造,我不记得在使用的Alloy I版本中看到过。{1}}构造。所以我把它拿出来,为了清晰起见,重新表达了一些表达,因为作者解释清晰度是使用with P
结构的主要动机。确保你理解Alloy的盒子符号以及为什么P.schedule [c] [s]是另一种编写c。(P.schedule)[s]或s的方式,这是值得的。角(P.schedule))。
fact SoundPDSs {
all P : PDS | {
all c : P.components, s : Service |
let c' = P.schedule[c][s] {
(some c' iff s in c.import)
// c and s require c' only iff c imports s
&&
(some c' => s in c'.export)
// c and s require c' only if c' exports s
}
all c : P.components | P.requires[c]= P.schedule[c][Service]
// c requires precisely those components
// that schedule says c depends on for some service
}
}
sig Name, Number, Service {}
从现在开始的重大变化是,Huth和Ryan使用fun
来定义各种属性,其中Alloy 4使用pred
- 关键字fun
仍然合法,但它意味着一个函数(一个表达式,当被计算时返回一个值,而不是一个布尔值)而不是一个谓词。
pred AddComponent(P, P': PDS, c: Component) {
not c in P.components
P'.components = P.components + c
} run AddComponent for 3 but 2 PDS
pred RemoveComponent(P, P' : PDS, c: Component) {
c in P.components
P'.components = P.components - c
} run RemoveComponent for 3 but 2 PDS
在HighestVersionPolicy中,我再次引入了框符号,试图让表达更清晰。请注意,此处未定义prev
- 它是模块顶部导入指令(open ...
)导入的关系之一,来自库模块以进行排序。
pred HighestVersionPolicy(P: PDS) {
all s : Service,
c : P.components,
c' : P.schedule[c][s],
c'' : P.components - c' {
s in c''.export && c''.name = c'.name
=>
c''.version in ^prev[c'.version]
}
} run HighestVersionPolicy for 3 but 1 PDS
pred AGuideSimulation(P, P', P'' : PDS, c1, c2 : Component) {
AddComponent[P, P', c1]
RemoveComponent[P, P'', c2]
HighestVersionPolicy[P]
HighestVersionPolicy[P']
HighestVersionPolicy[P'']
} run AGuideSimulation for 3
assert AddingIsFunctionalForPDSs {
all P, P', P'' : PDS, c : Component {
AddComponent[P, P', c] && AddComponent[P, P'', c]
=> P' = P''
}
}
check AddingIsFunctionalForPDSs for 3
version of their model given by Huth and Ryan on the web并不包含他们在文中描述的StructurallyEqual谓词;我添加它以帮助确保我的模型的翻译工作。
pred StructurallyEqual(P, P' : PDS) {
P.components = P'.components
P.schedule = P'.schedule
P.requires = P'.requires
}
run StructurallyEqual for 2
同样地,他们没有包含对AddingIsStructurallyFunctional的修复 - 意图可能是学生在Alloy中动态完成的。
assert AddingIsStructurallyFunctionalForPDSs {
all P, P', P'' : PDS, c : Component {
AddComponent[P, P', c] && AddComponent[P, P'', c]
=>
StructurallyEqual[P',P'']
}
}
check AddingIsStructurallyFunctionalForPDSs for 3