| 1 |
/* |
| 2 |
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2024 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 18 сент. 2019 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_EXPR_PARSER_H_ |
| 23 |
#define LSP_PLUG_IN_EXPR_PARSER_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/runtime/LSPString.h> |
| 27 |
#include <lsp-plug.in/expr/types.h> |
| 28 |
#include <lsp-plug.in/expr/evaluator.h> |
| 29 |
#include <lsp-plug.in/expr/Tokenizer.h> |
| 30 |
|
| 31 |
namespace lsp |
| 32 |
{ |
| 33 |
namespace expr |
| 34 |
{ |
| 35 |
enum expr_type_t |
| 36 |
{ |
| 37 |
ET_CALC, |
| 38 |
ET_RESOLVE, |
| 39 |
ET_CALL, |
| 40 |
ET_VALUE |
| 41 |
}; |
| 42 |
|
| 43 |
typedef struct expr_t |
| 44 |
{ |
| 45 |
evaluator_t eval; // Evaluation routine |
| 46 |
expr_type_t type; // Expression data type |
| 47 |
union |
| 48 |
{ |
| 49 |
struct |
| 50 |
{ |
| 51 |
expr_t *left; // First operand (unary, binary, ternary) |
| 52 |
expr_t *right; // Second operand (binary, ternary) |
| 53 |
expr_t *cond; // Condition (ternary) |
| 54 |
} calc; |
| 55 |
|
| 56 |
struct |
| 57 |
{ |
| 58 |
LSPString *name; // Base name of variable |
| 59 |
size_t count; // Number of additional indexes |
| 60 |
expr_t **items; // List of additional indexes |
| 61 |
} resolve; |
| 62 |
|
| 63 |
struct |
| 64 |
{ |
| 65 |
LSPString *name; // Base name of function |
| 66 |
size_t count; // Number of additional indexes |
| 67 |
expr_t **items; // List of additional indexes |
| 68 |
} call; |
| 69 |
|
| 70 |
value_t value; // Value |
| 71 |
}; |
| 72 |
} expr_t; |
| 73 |
|
| 74 |
expr_t *parse_create_expr(); |
| 75 |
void parse_destroy(expr_t *expr); |
| 76 |
|
| 77 |
status_t parse_ternary(expr_t **expr, Tokenizer *t, size_t flags); |
| 78 |
status_t parse_or(expr_t **expr, Tokenizer *t, size_t flags); |
| 79 |
status_t parse_xor(expr_t **expr, Tokenizer *t, size_t flags); |
| 80 |
status_t parse_and(expr_t **expr, Tokenizer *t, size_t flags); |
| 81 |
status_t parse_bit_or(expr_t **expr, Tokenizer *t, size_t flags); |
| 82 |
status_t parse_bit_xor(expr_t **expr, Tokenizer *t, size_t flags); |
| 83 |
status_t parse_bit_and(expr_t **expr, Tokenizer *t, size_t flags); |
| 84 |
status_t parse_cmp_eq(expr_t **expr, Tokenizer *t, size_t flags); |
| 85 |
status_t parse_cmp_rel(expr_t **expr, Tokenizer *t, size_t flags); |
| 86 |
status_t parse_strcat(expr_t **expr, Tokenizer *t, size_t flags); |
| 87 |
status_t parse_strrep(expr_t **expr, Tokenizer *t, size_t flags); |
| 88 |
status_t parse_addsub(expr_t **expr, Tokenizer *t, size_t flags); |
| 89 |
status_t parse_muldiv(expr_t **expr, Tokenizer *t, size_t flags); |
| 90 |
status_t parse_power(expr_t **expr, Tokenizer *t, size_t flags); |
| 91 |
status_t parse_not(expr_t **expr, Tokenizer *t, size_t flags); |
| 92 |
status_t parse_sign(expr_t **expr, Tokenizer *t, size_t flags); |
| 93 |
status_t parse_func(expr_t **expr, Tokenizer *t, size_t flags); |
| 94 |
status_t parse_primary(expr_t **expr, Tokenizer *t, size_t flags); |
| 95 |
status_t parse_identifier(expr_t **expr, Tokenizer *t, size_t flags); |
| 96 |
status_t parse_call(expr_t **expr, Tokenizer *t, size_t flags); |
| 97 |
|
| 98 |
status_t parse_expression(expr_t **expr, Tokenizer *t, size_t flags); |
| 99 |
|
| 100 |
} /* namespace expr */ |
| 101 |
} /* namespace lsp */ |
| 102 |
|
| 103 |
#endif /* LSP_PLUG_IN_EXPR_PARSER_H_ */ |