Alloy 合金错误签名

Alloy 合金错误签名,alloy,Alloy,我要举一个《计算机科学中的逻辑》一书的例子,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,

我要举一个《计算机科学中的逻辑》一书的例子,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
我必须在麻省理工学院的alloy analizer()上运行它,当我执行此代码时,出现以下错误:

第7行第15列出现语法错误: 此处可能出现1个标记: }

我搜索了一些参考书,论坛。。。我没有发现有用的东西。如果有人使用过这个工具,并且知道如何解决这个问题,我将非常感激


提前感谢。

您的主要问题是Huth/Ryan书的第二版似乎已于2004年出版,并且使用了合金分析仪当时接受的语法(毫不奇怪),这与合金分析仪当前版本接受的语法并不完全相同

因此,要在当前版本的分析器中运行此功能,您必须理解(a)他们试图表达的内容(b)他们试图表达的当前合金语法,以及(c)当前合金语法,足以将模型转换为当前语法。幸运的是,Huth和Ryan详细解释了他们使用的Alloy语法,因此对于熟悉Alloy 4的人来说,将模型转换为Alloy 4语法并不难

祝你好运

[Postscript]基于这样一种理论,即你的作业目标是让你熟悉Alloy Analyzer,而不是要求你将旧的Alloy语法转换为新的Alloy语法,因此我将Huth/Ryan PDS模型的粗略翻译添加到Alloy 4语法中,夹杂着一些评论。(我之所以说“粗糙”,是因为我没有花太多时间在它上面,而且我可能错过了一些细微差别,特别是在谓词最高级版本策略中,作者变得有点棘手。)如果你的作业的目标就是迫使你在语法的丛林中奋力拼搏,而你的本领只能用作弯刀,那么,我很抱歉把这次经历搞砸了

在模块顶部,主要更改是调用ordering library模块的方式

module PDS

open util/ordering[Number]
在组件中,关键字“option”被当前关键字“lone”替换,我转录了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的sig中,主要的更改还是对基数语法的更改:
->?
变为
->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 
}
事实上,作者使用了一个带有p的
结构,我不记得在我使用过的合金版本中见过这种结构。所以我把它拿出来,为了清晰起见,重新表述了一些表达式,因为作者解释说,清晰是他们将
与P
结构结合使用的主要动机。确保您理解Alloy的方框符号,以及为什么P.schedule[c][s]是c.(P.schedule)[s]或s.(c.(P.schedule))的另一种书写方式,这是非常值得的

从这里开始,最大的变化是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
不包括他们在文本中描述的结构相等的谓词;我添加它是为了确保我对模型的翻译有效

pred StructurallyEqual(P, P' : PDS) {
  P.components = P'.components
  P.schedule = P'.schedule
  P.requires = P'.requires
}

run StructurallyEqual for 2
类似地,它们也不包括对添加结构功能的修复——其目的大概是让学生在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

非常感谢你。我是个逻辑新手,一开始有点复杂,所以我会听从你的建议。再次感谢你,哇!干得好,迈克尔!
assert AddingIsStructurallyFunctionalForPDSs {
    all P, P', P'' : PDS, c : Component {
        AddComponent[P, P', c] && AddComponent[P, P'', c] 
        => 
        StructurallyEqual[P',P'']
    }
}
check AddingIsStructurallyFunctionalForPDSs for 3