Grammar specification

The ILOG® Rule Language (IRL) defines a lexical grammar.

Note:

A bullet (•) before a grammar rule indicates that the terminal symbol in the rule is detailed in IRL keywords.

Table 1. General form of an IRL program. Table shows the general form of an IRL program.
General form of an IRL program
 

RuleSetDefinition :

ImportOrUseDeclarationopt RulesetPropertyDefinitionopt HierarchicalPropertyDeclarationopt PropertyTypingDeclarationopt RuleOverridingDeclarationopt VariableDeclarationopt PackageListopt

Package definition
 

PackageList :

Package PackageListopt

 

Package :

PackageDefinition

PackageContent

•

PackageDefinition :

package Identifier

{ ImportOrUseDeclarationopt VariableDeclarationopt

PackageContentList }

 

PackageContentList:

PackageContent PackageContentListopt

•

PackageContent:

FunctionDefinitionListopt

RuleDefinitionListopt

TaskDefinitionListopt

Import or use declaration
 

ImportOrUseDeclaration:

SingleImportOrUseDeclaration

ImportOrUseOnDemandDeclaration

•

SingleImportOrUseDeclaration:

ImportOrUseKeyword PackageName. *;

•

ImportOrUseOnDemandDeclaration :

ImportOrUseKeyword TypeName;

 

ImportOrUseKeyword: one of

import

use

Ruleset property definition
 

RulesetPropertyDefinition :

ruleset identifier

{ PropertyListopt RulesetParameterListopt HasherDefinitionListopt

InstanceDefinitionListopt }

 

PropertyList:

PropertyEntry PropertyListopt

•

PropertyEntry:

property PropertyName = PropertyValue;

 

RulesetParameterList:

RulesetParameter RulesetParameterListopt

 

RulesetParameter:

InRulesetParameter InOutRulesetParameter OutRulesetParameter

LocalRulesetParameter

•

InRulesetParameter:

in Type Variable;

in Type Variable = Expression;

•

InoutRulesetParameter:

inout Type Variable;

•

OutRulesetParameter:

out Type Variable;

out Type Variable = Expression;

•

LocalRulesetParameter:

Type Variable;

Type Variable = Expression;

•

HasherDefinitionList:

hasher (ReturnType Variable) = Expression;

•

InstanceDefinitionList:

instances (ReturnType) = Expression;

instances (ReturnType) = {InstancesList};

 

InstancesList:

Expression

Expression, InstanceList

 

Type: one of

boolean char byte short int long float double String

ClassName

 

ReturnType:

void Type

Variable declaration
•

VariableDeclaration:

variables { LocalRulesetParameterList }

 

LocalRulesetParameterList:

LocalRulesetParameter LocalRulesetParameterList

Hierarchical property declaration
 

HierarchicalPropertyDeclaration :

hierarchy identifier

{ HierarchicalNodeDefinition }

•

HierarchicalChildren:

{ HierarchyDefinitionList }

 

HierarchyDefinitionList:

HierarchicalNodeDefinition HierarchyDefinitionListopt

 

HierarchicalNodeDefinition

STRING_LITERAL HierarchicalChildrenopt

Property typing declaration
•

PropertyTypingDeclaration :

propertydefinition

{ PropertyTypingList }

 

PropertyTypingList :

PropertyTyping PropertyTypingListopt

 

PropertyTyping:

Type Variable ;

Rule overriding declaration
•

RuleOverridingDeclaration :

overriding

{ RuleOverridingList }

 

RuleOverridingList :

RuleOverriding RuleOverridingListopt

 

RuleOverriding:

STRING_LITERAL overrides OverriddenList

 

OverriddenList:

STRING_LITERAL

STRING_LITERAL , OverriddenList

Function definition
 

FunctionDefinitionList :

FunctionDefinition FunctionDefinitionList

•

FunctionDefinition :

function ReturnType FunctionName ( FunctionArgumentList )

{ FunctionActionList }

 

FunctionArgumentList:

FunctionArgument

FunctionArgument, FunctionArgumentList

 

FunctionArgument:

ReturnType Variable

 

FunctionActionList:

FunctionAction FunctionActionListopt

 

FunctionAction: one of

InsertAction VarDeclAction ExecutableStatement

ForFunctionAction IfElseFunctionAction ModifyAction RetractAction

ReturnStatement ThrowAction TryFunctionAction UpdateAction

WhileFunctionAction

Table 2. Syntax of a rule
Rule header
 

RuleDefinitionList :

RuleDefinition RuleDefinitionList

•

RuleDefinition :

rule Identifier { RuleParametersopt RuleConditions RuleActions } ;

 

RuleParameters:

RulePriorityopt RulePropertyopt

•

RulePriority:

priority = PriorityExpression;

•

RuleProperty:

ActivationPropertyopt PropertyList

 

ActivationProperty:

property activation = true;

Rule conditions
•

RuleConditions :

when { FirstRuleCondition RuleConditionListopt }

 

RuleConditionList:

RuleCondition

RuleConditionList RuleCondition

 

FirstRuleCondition:

RuleCondition except WaitStatementList, EvaluateCondition

 

RuleCondition: one of

SimpleCondition NotCondition ExistsCondition EvaluateCondition

FromExpression InExpression CollectCondition WaitStatementList

•

SimpleCondition :

Variableopt:opt eventopt ClassCondition

 

Variable:

?opt Identifier

 

ClassCondition:

ClassName (TestAssignmentList);

•

NotCondition:

not ClassCondition ;

•

ExistsCondition:

exists ClassCondition ;

•

EvaluateCondition:

evaluate (TestAssignmentList);

•

FromExpression:

Variableopt SimpleCondition from PrimaryExpression;

•

InExpression:

Variableopt SimpleCondition in PrimaryExpression;

•

CollectCondition:

Variableopt collect (Expressionopt) SimpleCondition where

TestAssignmentSet;

 

WaitStatementList:

WaitLogicalStatement

WaitStatement

•

WaitLogicalStatement:

wait logical untilopt Expression WaitCondition opt

Variable wait logical untilopt Expression WaitConditionopt

TimeoutAction

•

WaitStatement:

wait Expressionopt WaitConditions

wait until Expression WaitConditions

Variable wait Expressionopt WaitConditions TimeoutAction

Variable wait until Expression WaitConditions TimeoutAction

 

WaitConditions:

{ WaitConditionList }

 

WaitConditionList:

WaitCondition

WaitConditionList

 

WaitCondition: one of

SimpleCondition NotCondition ExistsCondition

CollectCondition

Tests and variable declarations
 

TestAssignmentList:

TestAssignment

TestAssignmentList; TestAssignment

 

TestAssignment: one of

AndExpresssionList OrExpressionList VariableAssignment TestAssignmentSet

BooleanExpression NotAssignment TemporalConstraint

 

AndExpressionList:

TestAssignment && TestAssignment

 

OrExpressionList:

TestAssignment || TestAssignment

 

VariableAssignment :

Variable Expression BooleanAssignmentListopt

 

BooleanAssignmentList:

BooleanAssignment

BooleanAssignmentList BooleanAssignment

 

BooleanAssignment:

& BooleanArgument

 

TestAssignmentSet :

(TestAssignment)

 

NotAssignment :

! TestAssignment

 

TemporalConstraint:

Expressionopt.opt TemporalOperator Arguments

•

TemporalOperator: one of

after before occursin

 

BooleanExpression :

Expression

BooleanArgumentList

 

BooleanArgumentList :

BooleanArgument

BooleanArgumentList & BooleanArgument

•

BooleanArgument:

BooleanArgument

instanceof Identifier

isknown

isunknown

InTest

 

BooleanTerm : one of

PredefinedPredicate Expression

Identifier Expression (use of custom predicate)

 

PredefinedPredicate : one of

== != < > >= <=

 

InTest: one of

in Expression

in { InList }

!in Expression

!in { InList }

 

InList : one of

Expression

InList, Expression

Expressions
 

Expression :

AdditiveExpression

 

AdditiveExpression:

MultiplicativeExpression

MultiplicativeExpressionList

 

MultiplicativeExpressionList:

+ MultiplicativeExpression

- MultiplicativeExpression

+ MultiplicativeExpressionList

- MultiplicativeExpressionList

 

MultiplicativeExpression:

UnaryExpression

UnaryExpressionList

 

UnaryExpressionList:

* UnaryExpression

/ UnaryExpression

% UnaryExpression

* UnaryExpressionList

/ UnaryExpressionList

% UnaryExpressionList

 

UnaryExpression:

+ UnaryExpression

- UnaryExpression

++ UnaryExpression

-- UnaryExpression

UnaryExpression ++

UnaryExpression - -

CastExpression

TimeOfExpression

PrimaryExpression

AsExpression

 

CastExpression:

(ClassName) UnaryExpression

•

AsExpression:

UnaryExpression as (ClassName)

 

TimeOfExpression:

timeof (Expression);

Primary Expressions
•

PrimaryExpression:

PrimaryPrefix

PrimaryPrefix PrimarySuffixList

 

PrimaryPrefix: one of

Literal Name AllocationExpression (Expression)

 

Literal: one of

INTEGER_LITERAL FLOATING_POINT_LITERAL

CHARACTER_LITERAL STRING_LITERAL true false null

 

Name:

Variable IdentifierListopt

 

IdentifierList:

DotIdentifier

DotIdentifier IdentifierList

 

DotIdentifier:

. Identifier

 

AllocationExpression:

new ClassName Arguments

new Type DimensionList

new Type OptDimensionList BracedInitializationList

BracedInitializationList

 

Arguments:

(ExpressionList)

 

ExpressionList:

Expression

ExpressionList, Expression

 

DimensionList:

Dimension

DimensionList Dimension

 

Dimension:

[Expression]

 

OptDimensionList:

OptDimension

OptDimensionList OptDimension

 

OptDimension:

[Expressionopt]

 

BracedInitializationList:

{InitializationList}

 

InitializationList:

Initialization

InitializationList, Initialization

 

Initialization :

Expression

BracedInitializationList

{ExpressionList}

 

PrimarySuffixList:

PrimarySuffix

PrimarySuffixList PrimarySuffix

 

PrimarySuffix: one of

. Variable (access to variable or class field)

Arguments (access to IRL function or class method)

DimensionList (access to array element)

Rule actions
•

RuleActions :

then {RuleActionListopt}

 

RuleActionList:

RuleAction

RuleActionList RuleAction

 

RuleAction: one of

InsertAction VarDeclAction ExecutableStatement

ForAction IfElseAction ModifyAction RetractAction ThrowAction

TimeoutAction TryAction UpdateAction WhileAction

•

InsertAction :

insert logicalopt eventopt ClassName Argumentsopt

ExecutableActionStatementsopt

•

VarDeclAction:

Type Variable = Expression;

•

ForAction :

for(ForInitopt; TestAssignmentopt; ForUpdateopt)

LoopRuleAction

for(ForInitopt; TestAssignmentopt; ForUpdateopt)

{LoopRuleActionList}

•

ForFunctionAction :

for (ForInitopt; TestAssignmentopt; ForUpdateopt)

LoopFunctionAction

for (ForInitopt; TestAssignmentopt; ForUpdateopt)

{LoopFunctionActionList}

 

ForInit:

PrimaryExpression AssignmentOperatorExpression

 

ForUpdate:

PrimaryExpression AssignmentOperatorExpression

•

IfElseAction :

if TestAssignmentSet RuleAction ElseStatement opt

if TestAssignmentSet {RuleActionList} ElseStatementopt

•

ElseStatement:

else RuleAction

else {RuleActionList}

•

IfElseFunctionAction :

if TestAssignmentSet FunctionAction

ElseFunctionActionopt

if TestAssignmentSet {FunctionActionList}

ElseFunctionActionopt

•

ElseFunctionAction:

else FunctionAction

else {FunctionActionList}

•

ModifyAction :

modify refreshopt PrimaryExpression

ExecutableActionStatements;opt

•

RetractAction :

retract PrimaryExpression;

•

ThrowAction:

throw Expression;

•

TimeoutAction :

timeout Variable {NonTimeoutRuleActionList}

 

NonTimeoutRuleActionList:

NonTimeoutRuleAction

NonTimeoutRuleActionList NonTimeoutRuleAction

 

NonTimeoutRuleAction:

RuleAction but not TimeoutAction

 

RuleAction : one of

InsertAction VarDeclAction ExecutableStatement

ForAction IfElseAction ModifyAction RetractAction

UpdateAction WhileAction break; continue;

 

FunctionAction: one of

InsertAction VarDeclAction ExecutableStatement

ForFunctionAction IfElseFunctionAction ModifyAction

RetractAction UpdateAction WhileFunctionAction

break; continue; ReturnStatement

•

ReturnStatement:

return ( expression )

 

RuleActionList:

RuleAction RuleActionListopt

 

FunctionActionList:

FunctionAction FunctionActionListopt

•

TryAction:

try {RuleActionListopt}

Catches

or

try {RuleActionListopt}

Catchesopt

Finally

 

Catches:

CatchClause

Catches CatchClause

•

CatchClause:

catch (ExceptionType Identifier) {RuleActionListopt}

•

Finally:

finally {RuleActionListopt}

•

TryFunctionAction:

try {FunctionActionListopt}

FunctionCatches

or

try {FunctionActionListopt}

FunctionCatchesopt

Finally

 

FunctionCatches:

FunctionCatchClause

FunctionCatches FunctionCatchClause

•

FunctionCatchClause:

catch (ExceptionType Identifier) {FunctionActionListopt}

•

FunctionFinally:

finally {FunctionActionListopt}

•

UpdateAction :

update refreshopt PrimaryExpression;

•

WhileAction :

while TestAssignmentSet LoopRuleAction

while TestAssignmentSet {LoopRuleActionList}

•

WhileFunctionAction :

while TestAssignmentSet LoopFunctionAction

while TestAssignmentSet {LoopFunctionActionList}

Executable statements
 

ExecutableStatementList:

ExecutableStatement

ExecutableStatementList ExecutableStatement

 

ExecutableActionStatements:

{ ExecutableStatementList }

 

ExecutableStatement:

PrimaryExpression AssignmentOperatorExpressionopt;

 

AssignmentOperatorExpression:

AssignmentOperator Expression

  AssignmentOperator : one of = *= /= %= += -=
Table 3. Syntax of a ruleflow
Ruleflow tasks
 

TaskDefinitionList :

TaskDefinition TaskDefinitionList

 

TaskDefinition :

RuleTaskDefinition

FunctionTaskDefinition

FlowTaskDefinition

•

RuleTaskDefinition :

ruletask identifier

{

CommonTaskParameters

RuleTaskBody

RuleTaskScope

RuleTaskParametersopt

};opt

•

FunctionTaskDefinition :

functiontask identifier

{

CommonTaskParameters

FunctionTaskBody

};opt

•

FlowTaskDefinition :

flowtask identifier

{

CommonTaskParameters

FlowTaskBody

};opt

 
Deprecated feature:

Deprecation icon Ruleflow completion flag is deprecated in V8.6. This feature will be removed in a future release. See Deprecated features for migration details.

CommonTaskParameters:

CompletionFlagParameteropt InitialActionsopt FinalActionsopt PropertyListopt

•

CompletionFlagParameter:

completionflag = Expression

•

InitalActions:

initialaction {FunctionActionList}

•

FinalActions:

finalaction {FunctionActionList}

 

RuleTaskBody:

ExtendedBodyDefinition ComprehensiveBodyDefinition

DynamicComprehensiveBodyDefinition

•

RuleTaskScope:

scope {ScopeDefinition}

 

ScopeDefinition:

RuleName

PackageName.*

ScopeDefinitionopt

•

ExtendedBodyDefinition:

body {RulesList};opt

 

RulesList:

identifier

identifier, RulesList

•

ComprehensiveBodyDefinition:

body = select (Variable) {FunctionActionList};opt

body = select () {FunctionActionList};opt

•

DynamicComprehensiveBodyDefinition:

body = dynamicselect(Variable) {FunctionActionList}

EndDynamicComprehensiveBodyDefinition

or

body = dynamicselect () {FunctionActionList}

EndDynamicComprehensiveBodyDefinition

 

EndDynamicComprehensiveBodyDefinition:

;opt

or

DomainValueDefinition

•

DomainValueDefinition:

in Expression;

 

RuleTaskParameters:

AgendaFilterParameter AlgorithmParameters FiringParameter FiringLimitParameter OrderingParameter

•

AgendaFilterParameter:

agendafilter = Expression;

agendafilter = filter (Variable) {FunctionActionList};opt

•

AlgorithmParameters:

algorithm = AlgorithmValues;

iterator = Expression;

MatchedClasses

 

AlgorithmValues:

default sequential

•

MatchedClasses:

matchedclasses = Expression;

matchedclasses = {MatchedClassesList}; opt

 

MatchedClassesList:

ReturnType

ReturnType, MatchedClassesList

•

FiringParameter:

firing = FiringValues;

 

FiringValues:

allrules rule

•

FiringLimitParameter:

firinglimit = Expression;

•

OrderingParameter:

ordering = OrderingValues;

 

OrderingValues:

dynamic sorted literal

•

FunctionTaskBody:

body {FunctionActionList}; opt

•

FlowTaskBody:

body {FlowActionList}; opt

 

FlowActionList:

FlowAction FlowActionListopt

 

FlowAction: one of

FlowTaskInvocationAction FlowForkAction FlowGotoAction

FlowIfElseAction FlowSwitchAction FlowWhileAction

 

FlowTaskInvocationAction :

Labelopt identifier;

 

Label:

identifier:

•

FlowForkAction :

Labelopt fork FlowForkActionList;

•

FlowForkActionList:

{ FlowActionList}; opt

{ FlowActionList} && FlowForkActionList

•

FlowGotoAction :

goto identifier;

•

FlowIfElseAction :

Labelopt if TestAssignmentSet FlowAction FlowElseActionopt ;

Labelopt if TestAssignmentSet {FlowActionList}

FlowElseActionopt;

•

FlowElseAction :

else FlowAction

else {FlowActionList}

•

FlowSwitchAction :

Labelopt switch (Expression)

{ Casesopt Defaultopt }

•

Cases:

CaseClause

Cases CaseClause

•

CaseClause :

case INTEGER_LITERAL:

FlowAction

case INTEGER_LITERAL:

{FlowActionList}

•

Default :

default:

FlowAction

default:

{FlowActionList}

•

FlowWhileAction :

Labelopt while TestAssignmentSet LoopFlowAction

while TestAssignmentSet {LoopFlowActionList}

•

LoopFlowAction :

FlowAction

break;

continue;

 

LoopFlowActionList:

LoopFlowAction LoopFlowActionListopt