Expressions in SADL

Last revised 4/27/2021. Contact us.

Introduction

The SADL grammar has an expression language that is used in Rule, Ask, Graph, Update, Test, Explain, and Equation and External Equations, as well as  Expr statements. This grammar combines the often-encountered junction, comparison, negation, and mathematical expressions with graph patterns and list operations. The result is a rich expression language described herein.

Expression Precedence

The SADL expression grammar can be thought of as a hierarchy of operations. The precedence of operations determines the order, in the absence of parentheses, in which multiple operations are carried out. For example, computing the value of this expression depends upon the precedence of the operations of addition and multiplication.

2 + 4 * 5 + 6 = ?

Since multiplication has precedence over addition,

2 + 4 * 5 + 6 = 2 + 20 + 6 = 28

However, if addition had precedence over multiplication, the answer would be 66.

As with many expression grammars, the SADL grammar uses parentheses to override precedence defaults. So, one could write the expression

(2 + 4) * (5 + 6)

which would evaluate to 66. The use of parentheses shows up as the PrimaryExpression "embedded expression" in the precedence hierarchy below.

From lowest precedence to highest precedence, the operations supported by the SADL grammar include the following.

where PrimaryExpression can be one of

Notice that the PropOfSubject operation has a fairly high precedence. This allows one to write expressions such as the following without parentheses, since the PropOfSubject operation has higher precedence than math operations such as multiplication.

area of a Rectangle = height of the Rectangle * width of the Rectangle

Using Expr Statements to Validate Expressions

The Expr Statement in the SADL grammar is used only to provide validation of expressions using the SADL expression grammar in the development environment. The keyword Expr followed by a colon can be followed by any valid SADL expression followed by a period (end of statement). An information marker in the editor will contain the translation of the expression to the Intermediate Form, a reasoner/translator independent functional expression language that is ordinarily passed to the selected translator for translation to the target rule or query language. In the case of Expr Statements, the final result is the display of the Intermediate Form to the user in the information marker as a means of feedback to the user concerning the meaning of the expression.

Here are three examples of Expr Statements along with the Info Marker content for each.


Note that the SADL expression grammar is somewhat disjoint from the grammar for declaring classes, instances, properties, and property restrictions. Only expressions using the SADL expression grammar are valid in an Expr Statement.