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

            var durActionDef     = new NonTerminal("Durative action definition", typeof(TransientAstNode));
            var durActionDefBase = new NonTerminal("Durative action definition", typeof(DomainDurActionAstNode));
            var daParameters     = new NonTerminal("Durative action parameters", typeof(TransientAstNode));
            var daDuration       = new NonTerminal("Durative action duration", typeof(TransientAstNode));
            var daConditions     = new NonTerminal("Durative action conditions", typeof(TransientAstNode));
            var daEffects        = new NonTerminal("Durative action effects", typeof(TransientAstNode));

            var emptyOrDurConstr = new NonTerminal("Empty or duration-constraint", typeof(TransientAstNode));
            var emptyOrDaGd      = new NonTerminal("Empty or da-GD", typeof(TransientAstNode));
            var emptyOrDaEffect  = new NonTerminal("Empty or da-effect", typeof(TransientAstNode));
            var emptyBlock       = new NonTerminal("Empty block", typeof(TransientAstNode));

            var daName = new IdentifierTerminal("Durative action name", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var typedList      = new TypedList(p);
            var durationConstr = new DurConstr(p);
            var daGd           = new DaGd(p);
            var daEffect       = new DaEffect(p);

            // RULES

            durActionDef.Rule     = p.ToTerm("(") + durActionDefBase + ")";
            durActionDefBase.Rule = p.ToTerm(":durative-action") + daName + daParameters + daDuration + daConditions + daEffects;
            daParameters.Rule     = p.ToTerm(":parameters") + "(" + typedList + ")";
            daDuration.Rule       = p.ToTerm(":duration") + emptyOrDurConstr;
            daConditions.Rule     = p.ToTerm(":condition") + emptyOrDaGd;
            daEffects.Rule        = p.ToTerm(":effect") + emptyOrDaEffect;

            emptyOrDurConstr.Rule = emptyBlock | durationConstr;
            emptyOrDaGd.Rule      = emptyBlock | daGd;
            emptyOrDaEffect.Rule  = emptyBlock | daEffect;
            emptyBlock.Rule       = p.ToTerm("(") + p.ToTerm(")");

            p.MarkTransient(durActionDef, emptyOrDurConstr, emptyOrDaGd, emptyOrDaEffect);

            Rule = (bForm == BForm.BASE) ? durActionDefBase : durActionDef;
        }
示例#2
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        public DaEffect(MasterGrammar p, BForm bForm) : base(p, bForm)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var daEffect     = new NonTerminal("Da-effect", typeof(TransientAstNode));
            var daEffectBase = new NonTerminal("Da-effect base", typeof(TransientAstNode));

            var andDaEffects      = new NonTerminal("AND expression (da-effects)", typeof(AndDaEffectsAstNode));
            var daEffectsStarList = new NonTerminal("Da-effects star list", typeof(TransientAstNode));

            var forallDaEffect = new NonTerminal("FORALL expression (da-effect)", typeof(ForallDaEffectAstNode));
            var whenTimeEffect = new NonTerminal("WHEN expression (da-effect)", typeof(WhenDaEffectAstNode));

            var timedEffect = new NonTerminal("Timed-effect", typeof(TransientAstNode));

            // USED SUB-TREES

            var timedEffectBase = new TimedEffect(p, BForm.BASE);
            var typedList       = new TypedList(p);
            var daGd            = new DaGd(p);

            // RULES

            daEffect.Rule     = p.ToTerm("(") + daEffectBase + ")";
            daEffectBase.Rule = timedEffectBase | andDaEffects | forallDaEffect | whenTimeEffect;

            andDaEffects.Rule      = p.ToTerm("and") + daEffectsStarList;
            daEffectsStarList.Rule = p.MakeStarRule(daEffectsStarList, daEffect);

            forallDaEffect.Rule = p.ToTerm("forall") + "(" + typedList + ")" + daEffect;
            whenTimeEffect.Rule = p.ToTerm("when") + daGd + timedEffect;

            timedEffect.Rule = p.ToTerm("(") + timedEffectBase + ")";

            p.MarkTransient(daEffect, daEffectBase, timedEffect);

            Rule = (bForm == BForm.BASE) ? daEffectBase : daEffect;
        }