27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
34
There is a second, more complex, example of the -mrhoistk option in the
CHANGES_FROM_133*.TXT
file.
#143. Use #pred statement to describe the logical relationship of related predicates
A problem with predicates is that each one is regarded as unique and capable of disambiguating cases where two
alternatives have identical lookahead. For example, consider:
rule : <<pred(LATEXT(1))>>? A
| <<pred(LATEXT(1))>>? A
;
Even though the two alternatives are identical, this will not cause any error messages or warnings to be issued by the
original versions of
PCCTS
. One could compare the text of the predicate, but this is not a robust or satisfactory
solution.
The #pred statement allows one to give a symbolic name to a "predicate literal" or a "predicate expression" in order
to refer to it in other predicate expressions or in the rules of the grammar.
The predicate literal associated with a predicate symbol is C or C++ code which can be used to test the condition. A
predicate expression defines a predicate symbol in terms of other predicate symbols using "!", "&&", and "||". A
predicate symbol can be defined in terms of a predicate literal, a predicate expression, or both.
When a predicate symbol is defined with both a predicate literal and a predicate expression, the predicate literal is
used to generate code, but the predicate expression is used to check for two alternatives with identical predicates in
both alternatives.
Here are some examples of #pred statements:
#pred IsLabel <<isLabel(LATEXT(1))>>?
#pred IsLocalVar <<isLocalVar(LATEXT(1))>>?
#pred IsGlobalVar <<isGlobalVar(LATEXT(1)>>?
#pred IsVar <<isVar(LATEXT(1))>>? IsLocalVar || IsGlobalVar
#pred IsScoped <<isScoped(LATEXT(1))>>? IsLabel || IsLocalVar
The predicate IsLocalVar is related to IsGlobalVar (See the definition of IsVar). The #pred attempts to capture this
for use in analyzing the predicates appearing that appear in prediction expressions. This is discussed in more detail
in the file
CHANGES_FROM_133_BEFORE_MR13.TXT.
#144. Disable predicate hoisting explicitly using the pseudo-action:
rule: <<;>> <<nohoist>> ...
A common error, even among experienced
PCCTS
users, is to code an init-action to inhibit hoisting rather than a
leading action. An init-action does not inhibit hoisting.
This was coded:
rule1 : <<;>> rule2
This is what was meant:
rule1 : <<;>> <<;>> rule2
Now the user can code:
rule1 : <<;>> <<nohoist>> rule2
The following will give an error message:
rule1 : <<nohoist>> rule2
If the <<nohoist>> appears as an init-action rather than a leading action an error message is issued.
#145. Simplification of predicate expressions when there are multiple references to predicates
When a rule containing a semantic predicate is referenced by more than one alternative of a grandparent rule or
other ancestor, a large numbers of semantic predicate references can sometimes be generated. An effort has been
made to simplify some of them. The table below summarized the kind of simplification performed. In the table, X
and Y stand for single predicates (not trees).
(OR X (OR Y (OR Z))) => (OR X Y Z)
(AND X (AND Y (AND Z))) => (AND X Y Z)
(OR X (... (OR X Y) ... )) => (OR X (... Y ... ))
(AND X (... (AND X Y) ... )) => (AND X (... Y ... ))
(OR X (... (AND X Y) ... )) => (OR X (... ... ))