Boolean Guard Language
ArchStudio 4

The Boolean Guard Language

Boolean guards are a supported product-line guard language in the ArchStudio toolset. (Currently Boolean guards are the only such language, although other guard languages could be used by extending xADL 2.0 and providing appropriate tools). Boolean guards are used in modeling product-line architectures. Boolean guards are boolean expressions that serve two purposes:

  1. Optional Elements: Optional elements are accompanied by Boolean guards; if the guard expression evaluates to true, the element is included in the architecture. If the guards expression evaluates to false, the element is removed.
  2. Variant Elements: Each possible variant of an element is assigned an exclusive Boolean guard (that is, no two variants' guards should simultaneously evaluate to true under any circumstance). The variant whose guard expression does evaluate to true is included in the architecture, the rest are excluded.

Boolean expressions in the Boolean guard language are syntactically similar to traditional Boolean expressions in programming languages such as C, C++, and Java. Variables in the equation are bound to values at evaluation-time. So, an expression such as:

platform == "Macintosh"

is valid without any previous or external declaration of the variable platform. The variable will be bound to a value in the tool that evaluates the expression; in ArchStudio 3 this tool is traditionally the Selector (driven graphically by the SelectorDriver).

There are 3 valid types for the values of each variable: string, date, and double. Variables are indicated by standard C/C++/Java style names, such as num_of_processors or hasDisk. Constants of each type are denoted as follows:

The following comparison operators are available:

==equal to
!=not equal to
>greater than
>=greater than or equal to
<less than
<=less than or equal to

In comparisons, the left hand operator must be a variable and the right hand operator may be either a variable or a constant (string, date, or double). For example:

/* Is the speed over the number 65? */
speed >= 65

/* Is the alarm equal to the value stored in the
   variable timerDate? */
alarm == timerDate

For convenience, the language also offers in-set and in-range operators:

@{ ... }in-set
@[a, b]in-range

The left hand side of these operators must be a variable. For in-set, any number of variables or constant values are allowed between the braces ({ }), each separated by a comma.

For in-range, a single lower and upper bound are specified in the brackets ([ ]), separated by a comma.


/* Is the temperature between 10 and 40? */
temperature @[10, 40]

/* Is the ticket either a child, adult,
   or senior? */
ticket @{"child", "adult", "senior"}

Finally, expressions can be joined by conjunction operators and and or:


These two operators connect boolean expressions together. For example:

(speed >= 65) && (temperature @[10, 40])
(ticket @{"child", "adult", "senior"}) || (age <= 5)

The Boolean Guard Language in BNF

That summarizes the language. For the technically inclined, or those who want to build their own parser, the BNF for the language follows:

<BooleanGuard> ::= <BooleanExp>
<BooleanExp> ::= <And> | <Or> | <Not> |
<GreaterThanOrEquals> |
    <LessThan> | <LessThanOrEquals> | <Equals> |
    <NotEquals> | <InSet> | <InRange> |
    <Bool> | <Paren>
<And> ::= <BooleanExp> && <BooleanExp>
<Or> ::= <BooleanExp> || <BooleanExp>
<Not> ::= !<BooleanExp>
<GreaterThan> ::= <LeftOperand> > <RightOperand>
<GreaterThanOrEquals> ::= <LeftOperand> >= <RightOperand>
<LessThan> ::= <LeftOperand> < <RightOperand>
<LessThanOrEquals> ::= <LeftOperand> <= <RightOperand>
<Equals> ::= <LeftOperand> == <RightOperand>
<NotEquals> ::= <LeftOperand> != <RightOperand>
<InSet> ::= <LeftOperand> @{ <Set> }
<InRange> ::= <LeftOperand> @[ <RightOperand>, <RightOperand> ]
<Paren> ::= ( <BooleanExp> )
<Set> ::= <RightOperand> | <RightOperand>, <Set>

<LeftOperand> ::= Variable
<RightOperand> ::= Variable | Value
<Bool> ::= true | false