Exemplo n.º 1
0
        /// <summary>
        /// Parses the PDDL input file based on the given grammar. The parse tree is then converted into the AST.
        /// </summary>
        /// <typeparam name="TargetAst">Target AST root node type.</typeparam>
        /// <param name="inputFilePath">Input PDDL file.</param>
        /// <param name="grammar">Specific grammar to match the input data.</param>
        /// <returns>Root node of the created AST.</returns>
        public static TargetAst ParseAndCreateAst <TargetAst>(string inputFilePath, Grammar.MasterGrammar grammar) where TargetAst : BaseAstNode
        {
            string loadedString = LoadFileIntoString(inputFilePath);

            if (string.IsNullOrEmpty(loadedString))
            {
                throw new LoadingException($"Input file {Path.GetFileName(inputFilePath)} is empty or corrupted.");
            }

            Parser    parser = new Parser(grammar);
            ParseTree tree   = parser.Parse(loadedString);

            if (tree.HasErrors())
            {
                var    errorItem = tree.ParserMessages.Find(x => x.Level == Irony.ErrorLevel.Error);
                string message   = $"{errorItem.Message} (file: {Path.GetFileName(inputFilePath)}, line: {errorItem.Location.Line + 1}, column: {errorItem.Location.Column + 1})";

                throw new LoadingException(message);
            }

            var treeRoot = tree.Root.AstNode as TargetAst;

            if (treeRoot == null)
            {
                throw new LoadingException($"AST tree creation failed during loading {Path.GetFileName(inputFilePath)}.");
            }

            return(treeRoot);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs the function term rule from the specified parameters.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        /// <param name="identifierType">Identifier type.</param>
        /// <returns>Function term grammar rule.</returns>
        public static NonTerminal ConstructFunctionTermRule(MasterGrammar p, BForm bForm, IdentifierType identifierType)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var functionTerm      = new NonTerminal("Functional term", typeof(TransientAstNode));
            var functionTermBase  = new NonTerminal("Functional term base", typeof(FunctionTermAstNode));
            var functionArguments = new NonTerminal("Functional term arguments", typeof(TransientAstNode));

            var argTerm           = new NonTerminal("Term", typeof(TransientAstNode));
            var argTermIdentifier = new NonTerminal("Identifier term", typeof(IdentifierTermAstNode));

            var functionIdentifier   = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT);
            var varOrConstIdentifier = new IdentifierTerminal("Variable or constant identifier", identifierType);

            // RULES

            functionTerm.Rule      = p.ToTerm("(") + functionTermBase + ")";
            functionTermBase.Rule  = functionIdentifier + functionArguments;
            functionArguments.Rule = p.MakeStarRule(functionArguments, argTerm);

            argTerm.Rule           = argTermIdentifier | functionTerm;
            argTermIdentifier.Rule = varOrConstIdentifier;

            p.MarkTransient(functionTerm, argTerm);

            return((bForm == BForm.BASE) ? functionTermBase : functionTerm);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public NumericExprT(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var numericExprT        = new NonTerminal("Timed numeric expression", typeof(TransientAstNode));
            var numericExprTSimple  = new NonTerminal("Simple timed numeric expression", typeof(TimedNumericExpressionAstNode));
            var numericExprTComplex = new NonTerminal("Product of timed numeric expression", typeof(TransientAstNode));

            var numericExprTProduct         = new NonTerminal("Product variant of timed numeric expression", typeof(TimedNumericExpressionAstNode));
            var numericExprTProductVariant  = new NonTerminal("Either product variant of timed numeric expression", typeof(TransientAstNode));
            var numericExprTProductVariant1 = new NonTerminal("Product variant 1 of timed numeric expression", typeof(TransientAstNode));
            var numericExprTProductVariant2 = new NonTerminal("Product variant 2 of timed numeric expression", typeof(TransientAstNode));

            // USED SUB-TREES

            var numericExpr = new NumericExpr(p);

            // RULES

            numericExprT.Rule        = numericExprTSimple | numericExprTComplex;
            numericExprTSimple.Rule  = p.ToTerm("#t");
            numericExprTComplex.Rule = p.ToTerm("(") + numericExprTProduct + ")";

            numericExprTProduct.Rule         = p.ToTerm("*") + numericExprTProductVariant;
            numericExprTProductVariant.Rule  = numericExprTProductVariant1 | numericExprTProductVariant2;
            numericExprTProductVariant1.Rule = p.ToTerm("#t") + numericExpr;
            numericExprTProductVariant2.Rule = numericExpr + "#t";

            p.MarkTransient(numericExprT, numericExprTComplex, numericExprTProductVariant);

            Rule = numericExprT;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public Term(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var term           = new NonTerminal("Term", typeof(TransientAstNode));
            var termIdentifier = new NonTerminal("Identifier term", typeof(IdentifierTermAstNode));
            var termFunction   = new NonTerminal("Functional term", typeof(TransientAstNode));

            var termFunctionBase  = new NonTerminal("Functional term base", typeof(FunctionTermAstNode));
            var functionArguments = new NonTerminal("Functional term arguments", typeof(TransientAstNode));

            var functionIdentifier   = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT);
            var varOrConstIdentifier = new IdentifierTerminal("Variable or constant identifier", IdentifierType.VARIABLE_OR_CONSTANT);

            // RULES

            term.Rule           = termIdentifier | termFunction;
            termIdentifier.Rule = varOrConstIdentifier;
            termFunction.Rule   = p.ToTerm("(") + termFunctionBase + ")";

            termFunctionBase.Rule  = functionIdentifier + functionArguments;
            functionArguments.Rule = p.MakeStarRule(functionArguments, term);

            p.MarkTransient(term, termFunction);

            Rule = term;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructs the typed list rule from the specified parameters.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="itemIdentifierType">Item identifier type.</param>
        /// <returns>Typed list grammar rule.</returns>
        public static NonTerminal ConstructTypedListRule(MasterGrammar p, IdentifierType itemIdentifierType)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var typedList       = new NonTerminal("Typed list", typeof(TypedListAstNode));
            var singleTypedList = new NonTerminal("Single typed list", typeof(TransientAstNode));
            var typeDeclaration = new NonTerminal("Type declaration", typeof(TransientAstNode));

            var type            = new NonTerminal("Type", typeof(TransientAstNode));
            var typePlusList    = new NonTerminal("Type list", typeof(TransientAstNode));
            var identifiersList = new NonTerminal("Typed list identifiers", typeof(TransientAstNode));

            var itemIdentifier = new IdentifierTerminal("Item identifier", itemIdentifierType);
            var typeIdentifier = new IdentifierTerminal("Type identifier", IdentifierType.CONSTANT);

            // RULES

            typedList.Rule       = p.MakeStarRule(typedList, singleTypedList);
            singleTypedList.Rule = identifiersList + typeDeclaration;
            identifiersList.Rule = p.MakeStarRule(identifiersList, itemIdentifier);
            typeDeclaration.Rule = p.Empty | ("-" + type);

            type.Rule         = typeIdentifier | ("(" + p.ToTerm("either") + typePlusList + ")");
            typePlusList.Rule = p.MakePlusRule(typePlusList, typeIdentifier);

            return(typedList);
        }
Exemplo n.º 8
0
        /// <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;
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public NumericExprDa(MasterGrammar p) : base(p)
        {
            var durationVar = new NonTerminal("Duration variable term (duration numeric expression)", typeof(DurationVariableTermAstNode))
            {
                Rule = p.ToTerm("?duration")
            };

            Rule = NumericExpr.ConstructNumericExprRule(p, durationVar);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Constructor of the base grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Form specification.</param>
        /// <param name="subExpression">Sub-expression specification.</param>
        protected BaseGrammarNode(MasterGrammar p, BForm bForm = BForm.FULL, NonTerminal subExpression = null) : base("Base grammar node", typeof(TransientAstNode))
        {
            P             = p;
            BForm         = bForm;
            SubExpression = subExpression;

            p.MarkTransient(this);
            Rule = null;
        }
Exemplo n.º 12
0
        /// <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;
        }
Exemplo n.º 13
0
        /// <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;
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public DurConstr(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var durationConstr     = new NonTerminal("Duration-constraint", typeof(TransientAstNode));
            var durationConstrBase = new NonTerminal("Duration-constraint base", typeof(TransientAstNode));

            var simpleDurationConstr     = new NonTerminal("Simple duration-constraint", typeof(TransientAstNode));
            var simpleDurationConstrBase = new NonTerminal("Simple duration-constraint base", typeof(TransientAstNode));

            var andSimpleDurationConstrsBase  = new NonTerminal("AND expression (duration-constraints)", typeof(AndSimpleDurationConstraintsAstNode));
            var simpleDurationConstrsPlusList = new NonTerminal("Simple duration constraints plus-list", typeof(TransientAstNode));

            var atSimpleDurationConstr     = new NonTerminal("AT expression (duration-constraint)", typeof(AtSimpleDurationConstraintAstNode));
            var compOpSimpleDurationConstr = new NonTerminal("CompareOp (duration-constraint)", typeof(CompOpSimpleDurationConstraintAstNode));
            var timeSpecifier = new NonTerminal("Time specifier", typeof(TransientAstNode));

            var durCompareOp  = new NonTerminal("Compare operator for duration-constraint", typeof(TransientAstNode));
            var durCompareVal = new NonTerminal("Value for duration-constraint", typeof(TransientAstNode));

            // USED SUB-TREES

            var numericExpr = new NumericExpr(p);

            // RULES

            durationConstr.Rule     = p.ToTerm("(") + durationConstrBase + ")";
            durationConstrBase.Rule = andSimpleDurationConstrsBase | simpleDurationConstrBase;

            andSimpleDurationConstrsBase.Rule  = p.ToTerm("and") + simpleDurationConstrsPlusList;
            simpleDurationConstrsPlusList.Rule = p.MakeStarRule(simpleDurationConstrsPlusList, simpleDurationConstr);

            simpleDurationConstr.Rule     = p.ToTerm("(") + simpleDurationConstrBase + ")";
            simpleDurationConstrBase.Rule = atSimpleDurationConstr | compOpSimpleDurationConstr;

            atSimpleDurationConstr.Rule     = p.ToTerm("at") + timeSpecifier + simpleDurationConstr;
            compOpSimpleDurationConstr.Rule = durCompareOp + "?duration" + durCompareVal;
            timeSpecifier.Rule = p.ToTerm("start") | p.ToTerm("end");

            durCompareOp.Rule  = p.ToTerm("<=") | ">=" | "=";
            durCompareVal.Rule = numericExpr;

            p.MarkTransient(durationConstr, durationConstrBase, simpleDurationConstr, simpleDurationConstrBase, durCompareVal);

            Rule = durationConstr;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public Gd(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

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

            var andGdBase      = new NonTerminal("AND expression (GDs)", typeof(AndGdAstNode));
            var orGdBase       = new NonTerminal("OR expression (GD)", typeof(OrGdAstNode));
            var notGdBase      = new NonTerminal("NOT expression (GD)", typeof(NotGdAstNode));
            var implyGdBase    = new NonTerminal("IMPLY expression (GD)", typeof(ImplyGdAstNode));
            var existsGdBase   = new NonTerminal("EXISTS expression (GD)", typeof(ExistsGdAstNode));
            var forallGdBase   = new NonTerminal("FORALL expression (GD)", typeof(ForallGdAstNode));
            var equalsOpGdBase = new NonTerminal("Equals operator (GD)", typeof(EqualsOpGdAstNode));
            var numCompGdBase  = new NonTerminal("Numeric comparison expression (GD)", typeof(NumCompGdAstNode));
            var binaryComparer = new NonTerminal("Binary comparer", typeof(TransientAstNode));

            // USED SUB-TREES

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

            // RULES

            gd.Rule     = p.ToTerm("(") + gdBase + ")";
            gdBase.Rule = andGdBase | orGdBase | notGdBase | implyGdBase | existsGdBase | forallGdBase | predicateGdBase | equalsOpGdBase | numCompGdBase;

            andGdBase.Rule      = p.ToTerm("and") + gdStarList;
            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;
            forallGdBase.Rule   = p.ToTerm("forall") + "(" + typedList + ")" + gd;
            equalsOpGdBase.Rule = p.ToTerm("=") + valueOrTerm + valueOrTerm;
            numCompGdBase.Rule  = binaryComparer + numericExpr + numericExpr;
            binaryComparer.Rule = p.ToTerm(">") | "<" | ">=" | "<=";

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

            p.MarkTransient(gd, gdBase, binaryComparer);

            Rule = gd;
        }
Exemplo n.º 17
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;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public MetricExpr(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var metricExpr               = new NonTerminal("Metric expression", typeof(TransientAstNode));
            var metricExprTimeConst      = new NonTerminal("Total-time const (metric expression)", typeof(FunctionTermAstNode));
            var metricExprNumber         = new NonTerminal("Number term (metric expression)", typeof(NumberTermAstNode));
            var metricExprFuncIdentifier = new NonTerminal("Function term (metric expression)", typeof(FunctionTermAstNode));
            var metricExprComplex        = new NonTerminal("Complex metric expression", typeof(TransientAstNode));
            var metricExprComplexBase    = new NonTerminal("Complex metric expression base", typeof(TransientAstNode));

            var metricExprViolatedBase = new NonTerminal("Preference violation expression (metric expression)", typeof(MetricPreferenceViolationAstNode));
            var metricExprFunctionBase = new NonTerminal("Function term (metric expression)", typeof(FunctionTermAstNode));
            var metricOpBase           = new NonTerminal("Numeric operation base (metric expression)", typeof(TransientAstNode));

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

            // USED SUB-TREES

            var functionTerm = new FunctionTermC(p, BForm.BASE);
            var numericOp    = new NumericOp(p, metricExpr, BForm.BASE);

            // RULES

            metricExpr.Rule = metricExprTimeConst | metricExprNumber | metricExprFuncIdentifier | metricExprComplex;

            metricExprTimeConst.Rule      = p.ToTerm("total-time");
            metricExprNumber.Rule         = number;
            metricExprFuncIdentifier.Rule = functionIdentifier;
            metricExprComplex.Rule        = p.ToTerm("(") + metricExprComplexBase + ")";
            metricExprComplexBase.Rule    = metricExprViolatedBase | metricExprFunctionBase | metricOpBase;

            metricExprViolatedBase.Rule = p.ToTerm("is-violated") + preferenceName;
            metricExprFunctionBase.Rule = functionTerm;
            metricOpBase.Rule           = numericOp;

            p.MarkTransient(metricExpr, metricExprComplex, metricExprComplexBase, metricExprFunctionBase, metricOpBase);

            Rule = metricExpr;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public FunctionTypedList(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var functionsTypedList = new NonTerminal("Functions typed list", typeof(FunctionTypedListAstNode));

            var typedFuncBlock = new NonTerminal("Typed functions block", typeof(TransientAstNode));
            var funcBlock      = new NonTerminal("Functions block", typeof(TransientAstNode));

            var singleFunction     = new NonTerminal("Single function", typeof(TransientAstNode));
            var singleFunctionBase = new NonTerminal("Single function base", typeof(TransientAstNode));
            var functionIdentifier = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT);

            var typeDeclaration = new NonTerminal("Type declaration", typeof(TransientAstNode));

            var type           = new NonTerminal("Type", typeof(TransientAstNode));
            var typePlusList   = new NonTerminal("Type list", typeof(TransientAstNode));
            var typeIdentifier = new IdentifierTerminal("Type identifier", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var typedList = new TypedList(p);

            // RULES

            functionsTypedList.Rule = p.MakeStarRule(functionsTypedList, typedFuncBlock);
            typedFuncBlock.Rule     = funcBlock + typeDeclaration;

            funcBlock.Rule          = p.MakePlusRule(funcBlock, singleFunction);
            singleFunction.Rule     = p.ToTerm("(") + singleFunctionBase + ")";
            singleFunctionBase.Rule = functionIdentifier + typedList;

            typeDeclaration.Rule = p.Empty | ("-" + type);
            type.Rule            = typeIdentifier | ("(" + p.ToTerm("either") + typePlusList + ")");
            typePlusList.Rule    = p.MakePlusRule(typePlusList, typeIdentifier);

            p.MarkTransient(singleFunction);

            Rule = functionsTypedList;
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        public Action(MasterGrammar p, BForm bForm) : base(p, bForm)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var actionDef           = new NonTerminal("Action definition", typeof(TransientAstNode));
            var actionDefBase       = new NonTerminal("Action definition", typeof(DomainActionAstNode));
            var actionParameters    = new NonTerminal("Action parameters", typeof(TransientAstNode));
            var actionPreconditions = new NonTerminal("Action preconditions", typeof(TransientAstNode));
            var actionEffects       = new NonTerminal("Action effects", typeof(TransientAstNode));

            var emptyOrPreGd  = new NonTerminal("Empty or pre-GD", typeof(TransientAstNode));
            var emptyOrEffect = new NonTerminal("Empty or effect", typeof(TransientAstNode));
            var emptyBlock    = new NonTerminal("Empty block", typeof(TransientAstNode));

            var actionName = new IdentifierTerminal("Action name", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var typedList = new TypedList(p);
            var preGd     = new PreGd(p);
            var effect    = new Effect(p);

            // RULES

            actionDef.Rule           = p.ToTerm("(") + actionDefBase + ")";
            actionDefBase.Rule       = p.ToTerm(":action") + actionName + actionParameters + actionPreconditions + actionEffects;
            actionParameters.Rule    = p.ToTerm(":parameters") + "(" + typedList + ")";
            actionPreconditions.Rule = (p.ToTerm(":precondition") + emptyOrPreGd) | p.Empty;
            actionEffects.Rule       = (p.ToTerm(":effect") + emptyOrEffect) | p.Empty;

            emptyOrPreGd.Rule  = emptyBlock | preGd;
            emptyOrEffect.Rule = emptyBlock | effect;
            emptyBlock.Rule    = p.ToTerm("(") + p.ToTerm(")");

            p.MarkTransient(actionDef, emptyOrPreGd, emptyOrEffect);

            Rule = (bForm == BForm.BASE) ? actionDefBase : actionDef;
        }
Exemplo n.º 22
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;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="bForm">Block form.</param>
        public PredicateGd(MasterGrammar p, BForm bForm) : base(p, bForm)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var predicate           = new NonTerminal("Predicate GD", typeof(TransientAstNode));
            var predicateBase       = new NonTerminal("Predicate GD base", typeof(PredicateGdAstNode));
            var predicateArguments  = new NonTerminal("Predicate arguments", typeof(TransientAstNode));
            var predicateIdentifier = new IdentifierTerminal("Predicate identifier", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var term = new Term(p);

            // RULES

            predicate.Rule          = p.ToTerm("(") + predicateBase + ")";
            predicateBase.Rule      = predicateIdentifier + predicateArguments;
            predicateArguments.Rule = p.MakeStarRule(predicateArguments, term);

            p.MarkTransient(predicate, term);

            Rule = (bForm == BForm.BASE) ? predicateBase : predicate;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="numericExpression">Numeric expression type used within the numeric operation</param>
        /// <param name="bForm">Block form.</param>
        public NumericOp(MasterGrammar p, NonTerminal numericExpression, BForm bForm) : base(p, bForm, numericExpression)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var numericOp     = new NonTerminal("Numeric operation", typeof(TransientAstNode));
            var numericOpBase = new NonTerminal("Numeric operation base", typeof(TransientAstNode));

            var multiOp          = new NonTerminal("Multiary operation", typeof(NumericOpAstNode));
            var multiOperator    = new NonTerminal("Multiary operator", typeof(TransientAstNode));
            var multiOpArguments = new NonTerminal("Multiary operation arguments", typeof(TransientAstNode));

            var binaryOp          = new NonTerminal("Binary operation", typeof(NumericOpAstNode));
            var binaryUnaryOp     = new NonTerminal("Binary or unary operation", typeof(NumericOpAstNode));
            var binaryOpSecondArg = new NonTerminal("Second argument of binary operation", typeof(TransientAstNode));

            // USED SUB-TREES

            var numericExpr = SubExpression; // passed as a parameter

            // RULES

            numericOp.Rule     = p.ToTerm("(") + numericOpBase + ")";
            numericOpBase.Rule = multiOp | binaryOp | binaryUnaryOp;

            multiOp.Rule          = multiOperator + numericExpr + multiOpArguments; // at least two numeric args
            multiOperator.Rule    = p.ToTerm("*") | "+";
            multiOpArguments.Rule = p.MakePlusRule(multiOpArguments, numericExpr);

            binaryOp.Rule          = p.ToTerm("/") + numericExpr + numericExpr;       // the only binary is division
            binaryUnaryOp.Rule     = p.ToTerm("-") + numericExpr + binaryOpSecondArg; // unary/binary minus
            binaryOpSecondArg.Rule = numericExpr | p.Empty;

            p.MarkTransient(numericOp, numericOpBase, multiOperator, binaryOpSecondArg);

            Rule = (bForm == BForm.BASE) ? numericOpBase : numericOp;
        }
Exemplo n.º 25
0
 /// <summary>
 /// Constructor of the grammar node.
 /// </summary>
 /// <param name="p">Parent master grammar.</param>
 public DaEffect(MasterGrammar p) : this(p, BForm.FULL)
 {
 }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
 /// <summary>
 /// Constructor of the grammar node.
 /// </summary>
 /// <param name="p">Parent master grammar.</param>
 public TypedList(MasterGrammar p) : base(p)
 {
     Rule = ConstructTypedListRule(p, IdentifierType.VARIABLE);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Constructor of the grammar node.
 /// </summary>
 /// <param name="p">Parent master grammar.</param>
 /// <param name="bForm">Block form.</param>
 public PEffect(MasterGrammar p, BForm bForm) : base(p, bForm)
 {
     Rule = ConstructPEffectRule(p, bForm, new ValueOrTerm(p), new NumericExpr(p));
 }
Exemplo n.º 29
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public InitElem(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var initElem     = new NonTerminal("Init element", typeof(TransientAstNode));
            var initElemBase = new NonTerminal("Init element", typeof(TransientAstNode));

            var predicateInitElemBase = new NonTerminal("Predicate (init elem)", typeof(PredicateInitElemAstNode));
            var predicateArguments    = new NonTerminal("Predicate arguments", typeof(TransientAstNode));

            var equalsInitElemBase = new NonTerminal("EQUALS expression (init elem)", typeof(EqualsOpInitElemAstNode));
            var equalsFirstArg     = new NonTerminal("EQUALS expression first argument", typeof(TransientAstNode));
            var equalsSecondArg    = new NonTerminal("EQUALS expression second argument", typeof(TransientAstNode));

            var functionEqualsArg = new NonTerminal("EQUALS expression function argument", typeof(TransientAstNode));
            var functionBase      = new NonTerminal("Function term", typeof(FunctionTermAstNode));
            var functionArguments = new NonTerminal("Function arguments", typeof(TransientAstNode));

            var constOrFuncTerm = new NonTerminal("Const/func identifier term", typeof(IdentifierTermAstNode));
            var constTerm       = new NonTerminal("Const identifier term", typeof(IdentifierTermAstNode));
            var numberTerm      = new NonTerminal("Number term", typeof(NumberTermAstNode));

            var notInitElemBase          = new NonTerminal("NOT expression (init elem)", typeof(NotInitElemAstNode));
            var notArgument              = new NonTerminal("NOT expression argument", typeof(TransientAstNode));
            var notArgumentBase          = new NonTerminal("NOT expression argument", typeof(TransientAstNode));
            var equalsSimpleInitElemBase = new NonTerminal("EQUALS expression (init elem)", typeof(EqualsOpInitElemAstNode));

            var atPredicateInitElemBase  = new NonTerminal("Predicate (init elem)", typeof(PredicateInitElemAstNode));
            var atExpressionInitElemBase = new NonTerminal("AT expression (init elem)", typeof(AtInitElemAstNode));
            var atArgument     = new NonTerminal("AT expression argument", typeof(TransientAstNode));
            var atArgumentBase = new NonTerminal("AT expression argument", typeof(TransientAstNode));

            var predicateIdentifier   = new IdentifierTerminal("Predicate identifier", IdentifierType.CONSTANT);
            var functionIdentifier    = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT);
            var constOrFuncIdentifier = new IdentifierTerminal("Constant or function identifier", IdentifierType.CONSTANT);
            var constIdentifier       = new IdentifierTerminal("Constant identifier", IdentifierType.CONSTANT);
            var number = new NumberLiteral("Number");

            // RULES

            initElem.Rule     = p.ToTerm("(") + initElemBase + ")";
            initElemBase.Rule = predicateInitElemBase | equalsInitElemBase | notInitElemBase | atPredicateInitElemBase | atExpressionInitElemBase;

            predicateInitElemBase.Rule = predicateIdentifier + predicateArguments;
            predicateArguments.Rule    = p.MakeStarRule(predicateArguments, constIdentifier);

            equalsInitElemBase.Rule = p.ToTerm("=") + equalsFirstArg + equalsSecondArg;
            equalsFirstArg.Rule     = constOrFuncTerm | functionEqualsArg;
            equalsSecondArg.Rule    = constTerm | numberTerm;

            functionEqualsArg.Rule = p.ToTerm("(") + functionBase + ")";
            functionBase.Rule      = functionIdentifier + functionArguments;
            functionArguments.Rule = p.MakeStarRule(functionArguments, constTerm);

            constOrFuncTerm.Rule = constOrFuncIdentifier;
            constTerm.Rule       = constIdentifier;
            numberTerm.Rule      = number;

            notInitElemBase.Rule          = p.ToTerm("not") + notArgument;
            notArgument.Rule              = p.ToTerm("(") + notArgumentBase + ")";
            notArgumentBase.Rule          = predicateInitElemBase | equalsSimpleInitElemBase;
            equalsSimpleInitElemBase.Rule = p.ToTerm("=") + constTerm + constTerm;

            atPredicateInitElemBase.Rule  = p.ToTerm("at") + predicateArguments;
            atExpressionInitElemBase.Rule = p.ToTerm("at") + number + atArgument;
            atArgument.Rule     = p.ToTerm("(") + atArgumentBase + ")";
            atArgumentBase.Rule = predicateInitElemBase | equalsSimpleInitElemBase | notInitElemBase;

            p.MarkTransient(initElem, initElemBase, equalsFirstArg, equalsSecondArg, functionEqualsArg, notArgument, notArgumentBase, atArgument, atArgumentBase);

            Rule = initElem;
        }
Exemplo n.º 30
0
 /// <summary>
 /// Constructor of the grammar node.
 /// </summary>
 /// <param name="p">Parent master grammar.</param>
 public DerivedPred(MasterGrammar p) : this(p, BForm.FULL)
 {
 }