[NEXT] [PREV]
HANDBOOK
/ LANGUAGE REFERENCE MANUAL
/Predicates 

Gentle
Applications Concepts Examples Handbook Support Download

PredicateDecl =
Category Ident Signature Rules .
Category = "'nonterm'"  "'token'"  "'action'"  "'condition'"  "'choice'"  "'sweep'" . Signature = ["(" [ParamSpec{ "," ParamSpec}] [">"[ParamSpec{ "," ParamSpec}]]")"] . Rules = {Head ":" Body "."}  {"'rule'" Head [":"] Body ["."]} . Head = Ident ["(" [Pattern{ "," Pattern}] [">" [Expression{ "," Expression}]] ")"] . Body = {Member} [CostSpec] CostSpec = "$" Number .
Predicate DeclarationsA predicate declaration of the form
introduces a predicate p of category Category with n input parameters of types T_{1}, ..., T_{n}, and with m output parameters of types S_{1}, ..., S_{m}. A predicate may be used in a predicate invocation. A predicate that is invoked with input values Tau_{1}, ..., Tau_{n} is elaborated as follows. If no rule is applicable, the invocation fails. Otherwise, a rule is selected and elaborated, yielding output values Sigma_{1}, ..., Sigma_{n}, and the invocation succeeds.
RulesA rule has the form
For given input values Tau_{1}, ..., Tau_{n}, the rule is elaborated as follows. Let V_{1}, ..., V_{nin} be the variables appearing in P_{1}, ..., P_{n}, and W_{1}, ..., W_{nout} the variables appearing in E_{1}, ..., E_{m}. If the input values Tau_{1}, ..., Tau_{n} do not match the patterns P_{1}, ..., P_{n}, the rule is not applicable. Otherwise, the variables V_{1}, ..., V_{nin} are defined. Then the members M_{1} ... M_{k} are elaborated. If one of the members fails, the rule is not applicable. Otherwise, the variables W_{1}, ..., W_{nout} are defined. The expressions E_{1} ... E_{m} are evaluated, yielding output values Sigma_{1}, ..., Sigma_{m}. A variable that appears in a pattern is said to be defined. A variable that appears in an expression is said to be applied. Each applied variable must be a defined variable. Variables that are applied in a member M_{i} must be defined by one of the patterns P_{1}, ..., P_{n} or in a member M_{j} that appears to the left of M_{i} . A defined variable cannot be redefined.
