• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 
17 #ifndef LIBTEXTCLASSIFIER_UTILS_GRAMMAR_SEMANTICS_EVALUATORS_ARITHMETIC_EVAL_H_
18 #define LIBTEXTCLASSIFIER_UTILS_GRAMMAR_SEMANTICS_EVALUATORS_ARITHMETIC_EVAL_H_
19 
20 #include "utils/base/arena.h"
21 #include "utils/grammar/semantics/eval-context.h"
22 #include "utils/grammar/semantics/evaluator.h"
23 #include "utils/grammar/semantics/expression_generated.h"
24 #include "utils/grammar/semantics/value.h"
25 
26 namespace libtextclassifier3::grammar {
27 
28 // Evaluates an arithmetic expression.
29 // Expects zero or more arguments and produces either sum, product, minimum or
30 // maximum of its arguments. If no arguments are specified, each operator
31 // returns its identity value.
32 class ArithmeticExpressionEvaluator : public SemanticExpressionEvaluator {
33  public:
ArithmeticExpressionEvaluator(const SemanticExpressionEvaluator * composer)34   explicit ArithmeticExpressionEvaluator(
35       const SemanticExpressionEvaluator* composer)
36       : composer_(composer) {}
37 
38   StatusOr<const SemanticValue*> Apply(const EvalContext& context,
39                                        const SemanticExpression* expression,
40                                        UnsafeArena* arena) const override;
41 
42  private:
43   const SemanticExpressionEvaluator* composer_;
44 };
45 
46 }  // namespace libtextclassifier3::grammar
47 #endif  // LIBTEXTCLASSIFIER_UTILS_GRAMMAR_SEMANTICS_EVALUATORS_ARITHMETIC_EVAL_H_
48