Skip navigation links
mmj.verify

Class TypeConversionRule

    • Field Detail

      • convTyp

        protected Cnst convTyp
        convTyp is the "from" or source Typ Cd for The Type Conversion Rule, which is converted "to" the Rule's Type Code.

        Note that there is no need to store the "to" Type code here in the TypeConversionRule because it can easily be derived from the Type Code via GrammarRule.getBaseSyntaxAxiom().getTyp() AND from the root node's Stmt of GrammarRule.paramTransformationTree.

    • Constructor Detail

      • TypeConversionRule

        public TypeConversionRule()
        Default constructor.
      • TypeConversionRule

        public TypeConversionRule(Grammar grammar,
                                  Axiom baseSyntaxAxiom,
                                  Cnst convTyp)
        Constructor -- default GrammarRule for base Syntax Axioms, which means no parameter "transformations".
        Parameters:
        grammar - The Grammar.
        baseSyntaxAxiom - Syntax Axiom.
        convTyp - the "from" type code of this conversion
      • TypeConversionRule

        public TypeConversionRule(Grammar grammar,
                                  NotationRule oldNotationRule,
                                  int matchIndex,
                                  NullsPermittedRule nullsPermittedRule)
        Builds a new TypeConversionRule using a Notation rule which is being "cloned" and modified by substituting the paramTransformationTree from a NullsPermittedRule for one of the existing rule's variable hypothesis paramTransformationTree nodes.

        (That sounds hairy :)

        Note that the output paramTransformationTree is built using a deep clone of the existing rule's paramTransformationTree but the substituting tree does not need cloning BECAUSE when the GrammaticalParser builds a ParseTree for an expression, *it* does a full cloning operation; this, of course assumes that once a GrammarRule is created and fully populated that it is never modified (changing the grammar means rebuilding it, in other words.)

        Parameters:
        grammar - The Grammar.
        oldNotationRule - rule being "cloned".
        matchIndex - index to paramVarHypNode array indicating which VarHyp is being substituted.
        nullsPermittedRule - the modifying rule.
      • TypeConversionRule

        public TypeConversionRule(Grammar grammar,
                                  TypeConversionRule oldTCRule,
                                  int matchIndex,
                                  TypeConversionRule typeConversionRule)
        Builds a new TypeConversionRule using an existing TypeConversion rule which is being "cloned" and and modified by substituting the paramTransformationTree from another TypeConversionRule for one of the existing rule's variable hypothesis paramTransformationTree nodes.

        Note that the output paramTransformationTree is built using a deep clone of the existing rule's paramTransformationTree but the substituting tree does not need cloning BECAUSE when the GrammaticalParser builds a ParseTree for an expression, *it* does a full cloning operation; this, of course assumes that once a GrammarRule is created and fully populated that it is never modified (changing the grammar means rebuilding it, in other words.)

        Parameters:
        grammar - The Grammar.
        oldTCRule - rule being "cloned".
        matchIndex - index to paramVarHypNode array indicating which VarHyp is being substituted.
        typeConversionRule - the modifying rule.
    • Method Detail

      • buildBaseRule

        protected static TypeConversionRule buildBaseRule(Grammar grammar,
                                                          Axiom baseSyntaxAxiom,
                                                          ParseNodeHolder[] parseNodeHolderExpr)
        Type Conversion Rule builder for base Syntax Axioms, which means no parameter "transformations".
        Parameters:
        grammar - The Grammar.
        baseSyntaxAxiom - Syntax Axiom.
        parseNodeHolderExpr - Expression in parseNodeHolder array.
        Returns:
        new TypeConversionRule object.
      • isLoop

        public static boolean isLoop(Cnst fromTyp,
                                     Cnst toTyp)
        isLoop determines whether or not a new Type Conversion from/to pair of Type Codes create a "loop" -- meaning that "from" converts to "to" and "to" converts to "from", directly or indirectly.

        isLoop relies on Cnst.convFromTypGRArray already being fully populated with all "from" Type Codes for the subject Cnst, including direct conversions and all indirect conversions; this puts the onus on TypeConversionRule.deriveAdditionalRules to figure out the complicated stuff.

        Parameters:
        fromTyp - the "from" converstion Type Code.
        toTyp - the "to" converstion Type Code.
        Returns:
        true if it is a loop, else false.
      • getDupRule

        public GrammarRule getDupRule(Grammar grammar,
                                      Cnst[] ruleFormatExprIn)
        Return a duplicate of the input ruleFormatExpr if it exists, or return null.
        Specified by:
        getDupRule in class GrammarRule
        Parameters:
        grammar - The Grammar.
        ruleFormatExprIn - the expression to check.
        Returns:
        GrammarRule if duplicate found, or null.
      • addToGrammar

        public void addToGrammar(Grammar grammar,
                                 Cnst[] ruleFormatExprIn)
        Add Type Conversion rule format expression to the system "repository".
        Specified by:
        addToGrammar in class GrammarRule
        Parameters:
        grammar - The Grammar object (Mr Big).
        ruleFormatExprIn - the expression to add.
      • deriveAdditionalRules

        public void deriveAdditionalRules(Grammar grammar)
        deriveAdditionalRules based on the addition of a new GrammarRule to those already generated and accepted.

        A PriorityQueue is used to store new derivedGrammarRules awaiting processing (dup checking, parse checking and possible addition to the Grammar data.) The Comparator orders derived rules based on MaxSeqNbr and ruleNbr so that low Metamath sequence number statements are added to the Grammar before higher sequenced statements. The existing rules are stored in separate repositories, which are scanned, as needed, when a new rule is added; the order that the repositories are scanned is irrelevant because the PriorityQueue controls update processing sequence.

        Note also that a newly derived rule may generate other derived rules, which in turn trigger other derivations; this is a "feature" (as well as a scary opportunity for an infinite loop!) The benefit is that each pair of rules may be considered separately; when processing the pair there is no need to worry about other possible Type Conversion and Null Permitted Rules. For example, an "A" Type hypothesis in a Notation Rule may be the target of a "B to A" Type Conversion, but the fact that there is a "C to B" or "C to A" conversion can be ignored -- if the "B to A" conversion generates a variant rule of the original rule, then when *that* rule comes back through the PriorityQueue, the "C to B" rule will automatically come into play. This also means that a "B to A" conversion will combine with a "C to B" conversion to generate a "C to A" conversion -- eventually.

        Specified by:
        deriveAdditionalRules in class GrammarRule
        Parameters:
        grammar - The Grammar.
      • deriveRulesUsingNullsPermitted

        protected void deriveRulesUsingNullsPermitted(Grammar grammar,
                                                      NullsPermittedRule nullsPermittedRule)
        Generates a NullsPermittedRule *if* the input NullsPermittedRule Type Code matches the Type Code of the TypeConversionRule's VarHyp.

        Note: The form of a TypeConversionRule *expression* is exactly one variable whose Type Code differs from that of the rule's Type.

        Parameters:
        grammar - The Grammar.
        nullsPermittedRule - the modifying rule.
      • deriveRulesUsingTypeConversion

        protected void deriveRulesUsingTypeConversion(Grammar grammar,
                                                      TypeConversionRule typeConversionRule)
        Generates a TypeConversionRule *if* the input TypeConversionRule Type Code matches the Type Code of this TypeConversionRule's VarHyp.

        Note: The form of a TypeConversionRule *expression* is exactly one variable whose Type Code differs from that of the rule's Type.

        Parameters:
        grammar - The Grammar.
        typeConversionRule - the modifying rule.
      • getConvTyp

        public Cnst getConvTyp()
        Return convTyp, the "from" part of the Type conversion.
        Returns:
        convTyp, the "from" part of the Type conversion.
      • getForestRuleExpr

        public Cnst[] getForestRuleExpr()
        Returns the ruleFormatExpr for the Type Conversion Rule by simulating retrieving it from the Grammar Rule Tree/Forest.

        In reality, the ruleFormatExpr for a Type Conversion Rule is an length = 1 symbol sequence = convTyp.

        Specified by:
        getForestRuleExpr in class GrammarRule
        Returns:
        ruleFormatExpr for the Type Conversion Rule.