Question

I have the following Alloy model and I'm not sure how to convert it to the Alloy Java API.

sig A {
  B: Int
}

I know we can use A.addField("B", Expr) to add the attribute, but what should I put in the Expr parameter to make it represents Ints?

Thanks

Was it helpful?

Solution

It is much easier to parse the entire Alloy model from string instead of creating AST manually. See this post for an example. That example uses

CompUtil.parseEverything_fromFile(..., <file_name>)

but you can replace that with

CompUtil.parseOneModule_fromString("sig A{ B: Int}")

to parse directly from string (note that the return type in the latter case is List<Command>, and not CompModule like in the linked example, but that shouldn't be a problem for you).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top