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

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

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

            // USED SUB-TREES

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

            // RULES

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

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

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

            return(numericExpr);
        }
Пример #2
0
        /// <summary>
        /// Constructor of the grammar node.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        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;
        }
Пример #3
0
        /// <summary>
        /// Constructs the value or term rule from the specified parameters.
        /// </summary>
        /// <param name="p">Parent master grammar.</param>
        /// <param name="numericExpr">Numeric expression.</param>
        /// <param name="durationVarExpr">Duration variable..</param>
        /// <returns>Value or term grammar rule.</returns>
        public static NonTerminal ConstructValueOrTermRule(MasterGrammar p, NonTerminal numericExpr, NonTerminal durationVarExpr = null)
        {
            // NON-TERMINAL AND TERMINAL SYMBOLS

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

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

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

            // USED SUB-TREES

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

            // RULES

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

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

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

            return(valueOrTerm);
        }