···15*/
16package com.ezylang.evalex.config;
1718-import com.ezylang.evalex.Expression;
19import com.ezylang.evalex.data.DataAccessorIfc;
20import com.ezylang.evalex.data.EvaluationValue;
21import com.ezylang.evalex.data.conversion.DefaultEvaluationValueConverter;
···32import com.ezylang.evalex.operators.OperatorIfc;
33import com.ezylang.evalex.operators.arithmetic.*;
34import com.ezylang.evalex.operators.booleans.*;
35-import com.ezylang.evalex.parser.ASTNode;
36import com.ezylang.evalex.parser.ExpressionParser;
37import java.math.BigDecimal;
38import java.math.MathContext;
···123 /**
124 * Default constants will be added automatically to each expression and can be used in expression
125 * evaluation. <br>
126- * It is assumed that constant will <b>never</b> change. {@link
127- * ExpressionParser#inlineASTNode(Expression, ASTNode)} relies on this assumption!
128 */
129 @Builder.Default
130 private final Map<String, EvaluationValue> constants =
···15*/
16package com.ezylang.evalex.config;
17018import com.ezylang.evalex.data.DataAccessorIfc;
19import com.ezylang.evalex.data.EvaluationValue;
20import com.ezylang.evalex.data.conversion.DefaultEvaluationValueConverter;
···31import com.ezylang.evalex.operators.OperatorIfc;
32import com.ezylang.evalex.operators.arithmetic.*;
33import com.ezylang.evalex.operators.booleans.*;
034import com.ezylang.evalex.parser.ExpressionParser;
35import java.math.BigDecimal;
36import java.math.MathContext;
···121 /**
122 * Default constants will be added automatically to each expression and can be used in expression
123 * evaluation. <br>
124+ * It is assumed that constant will <b>never</b> change.
0125 */
126 @Builder.Default
127 private final Map<String, EvaluationValue> constants =
···1718import com.ezylang.evalex.EvaluationContext;
19import com.ezylang.evalex.EvaluationException;
20-import com.ezylang.evalex.Expression;
21import com.ezylang.evalex.data.EvaluationValue;
22-import com.ezylang.evalex.data.types.ExpressionNodeValue;
23-import com.ezylang.evalex.parser.ASTNode;
24-import com.ezylang.evalex.parser.InlinedASTNode;
25import com.ezylang.evalex.parser.Token;
26import java.util.List;
27-import org.jetbrains.annotations.Nullable;
2829/**
30 * Interface that is required for all functions in a function dictionary for evaluation of
···92 default int getCountOfNonVarArgParameters() {
93 int numOfParameters = getFunctionParameterDefinitions().size();
94 return hasVarArgs() ? numOfParameters - 1 : numOfParameters;
95- }
96-97- default boolean forceInline() {
98- return false;
99- }
100-101- default @Nullable EvaluationValue inlineFunction(
102- Expression expression, Token token, ASTNode... parameters) throws EvaluationException {
103-104- EvaluationValue[] parsed;
105- if (parameters.length == 0) {
106- parsed = EvaluationValue.EMPTY;
107- } else {
108- parsed = new EvaluationValue[parameters.length];
109- for (int i = 0; i < parameters.length; i++) {
110- if (token.getFunctionDefinition().isParameterLazy(i)) {
111- parsed[i] = ExpressionNodeValue.of(parameters[i]);
112- } else {
113- parsed[i] = ((InlinedASTNode) parameters[i]).value();
114- }
115- }
116- }
117-118- this.validatePreEvaluation(token, parsed);
119- return this.evaluate(EvaluationContext.builder(expression).build(), token, parsed);
120 }
121}
···1718import com.ezylang.evalex.EvaluationContext;
19import com.ezylang.evalex.EvaluationException;
020import com.ezylang.evalex.data.EvaluationValue;
00021import com.ezylang.evalex.parser.Token;
22import java.util.List;
02324/**
25 * Interface that is required for all functions in a function dictionary for evaluation of
···87 default int getCountOfNonVarArgParameters() {
88 int numOfParameters = getFunctionParameterDefinitions().size();
89 return hasVarArgs() ? numOfParameters - 1 : numOfParameters;
000000000000000000000000090 }
91}
···16package com.ezylang.evalex.functions.basic;
1718import com.ezylang.evalex.EvaluationContext;
19-import com.ezylang.evalex.Expression;
20import com.ezylang.evalex.data.EvaluationValue;
21import com.ezylang.evalex.functions.AbstractFunction;
22-import com.ezylang.evalex.parser.ASTNode;
23import com.ezylang.evalex.parser.Token;
24import java.security.SecureRandom;
25-import org.jetbrains.annotations.Nullable;
2627/** Random function produces a random value between 0 and 1. */
28public class RandomFunction extends AbstractFunction {
···34 SecureRandom secureRandom = new SecureRandom();
3536 return context.expression().convertDoubleValue(secureRandom.nextDouble());
37- }
38-39- @Override
40- public @Nullable EvaluationValue inlineFunction(
41- Expression expression, Token token, ASTNode... parameters) {
42- return null;
43 }
44}
···16package com.ezylang.evalex.functions.basic;
1718import com.ezylang.evalex.EvaluationContext;
019import com.ezylang.evalex.data.EvaluationValue;
20import com.ezylang.evalex.functions.AbstractFunction;
021import com.ezylang.evalex.parser.Token;
22import java.security.SecureRandom;
02324/** Random function produces a random value between 0 and 1. */
25public class RandomFunction extends AbstractFunction {
···31 SecureRandom secureRandom = new SecureRandom();
3233 return context.expression().convertDoubleValue(secureRandom.nextDouble());
00000034 }
35}
···1+/*
2+ Copyright 2012-2024 Udo Klimaschewski
3+4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+8+ http://www.apache.org/licenses/LICENSE-2.0
9+10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+*/
16+package com.ezylang.evalex.parser;
17+18+import com.ezylang.evalex.EvaluationContext;
19+import com.ezylang.evalex.EvaluationException;
20+import com.ezylang.evalex.data.EvaluationValue;
21+22+public interface Solvable {
23+ EvaluationValue solve(EvaluationContext context) throws EvaluationException;
24+}