`HRL.grm`

    // FILE. . . . . /cygdrive/c/cygwin/home/hak/ilt/src/ilog/rif/HRL.grm
    // EDIT BY . . . Hassan Ait-Kaci
    // ON MACHINE. . 4j4zn71.Ilog.Biz
    // STARTED ON. . Tue Sep 19 10:29:49 2006

    // Last modified on Thu Sep 21 05:35:25 2006 by hak

This is a Jacc grammar for a Horn Rule Language (HRL) based on the RIF Condition Language (RCL) defined as a combination of partial grammars. It has evolved out of the first-cut grammar for a minimal "human-readable" syntax and which is described in the proposal submitted to the W3C Working Group on the Rule Interchange Format (RIF) by Harold Boley et al., on April 23, 2006. It is meant to be able to express the abstract syntax form taken by conditions of the rules that appear to be common to a reasonably large variety of families of rule languages. The proposal in question is available from the public RIF WG mail archive: [RIF] Extensible Design. This Jacc grammar specification is a literal transcription of the BNF rules given in the above references. This version of the RCL grammar is annotated for simple XML serialization. We give below the Jacc grammar rules for RCL. Note that the grammar their combination defines is LALR(1). This HTML file is the root of a hyperlinked documentation allowing one to explore the grammar via navigation through its elements - rules, terminal and non-terminal symbols. The comments accompanying some rules come from the original documents. It also contains the pure Yacc rules. This documentation is generated by Jacc from the Jacc grammar specified in file `HRL.grm` (i.e., with the command "`jacc -doc HRL`"). Along with this Jacc grammar file, there are other supporting source files. Essentially, the rule format is that of Yacc. As in Yacc, Jacc rules may be annotated with semantic actions, in the form of code involving the rule's RHS constituents (denoted by `$1`, `$2`, ..., `$n` - the so-called pseudo-variables where the index `n` in `$n` refers to the order of RHS constituents. Such actions appear between curly braces ('`{`' and '`}`') wherever a symbol may appear in a rule's RHS. Jacc also allows an additional form of annotation in the RHS of a rule to indicate the XML serialization pattern of the abstract syntactic tree (AST) node corresponding to a derivation with this rule. This XML serialization meta-annotation comes between square brackets ('`[`' and '`]`') and is of the form:
      [ XmlTag n_1 ... n_k ]
where `XmlTag` is an identifier to use as XML tag for this node in the XML serialization of the AST, and the `n_k`'s are a sequence of numbers denoting positions of symbols in the RHS of the rule (as for pseudo-variables but without `'$'`). The number sequence indicates the order in which subnodes are to be serialized. For example, the annotated rule:
      QUANTIF
         : 'Exists' Var_plus '(' CONDIT ')'
           [ Exists 2 4 ]
         ;
means that an AST node for this rule will be serialized thus:
       <Exists>
         (Xml serialization of Var_plus)
         (Xml serialization of CONDIT)
       </Exists>
Rules without XML serialization annotation follow a default behavior: the serialization is the concatenation of those of its RHS's constituents, eliminating punctuation tokens (i.e., empty nodes and literal tokens - namely, tokens that do not carry a value). For example, see the two test files `Test.hrl` and `Test2.hrl`. Running the command `hrl` on them produces the output shown in `Test.run`.

    ////////////////////////////////////////////////////////////////////////

    %package ilog.rif;

    %include "ParserCode.grm"  // Code for setting params and showing xml serialization

    %token Var Rel Fun Value Object // NB: Var is a token (i.e., the '?' is part of it)

    %start ROOT

    ////////////////////////////////////////////////////////////////////////

    %%

Horn Rule Language (HRL) program grammar's root.

    ROOT
      : HRL
      { showXml(); }  // show the XML tree
      ;

HRL program units are rulesets.

    HRL
      : RuleSet
      [ rif:RuleSet 1 ]  // XML serialization pattern
      ;

Rulesets are sequences of rules.

    RuleSet
      : Rule
      | RuleSet Rule
      ;

A Horn rule is a kind of rule.

    Rule
      : HornRule
      [ rif:HornRule 1 ]  // XML serialization pattern
      ;

A Horn rule is a logical implication.

    HornRule
      : Implication
      ;

An implication consists of a $HEAD$ (the LHS - what's on the left of $:-$) and a $BODY$ (the RHS - what's on the right of $:-$).

    Implication
      : HEAD ':-' BODY
      [ hrl:Implies 3 1 ]  // XML serialization pattern
      ;

A Horn rule's head is a literal formula ($LITFORM$).

    HEAD
      : LITFORM
      [ hrl:Consequent 1 ]  // XML serialization pattern
      ;

A Horn rule's body is a condition ($CONDIT$).

    BODY
      : CONDIT
      [ hrl:Antecedent 1 ]  // XML serialization pattern
      ;

    ////////////////////////////////////////////////////////////////////////
    // Includes:
    ////////////////////////////////////////////////////////////////////////

    // RIF Condition Language basis:
    %include RCL_basis.grm

    // RCL's dual (value,object) constants:
    %include RCL_valobj.grm

    // RCL's universal quantification:
    %include RCL_forall.grm

    // RCL's constructive negation:
    %include RCL_neg.grm

    // RCL's negation-as-failure:
    %include RCL_naf.grm

    // RCL's both negation-as-failure and constructive negation:
    %include RCL_nafneg.grm

    %%

    ////////////////////////////////////////////////////////////////////////

This file was generated on Thu Sep 21 08:10:12 PDT 2006 from file `HRL.grm`
by the `ilog.language.tools.Hilite` Java tool written by Hassan Aït-Kaci