|
[See source files here.]
This is a Jacc grammar for the so-called presentation syntax of the
RIF Basic Logic
Dialext (BLD) developed as a result of the activities of the RIF
Working Group (Phase 1).
This Jacc grammar specification given here is a literal transcription
of the BNF rules given in the above references. There are two sets of
grammar rules:
- the rules for the Basic Logic Condition (BLC) language; and,
- the rules for the Basic Logic Rule language (BLR).
These two grammars expressed in Yacc form are:
-
BLD Condition Language
Formula
: Atomic
| AND OPENPAR Formulas_opt CLOSEPAR
| OR OPENPAR Formulas_opt CLOSEPAR
| EXISTS Vars OPENPAR Formula CLOSEPAR
| EXTERNAL OPENPAR Atom CLOSEPAR
;
Atomic
: Atom
| Equal
| Member
| Subclass
| Frame
;
Atom
: UniTerm
;
UniTerm
: Const OPENPAR UniTermBody CLOSEPAR
;
Equal
: Term EQUAL Term
;
Member
: Term MEMBER Term
;
Subclass
: Term SUBCLASS Term
;
Frame
: Term OPENBRA FrameAttributes_opt CLOSEBRA
;
Term
: Const
| Var
| Expr
| EXTERNAL OPENPAR Expr CLOSEPAR
;
Expr
: UniTerm
;
Const
: STRING LEXSPACE SymSpace
;
Var
: VARIABLE
;
UniTermBody
: Terms_opt
| TermAttributes_opt
;
TermAttributes_opt
: // empty
| TermAttributes
;
TermAttributes
: TermAttribute
| TermAttributes TermAttribute
;
TermAttribute
: Const ARROW Term
;
FrameAttributes_opt
: // empty
| FrameAttributes
;
FrameAttributes
: FrameAttribute
| FrameAttributes FrameAttribute
;
FrameAttribute
: Term ARROW Term
;
Formulas_opt
: // empty
| Formulas
;
Formulas
: Formula
| Formulas Formulas
;
Terms_opt
: // empty
| Terms_opt Term
;
Vars
: Var
| Vars Var
;
SymSpace
: IDENTIFIER COLON IDENTIFIER
;
-
BLD Rule Language
Group
: GROUP Meta_opt OPENPAR RuleSet_opt CLOSEPAR
;
Meta
: Frame
;
Rule
: Clause
| FORALL Vars_opt OPENPAR Clause CLOSEPAR
;
Clause
: Atomic
| Implies
;
Implies
: Atomic IF Formula
;
RuleSet_opt
: // empty
| RuleSet
;
RuleSet
: RuleOrGroup
| RuleSet RuleOrGroup
;
RuleOrGroup
: Rule
| Group
;
Meta_opt
: // empty
| Meta
;
Vars_opt
: // empty
| Vars
;
This version of the BLD grammar is annotated for simple XML
serialization as per the scheme specified in the current BLD
document. If and where we may diverge with what is the BLD
document, it will be indicated in what mannner and why.
This HTML file is the root of a hyperlinked documentation allowing
one to explore the Jacc grammar for BLD 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 - i.e., without semantic actions.
This documentation is generated by Jacc from the Jacc grammar
specified in file BLD.grm
(i.e., with the command "jacc -doc BLD"). Along with
this Jacc grammar file, there are other supporting source files.
Essentially, the format of a Jacc grammar is that of a Yacc
grammar. As in Yacc, Jacc rules may be annotated with semantic
actions in the form of Java 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 described
by this Jacc grammar for a
XML annotation language for a Jacc grammar! (Yes - it generates a
a meta-metaparser.)
For example, the annotated rule:
QUANTIF
: 'Exists' Var_plus '(' CONDIT ')'
[
nsprefix : hrl
localname : quantifier
attributes : {kind="existential"}
children : (2,4)
]
;
means that an AST node for this rule will be serialized thus:
<hrl:quantifier kind="existential">
(XML serialization of Var_plus)
(XML serialization of CONDIT)
</hrl:quantifier>
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).
See JaccXmlAnnotations.doc for more details.
For example, see the two test files test1.bld
and test2.bld. Running the command bld on them produces the XML trees shown in test1.xml and test2.xml.
The terminal symbols are:
| Token |
Value |
| STRING |
double-quoted string |
| VARIABLE |
max-length sequence of non-special chars starting
with a '?' |
| IDENTIFIER |
max-length sequence of non-special chars |
| OR |
'Or' |
| AND |
'And' |
| FORALL |
'Forall' |
| EXISTS |
'Exists' |
| GROUP |
'Group' |
| EXTERNAL |
'External' |
| IF |
':-' |
| ARROW |
'->' |
| LEXSPACE |
'^^' |
| EQUAL |
'=' |
| MEMBER |
'#' |
| SUBCLASS |
'##' |
| COLON |
':' |
| OPENPAR |
'(' |
| CLOSEPAR |
')' |
| OPENBRA |
'[' |
| CLOSEBRA |
']' |
Important Notes:
-
VARIABLE is a token
recognized thanks to its leading '?' but the token returned by the lexer
suppresses this leading '?'.
This means that '?' is
not a separate punctuation mark as shown by the EBNF.
-
Using STRING dispenses
from the spurious "..."^^
notation, making '^^' an infix
operator.
In other words, the initial and final double quotes are
part of the token itself an need not appear at the grammar level.
-
IDENTIFIER is any maximal sequence of
non-separator not-punctuation unicode characters that does not start
with a '?'.
-
For now, a SymSpace is simply
parsed as a pair of IDENTIFIERs
separated by a colon (':').
This means that ':'
is a separate punctuation mark unlike what is shown by
the EBNF.
|