Exemple #1
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        public DerivedPred(MasterGrammar p, BForm bForm) : base(p, bForm)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var derivedDef     = new NonTerminal("Derived predicate definition", typeof(TransientAstNode));
            var derivedDefBase = new NonTerminal("Derived predicate definition", typeof(DomainDerivedPredAstNode));

            var predicateSkeleton     = new NonTerminal("Derived predicate skeleton", typeof(TransientAstNode));
            var predicateSkeletonBase = new NonTerminal("Derived predicate skeleton", typeof(PredicateSkeletonAstNode));

            var predicateIdentifier = new IdentifierTerminal("Predicate identifier", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var gd        = new Gd(p);
            var typedList = new TypedList(p);

            // RULES

            derivedDef.Rule     = p.ToTerm("(") + derivedDefBase + ")";
            derivedDefBase.Rule = p.ToTerm(":derived") + predicateSkeleton + gd;

            predicateSkeleton.Rule     = p.ToTerm("(") + predicateSkeletonBase + ")";
            predicateSkeletonBase.Rule = predicateIdentifier + typedList;

            p.MarkTransient(derivedDef, predicateSkeleton);

            Rule = (bForm == BForm.BASE) ? derivedDefBase : derivedDef;
        }
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public PreGd(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var preGd         = new NonTerminal("Pre-GD", typeof(TransientAstNode));
            var preGdBase     = new NonTerminal("Pre-GD base", typeof(TransientAstNode));
            var preGdStarList = new NonTerminal("Pre-GD star-list", typeof(TransientAstNode));

            var prefPreGdBase   = new NonTerminal("Preference expression (pre-GD)", typeof(PreferenceGdAstNode));
            var prefNameOrEmpty = new NonTerminal("Optional preference name", typeof(TransientAstNode));
            var prefName        = new IdentifierTerminal("Preference name", IdentifierType.CONSTANT);

            var andPreGdBase    = new NonTerminal("AND expression (pre-GDs)", typeof(AndGdAstNode));
            var forallPreGdBase = new NonTerminal("FORALL expression (pre-GD)", typeof(ForallGdAstNode));
            var orGdBase        = new NonTerminal("OR expression (pre-GD)", typeof(OrGdAstNode));
            var notGdBase       = new NonTerminal("NOT expression (pre-GD)", typeof(NotGdAstNode));
            var implyGdBase     = new NonTerminal("IMPLY expression (pre-GD)", typeof(ImplyGdAstNode));
            var existsGdBase    = new NonTerminal("EXISTS expression (pre-GD)", typeof(ExistsGdAstNode));
            var equalsOpGdBase  = new NonTerminal("Equals operator (pre-GD)", typeof(EqualsOpGdAstNode));

            var numCompGdBase  = new NonTerminal("Numeric comparison expression (pre-GD)", typeof(NumCompGdAstNode));
            var binaryComparer = new NonTerminal("Binary comparer", typeof(TransientAstNode));

            var gdStarList = new NonTerminal("GD star-list", typeof(TransientAstNode));

            // USED SUB-TREES

            var typedList       = new TypedList(p);
            var gd              = new Gd(p);
            var predicateGdBase = new PredicateGd(p, BForm.BASE);
            var numericExpr     = new NumericExpr(p);
            var valueOrTerm     = new ValueOrTerm(p);

            // RULES

            preGd.Rule     = p.ToTerm("(") + preGdBase + ")";
            preGdBase.Rule = prefPreGdBase | andPreGdBase | forallPreGdBase | orGdBase | notGdBase | implyGdBase | existsGdBase | predicateGdBase | equalsOpGdBase | numCompGdBase;

            prefPreGdBase.Rule   = p.ToTerm("preference") + prefNameOrEmpty + gd;
            prefNameOrEmpty.Rule = prefName | p.Empty;

            andPreGdBase.Rule    = p.ToTerm("and") + preGdStarList;
            forallPreGdBase.Rule = p.ToTerm("forall") + "(" + typedList + ")" + preGd;
            orGdBase.Rule        = p.ToTerm("or") + gdStarList;
            notGdBase.Rule       = p.ToTerm("not") + gd;
            implyGdBase.Rule     = p.ToTerm("imply") + gd + gd;
            existsGdBase.Rule    = p.ToTerm("exists") + "(" + typedList + ")" + gd;
            equalsOpGdBase.Rule  = p.ToTerm("=") + valueOrTerm + valueOrTerm;

            numCompGdBase.Rule  = binaryComparer + numericExpr + numericExpr;
            binaryComparer.Rule = p.ToTerm(">") | "<" | ">=" | "<=";

            preGdStarList.Rule = p.MakeStarRule(preGdStarList, preGd);
            gdStarList.Rule    = p.MakeStarRule(gdStarList, gd);

            p.MarkTransient(preGd, preGdBase, gd, numericExpr, binaryComparer);

            Rule = preGd;
        }
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        public Effect(MasterGrammar p, BForm bForm) : base(p, bForm)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var effect     = new NonTerminal("Effect", typeof(TransientAstNode));
            var effectBase = new NonTerminal("Effect base", typeof(TransientAstNode));

            var andCEffectsBase = new NonTerminal("AND expression (c-effects)", typeof(AndCEffectsAstNode));
            var cEffectStarList = new NonTerminal("C-effects list", typeof(TransientAstNode));

            var cEffect     = new NonTerminal("C-effect", typeof(TransientAstNode));
            var cEffectBase = new NonTerminal("C-effect base", typeof(TransientAstNode));

            var forallCEffectBase = new NonTerminal("FORALL expression (c-effect)", typeof(ForallCEffectAstNode));
            var whenCEffectBase   = new NonTerminal("WHEN expression (c-effect)", typeof(WhenCEffectAstNode));

            var condEffect     = new NonTerminal("Cond-Effect", typeof(TransientAstNode));
            var condEffectBase = new NonTerminal("Cond-Effect base", typeof(TransientAstNode));

            var andPEffectsBase = new NonTerminal("AND expression (p-effects)", typeof(AndPEffectsAstNode));
            var pEffectStarList = new NonTerminal("P-effects star-list", typeof(TransientAstNode));

            // USED SUB-TREES

            var typedList   = new TypedList(p);
            var gd          = new Gd(p);
            var pEffect     = new PEffect(p, BForm.FULL);
            var pEffectBase = new PEffect(p, BForm.BASE);

            // RULES

            // (general) effect - c-effect or a list of c-effects
            effect.Rule     = p.ToTerm("(") + effectBase + ")";
            effectBase.Rule = cEffectBase | andCEffectsBase;

            andCEffectsBase.Rule = p.ToTerm("and") + cEffectStarList;
            cEffectStarList.Rule = p.MakeStarRule(cEffectStarList, cEffect);

            // c-effect (allowing conditional effects)
            cEffect.Rule     = p.ToTerm("(") + cEffectBase + ")";
            cEffectBase.Rule = forallCEffectBase | whenCEffectBase | pEffectBase;

            forallCEffectBase.Rule = p.ToTerm("forall") + "(" + typedList + ")" + effect;
            whenCEffectBase.Rule   = p.ToTerm("when") + gd + condEffect;

            // cond-effect (not allowing inner conditional effects)
            condEffect.Rule     = p.ToTerm("(") + condEffectBase + ")";
            condEffectBase.Rule = pEffectBase | andPEffectsBase;

            andPEffectsBase.Rule = p.ToTerm("and") + pEffectStarList;
            pEffectStarList.Rule = p.MakeStarRule(pEffectStarList, pEffect);

            p.MarkTransient(effect, effectBase, cEffect, cEffectBase, condEffect, condEffectBase);

            Rule = (bForm == BForm.BASE) ? effectBase : effect;
        }
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public ConGd(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var conGd         = new NonTerminal("Con-GD", typeof(TransientAstNode));
            var conGdBase     = new NonTerminal("Con-GD base", typeof(TransientAstNode));
            var conGdStarList = new NonTerminal("Con-GD star-list", typeof(TransientAstNode));

            var andConGdBase    = new NonTerminal("AND expression (con-GDs)", typeof(AndConGdAstNode));
            var forallConGdBase = new NonTerminal("FORALL expression (con-GDs)", typeof(ForallConGdAstNode));

            var atEndConGdBase          = new NonTerminal("AT-END expression (con-GD)", typeof(AtEndConGdAstNode));
            var alwaysConGdBase         = new NonTerminal("ALWAYS expression (con-GD)", typeof(AlwaysConGdAstNode));
            var sometimeConGdBase       = new NonTerminal("SOMETIME expression (con-GD)", typeof(SometimeConGdAstNode));
            var withinConGdBase         = new NonTerminal("WITHIN expression (con-GD)", typeof(WithinConGdAstNode));
            var atMostOnceConGdBase     = new NonTerminal("AT-MOST-ONCE expression (con-GD)", typeof(AtMostOnceConGdAstNode));
            var sometimeAfterConGdBase  = new NonTerminal("SOMETIME-AFTER expression (con-GD)", typeof(SometimeAfterConGdAstNode));
            var sometimeBeforeConGdBase = new NonTerminal("SOMETIME-BEFORE expression (con-GD)", typeof(SometimeBeforeConGdAstNode));
            var alwaysWithinConGdBase   = new NonTerminal("ALWAYS-WITHIN expression (con-GD)", typeof(AlwaysWithinConGdAstNode));
            var holdDuringConGdBase     = new NonTerminal("HOLD-DURING expression (con-GD)", typeof(HoldDuringConGdAstNode));
            var holdAfterConGdBase      = new NonTerminal("HOLD-AFTER expression (con-GD)", typeof(HoldAfterConGdAstNode));

            var number = new NumberLiteral("Number");

            // USED SUB-TREES

            var typedList = new TypedList(p);
            var gd        = new Gd(p);

            // RULES

            conGd.Rule     = p.ToTerm("(") + conGdBase + ")";
            conGdBase.Rule = andConGdBase | forallConGdBase | atEndConGdBase | alwaysConGdBase | sometimeConGdBase | withinConGdBase | atMostOnceConGdBase
                             | sometimeAfterConGdBase | sometimeBeforeConGdBase | alwaysWithinConGdBase | holdDuringConGdBase | holdAfterConGdBase;

            andConGdBase.Rule    = p.ToTerm("and") + conGdStarList;
            forallConGdBase.Rule = p.ToTerm("forall") + "(" + typedList + ")" + conGd;

            atEndConGdBase.Rule          = p.ToTerm("at") + p.ToTerm("end") + gd;
            alwaysConGdBase.Rule         = p.ToTerm("always") + gd;
            sometimeConGdBase.Rule       = p.ToTerm("sometime") + gd;
            withinConGdBase.Rule         = p.ToTerm("within") + number + gd;
            atMostOnceConGdBase.Rule     = p.ToTerm("at-most-once") + gd;
            sometimeAfterConGdBase.Rule  = p.ToTerm("sometime-after") + gd + gd;
            sometimeBeforeConGdBase.Rule = p.ToTerm("sometime-before") + gd + gd;
            alwaysWithinConGdBase.Rule   = p.ToTerm("always-within") + number + gd + gd;
            holdDuringConGdBase.Rule     = p.ToTerm("hold-during") + number + number + gd;
            holdAfterConGdBase.Rule      = p.ToTerm("hold-after") + number + gd;

            conGdStarList.Rule = p.MakeStarRule(conGdStarList, conGd);

            p.MarkTransient(conGd, conGdBase);

            Rule = conGd;
        }
Exemple #5
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public DaGd(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var daGd         = new NonTerminal("Da-GD", typeof(TransientAstNode));
            var daGdBase     = new NonTerminal("Da-GD base", typeof(TransientAstNode));
            var daGdStarList = new NonTerminal("Da-GD star-list", typeof(TransientAstNode));

            var andDaGdBase    = new NonTerminal("AND expression (da-GDs)", typeof(AndDaGdAstNode));
            var forallDaGdBase = new NonTerminal("FORALL expression (da-GD)", typeof(ForallDaGdAstNode));
            var prefDaGdBase   = new NonTerminal("Preference (da-GD)", typeof(PreferenceDaGdAstNode));

            var prefNameOrEmpty = new NonTerminal("Optional preference name", typeof(TransientAstNode));
            var prefName        = new IdentifierTerminal("Preference name", IdentifierType.CONSTANT);

            var timedDaGd     = new NonTerminal("Timed-da-GD", typeof(TransientAstNode));
            var timedDaGdBase = new NonTerminal("Timed-da-GD base", typeof(TransientAstNode));
            var atTimedDaGd   = new NonTerminal("AT expression (timed-da-GD)", typeof(AtTimedDaGdAstNode));
            var overTimedDaGd = new NonTerminal("OVER expression (timed-da-GD)", typeof(OverTimedDaGdAstNode));

            var timeSpecifier     = new NonTerminal("Time specifier", typeof(TransientAstNode));
            var intervalSpecifier = new NonTerminal("Interval specifier", typeof(TransientAstNode));

            // USED SUB-TREES

            var typedList = new TypedList(p);
            var gd        = new Gd(p);

            // RULES

            daGd.Rule     = p.ToTerm("(") + daGdBase + ")";
            daGdBase.Rule = andDaGdBase | forallDaGdBase | prefDaGdBase | timedDaGdBase;

            andDaGdBase.Rule    = p.ToTerm("and") + daGdStarList;
            forallDaGdBase.Rule = p.ToTerm("forall") + "(" + typedList + ")" + daGd;

            prefDaGdBase.Rule    = p.ToTerm("preference") + prefNameOrEmpty + timedDaGd;
            prefNameOrEmpty.Rule = prefName | p.Empty;

            timedDaGd.Rule     = p.ToTerm("(") + timedDaGdBase + ")";
            timedDaGdBase.Rule = atTimedDaGd | overTimedDaGd;
            atTimedDaGd.Rule   = p.ToTerm("at") + timeSpecifier + gd;
            overTimedDaGd.Rule = p.ToTerm("over") + intervalSpecifier + gd;

            timeSpecifier.Rule     = p.ToTerm("start") | p.ToTerm("end");
            intervalSpecifier.Rule = p.ToTerm("all");

            daGdStarList.Rule = p.MakeStarRule(daGdStarList, daGd);

            p.MarkTransient(daGd, daGdBase, timedDaGd, timedDaGdBase);

            Rule = daGd;
        }