コード例 #1
0
        /// <summary>
        /// Constructs the numeric expression rule from the specified parameters.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="durationVariable">Duration variable.</param>
        /// <returns>Numeric expression grammar rule.</returns>
        public static NonTerminal ConstructNumericExprRule(MasterGrammar p, NonTerminal durationVariable = null)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var numericExpr               = new NonTerminal("Numeric expression", typeof(TransientAstNode));
            var numericExprNumber         = new NonTerminal("Number term for numeric expression", typeof(NumberTermAstNode));
            var numericExprFuncIdentifier = new NonTerminal("Function identifier term for numeric expression", typeof(FunctionTermAstNode));
            var numericExprComplex        = new NonTerminal("Complex numeric expression", typeof(TransientAstNode));
            var numericExprComplexBase    = new NonTerminal("Complex numeric expression base", typeof(TransientAstNode));

            var number             = new NumberLiteral("Number");
            var functionIdentifier = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var termFunctionBase = new FunctionTerm(p, BForm.BASE);
            var numericOpBase    = new NumericOp(p, numericExpr, BForm.BASE);

            // RULES

            numericExpr.Rule               = numericExprNumber | numericExprFuncIdentifier | numericExprComplex;
            numericExprNumber.Rule         = number;
            numericExprFuncIdentifier.Rule = functionIdentifier;
            numericExprComplex.Rule        = p.ToTerm("(") + numericExprComplexBase + ")";
            numericExprComplexBase.Rule    = termFunctionBase | numericOpBase;

            if (durationVariable != null)
            {
                numericExpr.Rule = durationVariable | numericExpr.Rule;
            }

            p.MarkTransient(numericExpr, numericExprComplex, numericExprComplexBase, numericOpBase);

            return(numericExpr);
        }
コード例 #2
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        public TimedEffect(MasterGrammar p, BForm bForm) : base(p, bForm)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

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

            var atTimedEffectBase     = new NonTerminal("AT expression (timed effect)", typeof(AtTimedEffectAstNode));
            var assignTimedEffectBase = new NonTerminal("Assign expression (timed effect)", typeof(AssignTimedEffectAstNode));

            var timeSpecifier       = new NonTerminal("Time specifier", typeof(TransientAstNode));
            var timedCondEffect     = new NonTerminal("Timed cond-Effect", typeof(TransientAstNode));
            var timedCondEffectBase = new NonTerminal("Timed Cond-Effect base", typeof(TransientAstNode));

            var andTimedPEffectsBase = new NonTerminal("AND expression (timed p-effects)", typeof(AndPEffectsAstNode));
            var timedPEffectStarList = new NonTerminal("Timed p-effects star-list", typeof(TransientAstNode));

            var assignTimedEffectOp       = new NonTerminal("Assign expression operator (timed effect)", typeof(TransientAstNode));
            var assignTimedEffectFuncHead = new NonTerminal("Assign expression function head (timed effect)", typeof(TransientAstNode));
            var assignFuncIdentifier      = new NonTerminal("Function identifier for ASSIGN operation", typeof(FunctionTermAstNode));

            var functionIdentifier = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var assignFunctionTerm = new FunctionTerm(p);
            var numericExprT       = new NumericExprT(p);
            var timedPEffect       = new PEffectT(p, BForm.FULL);
            var timedPEffectBase   = new PEffectT(p, BForm.BASE);

            // RULES

            // timed effect
            timedEffect.Rule     = p.ToTerm("(") + timedEffectBase + ")";
            timedEffectBase.Rule = atTimedEffectBase | assignTimedEffectBase;

            atTimedEffectBase.Rule = p.ToTerm("at") + timeSpecifier + timedCondEffect;
            timeSpecifier.Rule     = p.ToTerm("start") | p.ToTerm("end");

            // timed cond-effect ("cond-effect" with assign operation being extended with the use of "f-exp-da")
            timedCondEffect.Rule     = p.ToTerm("(") + timedCondEffectBase + ")";
            timedCondEffectBase.Rule = timedPEffectBase | andTimedPEffectsBase;

            andTimedPEffectsBase.Rule = p.ToTerm("and") + timedPEffectStarList;
            timedPEffectStarList.Rule = p.MakeStarRule(timedPEffectStarList, timedPEffect);

            // timed p-effect
            timedPEffect.Rule = p.ToTerm("(") + timedPEffectBase + ")";

            assignTimedEffectBase.Rule     = assignTimedEffectOp + assignTimedEffectFuncHead + numericExprT;
            assignTimedEffectOp.Rule       = p.ToTerm("increase") | "decrease";
            assignTimedEffectFuncHead.Rule = assignFuncIdentifier | assignFunctionTerm;
            assignFuncIdentifier.Rule      = functionIdentifier;

            p.MarkTransient(timedEffect, timedEffectBase, timedCondEffect, timedCondEffectBase, assignTimedEffectFuncHead);

            Rule = (bForm == BForm.BASE) ? timedEffectBase : timedEffect;
        }
コード例 #3
0
        /// <summary>
        /// Constructs the value or term rule from the specified parameters.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="numericExpr">Numeric expression.</param>
        /// <param name="durationVarExpr">Duration variable..</param>
        /// <returns>Value or term grammar rule.</returns>
        public static NonTerminal ConstructValueOrTermRule(MasterGrammar p, NonTerminal numericExpr, NonTerminal durationVarExpr = null)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var valueOrTerm            = new NonTerminal("Value/term", typeof(TransientAstNode));
            var valueOrTermComplex     = new NonTerminal("Complex value/term", typeof(TransientAstNode));
            var valueOrTermComplexBase = new NonTerminal("Complex value/term base", typeof(TransientAstNode));

            var valueOrTermIdentifier = new NonTerminal("Identifier value/term", typeof(IdentifierTermAstNode));
            var valueOrTermNumber     = new NonTerminal("Number value/term", typeof(NumberTermAstNode));
            var valueOrTermFunction   = new NonTerminal("Functional value/term", typeof(TransientAstNode));
            var valueOrTermNumericOp  = new NonTerminal("Numeric-op value/term", typeof(TransientAstNode));

            var varOrConstOrFuncIdentifier = new IdentifierTerminal("Variable or constant or function identifier", IdentifierType.VARIABLE_OR_CONSTANT);
            var number = new NumberLiteral("Number");

            // USED SUB-TREES

            var numericOpBase    = new NumericOp(p, numericExpr, BForm.BASE);
            var termFunctionBase = new FunctionTerm(p, BForm.BASE);

            // RULES

            valueOrTerm.Rule            = valueOrTermIdentifier | valueOrTermNumber | valueOrTermComplex;
            valueOrTermComplex.Rule     = p.ToTerm("(") + valueOrTermComplexBase + ")";
            valueOrTermComplexBase.Rule = valueOrTermFunction | valueOrTermNumericOp;
            valueOrTermIdentifier.Rule  = varOrConstOrFuncIdentifier;
            valueOrTermNumber.Rule      = number;
            valueOrTermFunction.Rule    = termFunctionBase;
            valueOrTermNumericOp.Rule   = numericOpBase;

            if (durationVarExpr != null)
            {
                valueOrTerm.Rule |= durationVarExpr;
            }

            p.MarkTransient(valueOrTerm, valueOrTermComplex, valueOrTermComplexBase, valueOrTermFunction, valueOrTermNumericOp, numericOpBase);

            return(valueOrTerm);
        }
コード例 #4
0
        /// <summary>
        /// Constructs the primitive effect rule from the specified parameters.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        /// <param name="valueOrTermForAssign">Value or term for an assignment.</param>
        /// <param name="numericExprForAssign">Numeric expression for an assignment.</param>
        /// <returns>Primitive effect grammar rule.</returns>
        public static NonTerminal ConstructPEffectRule(MasterGrammar p, BForm bForm, NonTerminal valueOrTermForAssign, NonTerminal numericExprForAssign)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var pEffect     = new NonTerminal("P-effect", typeof(TransientAstNode));
            var pEffectBase = new NonTerminal("P-effect base", typeof(TransientAstNode));

            var atomicFormulaPEffect     = new NonTerminal("Atomic formula (p-effect)", typeof(TransientAstNode));
            var atomicFormulaPEffectBase = new NonTerminal("Atomic formula base (p-effect)", typeof(TransientAstNode));

            var predicatePEffectBase = new NonTerminal("Predicate (p-effect)", typeof(PredicatePEffectAstNode));
            var predicateArguments   = new NonTerminal("Predicate arguments", typeof(TransientAstNode));

            var equalsOpPEffectBase = new NonTerminal("Equals-op (p-effect)", typeof(EqualsOpPEffectAstNode));
            var notPEffectBase      = new NonTerminal("NOT expression (p-effect)", typeof(NotPEffectAstNode));

            var assignPEffectBase = new NonTerminal("General assign expression (p-effect)", typeof(TransientAstNode));
            var objOrNumAssign    = new NonTerminal("Numeric or object assign operator (p-effect)", typeof(AssignPEffectAstNode));
            var onlyNumAssign     = new NonTerminal("Numeric assign operator (p-effect)", typeof(AssignPEffectAstNode));

            var numAssignOp         = new NonTerminal("Assign operation", typeof(TransientAstNode));
            var assignOpArg1        = new NonTerminal("Assign operation first argument", typeof(TransientAstNode));
            var assignOpArg2        = new NonTerminal("Assign operation second argument", typeof(TransientAstNode));
            var assignOpArg2Num     = new NonTerminal("Assign operation second numeric argument", typeof(TransientAstNode));
            var assignOpFuncIdentif = new NonTerminal("Function identifier for ASSIGN operation", typeof(FunctionTermAstNode));
            var undefinedFuncVal    = new NonTerminal("Undefined function value", typeof(UndefinedFuncValAstNode));

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

            // USED SUB-TREES

            var valueOrTerm          = new ValueOrTerm(p);
            var predFuncTermFunction = new FunctionTerm(p);
            var term = new Term(p);

            // RULES

            pEffect.Rule     = p.ToTerm("(") + pEffectBase + ")";
            pEffectBase.Rule = atomicFormulaPEffectBase | notPEffectBase | assignPEffectBase;

            atomicFormulaPEffect.Rule     = p.ToTerm("(") + atomicFormulaPEffectBase + ")";
            atomicFormulaPEffectBase.Rule = predicatePEffectBase | equalsOpPEffectBase;

            predicatePEffectBase.Rule = predicateIdentifier + predicateArguments;
            predicateArguments.Rule   = p.MakeStarRule(predicateArguments, term);

            equalsOpPEffectBase.Rule = p.ToTerm("=") + valueOrTerm + valueOrTerm;
            notPEffectBase.Rule      = p.ToTerm("not") + atomicFormulaPEffect;

            assignPEffectBase.Rule = objOrNumAssign | onlyNumAssign;
            objOrNumAssign.Rule    = p.ToTerm("assign") + assignOpArg1 + assignOpArg2;
            onlyNumAssign.Rule     = numAssignOp + assignOpArg1 + assignOpArg2Num;

            assignOpArg1.Rule        = assignOpFuncIdentif | predFuncTermFunction;
            assignOpArg2.Rule        = undefinedFuncVal | valueOrTermForAssign;
            assignOpFuncIdentif.Rule = functionIdentifier;
            assignOpArg2Num.Rule     = numericExprForAssign;

            numAssignOp.Rule      = p.ToTerm("scale-up") | "scale-down" | "increase" | "decrease";
            undefinedFuncVal.Rule = p.ToTerm("undefined");

            p.MarkTransient(pEffect, pEffectBase, atomicFormulaPEffect, atomicFormulaPEffectBase, assignPEffectBase, assignOpArg1, assignOpArg2, assignOpArg2Num);

            return((bForm == BForm.BASE) ? pEffectBase : pEffect);
        }