ExpressEvalByLeo/Src/MathEval/TestDyn.mq5

71 lines
2.1 KiB
MQL5
Raw Permalink Normal View History

2026-05-14 14:13:20 -05:00
//+------------------------------------------------------------------+
//| TestDyn.mq5 |
//| Copyright 2026, Niquel Mendoza. |
//| https://www.mql5.com/es/users/nique_372/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza."
#property link "https://www.mql5.com/es/users/nique_372/news"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "AST.mqh"
#include "Tokenizer.mqh"
#include "..\\Common\\NodeUtils.mqh"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
CMathExpTokenizer tokenizer;
TokenMathExp tokns[];
const string text = "$suma * $producto ";
if(!tokenizer.Tokenize(text, tokns))
{
Print(tokenizer.FormatLastError(text));
return;
}
else
{
tokenizer.PrintValues(tokns);
}
//---
CMathExpresionEvalDync eval;
CHashMap<string, IValor*> variables;
variables.Add("suma", new IValorSimpleValVal<int>(10));
variables.Add("producto", new IValorSimpleValVal<int>(10));
//---
eval.TableSymbols(&variables);
ValueNode bit;
eval.CleanCache(tokns);
Print(eval.ParsNoRes(tokns, bit));
Print(bit.type);
if(bit.type == MATH_EXP_NODE_TYPE_STATIC)
{
Print("Valor: ", (bit.s_val_type == AST_LOGIC_NUMBER_DOUBLE ? bit.s_val.double_value : bit.s_val.long_value));
}
else
{
CNodeUtils::PrintValue(bit.d_val);
delete bit.d_val;
}
//---
string t[];
IValor* p[];
const int to = variables.CopyTo(t, p);
for(int i = 0; i < to; i++)
{
delete p[i];
}
}
//+------------------------------------------------------------------+