示例#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;
        }
示例#2
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;
        }
        /// <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);
        }
示例#4
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);
        }
        /// <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);
        }
示例#6
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;
        }
        /// <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;
        }
示例#8
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;
        }
示例#9
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;
        }
示例#10
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;
        }
示例#11
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);
        }
示例#12
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;
        }
示例#13
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;
        }
示例#14
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;
        }
示例#15
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;
        }
示例#16
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);
        }
示例#17
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public Domain(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var domain            = new NonTerminal("Domain", typeof(DomainAstNode));
            var domainSections    = new NonTerminal("Domain sections", typeof(TransientAstNode));
            var domainSection     = new NonTerminal("Domain section", typeof(TransientAstNode));
            var domainSectionBase = new NonTerminal("Domain section base", typeof(TransientAstNode));

            var requireDef     = new NonTerminal("Requirements section", typeof(DomainRequirementsAstNode));
            var typesDef       = new NonTerminal("Types section", typeof(DomainTypesAstNode));
            var constantsDef   = new NonTerminal("Constants section", typeof(DomainConstantsAstNode));
            var predicatesDef  = new NonTerminal("Predicates section", typeof(DomainPredicatesAstNode));
            var functionsDef   = new NonTerminal("Functions section", typeof(DomainFunctionsAstNode));
            var constraintsDef = new NonTerminal("Constraints section", typeof(DomainConstraintsAstNode));
            var structureDef   = new NonTerminal("Structure section", typeof(TransientAstNode));

            var requireList = new NonTerminal("Requirements", typeof(TransientAstNode));

            var predicatesList        = new NonTerminal("Predicates list", typeof(TransientAstNode));
            var predicateSkeleton     = new NonTerminal("Predicate skeleton", typeof(TransientAstNode));
            var predicateSkeletonBase = new NonTerminal("Predicate skeleton base", typeof(PredicateSkeletonAstNode));

            var domainName          = new IdentifierTerminal("Domain name", IdentifierType.CONSTANT);
            var requireName         = new IdentifierTerminal("Requirement identifier", IdentifierType.REQUIREMENT);
            var predicateIdentifier = new IdentifierTerminal("Predicate identifier", IdentifierType.CONSTANT);

            // USED SUB-TREES

            var typedListC    = new TypedListC(p);
            var typedListV    = new TypedList(p);
            var funcTypedList = new FunctionTypedList(p);
            var conGd         = new ConGd(p);

            var action      = new Action(p, BForm.BASE);
            var durAction   = new DurAction(p, BForm.BASE);
            var derivedPred = new DerivedPred(p, BForm.BASE);

            // RULES

            domain.Rule         = p.ToTerm("(") + p.ToTerm("define") + "(" + p.ToTerm("domain") + domainName + ")" + domainSections + ")";
            domainSections.Rule = p.MakeStarRule(domainSections, domainSection);

            domainSection.Rule     = p.ToTerm("(") + domainSectionBase + ")";
            domainSectionBase.Rule = requireDef | typesDef | constantsDef | predicatesDef | functionsDef | constraintsDef | structureDef;

            requireDef.Rule  = p.ToTerm(":requirements") + requireList;
            requireList.Rule = p.MakePlusRule(requireList, requireName);

            typesDef.Rule     = p.ToTerm(":types") + typedListC;
            constantsDef.Rule = p.ToTerm(":constants") + typedListC;

            predicatesDef.Rule         = p.ToTerm(":predicates") + predicatesList;
            predicatesList.Rule        = p.MakePlusRule(predicatesList, predicateSkeleton);
            predicateSkeleton.Rule     = p.ToTerm("(") + predicateSkeletonBase + ")";
            predicateSkeletonBase.Rule = predicateIdentifier + typedListV;

            functionsDef.Rule = p.ToTerm(":functions") + funcTypedList;

            constraintsDef.Rule = p.ToTerm(":constraints") + conGd;

            structureDef.Rule = action | durAction | derivedPred;

            p.MarkTransient(domainSection, domainSectionBase, predicateSkeleton, structureDef);

            Rule = domain;
        }
示例#18
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public PrefConGd(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var prefConGd         = new NonTerminal("Pref-con-GD", typeof(TransientAstNode));
            var prefConGdBase     = new NonTerminal("Pref-con-GD base", typeof(TransientAstNode));
            var prefConGdStarList = new NonTerminal("Pref-con-GD star-list", typeof(TransientAstNode));

            var preferencePrefConGdBase = new NonTerminal("Preference expression (pref-con-GD)", typeof(PreferenceConGdAstNode));
            var preferenceNameOrEmpty   = new NonTerminal("Optional preference name", typeof(TransientAstNode));
            var preferenceName          = new IdentifierTerminal("Preference name", IdentifierType.CONSTANT);

            var andPrefConGdBase    = new NonTerminal("AND expression (pref-con-GDs)", typeof(AndConGdAstNode));
            var forallPrefConGdBase = new NonTerminal("FORALL expression (pref-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 conGd     = new ConGd(p);
            var gd        = new Gd(p);

            // RULES

            prefConGd.Rule     = p.ToTerm("(") + prefConGdBase + ")";
            prefConGdBase.Rule = preferencePrefConGdBase | andPrefConGdBase | forallPrefConGdBase | atEndConGdBase | alwaysConGdBase | sometimeConGdBase | withinConGdBase
                                 | atMostOnceConGdBase | sometimeAfterConGdBase | sometimeBeforeConGdBase | alwaysWithinConGdBase | holdDuringConGdBase | holdAfterConGdBase;

            preferencePrefConGdBase.Rule = p.ToTerm("preference") + preferenceNameOrEmpty + conGd;
            preferenceNameOrEmpty.Rule   = preferenceName | p.Empty;

            andPrefConGdBase.Rule    = p.ToTerm("and") + prefConGdStarList;
            forallPrefConGdBase.Rule = p.ToTerm("forall") + "(" + typedList + ")" + prefConGd;

            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;

            prefConGdStarList.Rule = p.MakeStarRule(prefConGdStarList, prefConGd);

            p.MarkTransient(prefConGd, prefConGdBase);

            Rule = prefConGd;
        }
示例#19
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        public Problem(MasterGrammar p) : base(p)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

            var problem             = new NonTerminal("Problem", typeof(ProblemAstNode));
            var definedProblem      = new NonTerminal("Defined problem", typeof(TransientAstNode));
            var correspondingDomain = new NonTerminal("Corresponding domain", typeof(TransientAstNode));

            var problemSections    = new NonTerminal("Problem sections", typeof(TransientAstNode));
            var problemSection     = new NonTerminal("Problem section", typeof(TransientAstNode));
            var problemSectionBase = new NonTerminal("Problem section base", typeof(TransientAstNode));

            var requireDef = new NonTerminal("Requirements section", typeof(ProblemRequirementsAstNode));
            var objectsDef = new NonTerminal("Objects section", typeof(ProblemObjectsAstNode));
            var initDef    = new NonTerminal("Init section", typeof(ProblemInitAstNode));
            var goalDef    = new NonTerminal("Goal section", typeof(ProblemGoalAstNode));
            var constrDef  = new NonTerminal("Constraints section", typeof(ProblemConstraintsAstNode));
            var metricDef  = new NonTerminal("Metric section", typeof(ProblemMetricAstNode));
            var lengthDef  = new NonTerminal("Length section", typeof(ProblemLengthAstNode));

            var requireList           = new NonTerminal("Requirements list", typeof(TransientAstNode));
            var initElemList          = new NonTerminal("Init elements list", typeof(TransientAstNode));
            var optimizationSpecifier = new NonTerminal("Optimization specifier", typeof(TransientAstNode));
            var lengthSpec            = new NonTerminal("Length definition specification", typeof(TransientAstNode));
            var lengthSpecifier       = new NonTerminal("Length specifier", typeof(TransientAstNode));

            var problemName = new IdentifierTerminal("Problem name", IdentifierType.CONSTANT);
            var domainName  = new IdentifierTerminal("Domain name", IdentifierType.CONSTANT);
            var requireName = new IdentifierTerminal("Requirement identifier", IdentifierType.REQUIREMENT);
            var number      = new NumberLiteral("Number");

            // USED SUB-TREES

            var typedListC = new TypedListC(p);
            var initElem   = new InitElem(p);
            var preGd      = new PreGd(p);
            var prefConGd  = new PrefConGd(p);
            var metricExpr = new MetricExpr(p);

            // RULES

            problem.Rule = p.ToTerm("(") + p.ToTerm("define") + definedProblem + correspondingDomain + problemSections + ")";

            definedProblem.Rule      = "(" + p.ToTerm("problem") + problemName + ")";
            correspondingDomain.Rule = "(" + p.ToTerm(":domain") + domainName + ")";
            problemSections.Rule     = p.MakeStarRule(problemSections, problemSection);

            problemSection.Rule     = p.ToTerm("(") + problemSectionBase + ")";
            problemSectionBase.Rule = requireDef | objectsDef | initDef | goalDef | constrDef | metricDef | lengthDef;

            requireDef.Rule = p.ToTerm(":requirements") + requireList;
            objectsDef.Rule = p.ToTerm(":objects") + typedListC;
            initDef.Rule    = p.ToTerm(":init") + initElemList;
            goalDef.Rule    = p.ToTerm(":goal") + preGd;
            constrDef.Rule  = p.ToTerm(":constraints") + prefConGd;
            metricDef.Rule  = p.ToTerm(":metric") + optimizationSpecifier + metricExpr;
            lengthDef.Rule  = p.ToTerm(":length") + lengthSpec + lengthSpec;

            requireList.Rule  = p.MakePlusRule(requireList, requireName);
            initElemList.Rule = p.MakeStarRule(initElemList, initElem);

            optimizationSpecifier.Rule = p.ToTerm("minimize") | p.ToTerm("maximize");

            lengthSpec.Rule      = (p.ToTerm("(") + lengthSpecifier + number + ")") | p.Empty;
            lengthSpecifier.Rule = p.ToTerm(":serial") | p.ToTerm(":parallel");

            p.MarkTransient(problemSection, problemSectionBase, optimizationSpecifier, lengthSpecifier);

            Rule = problem;
        }