Tell me what you want, What you really, really want.

Moderator: Mmiscool

User avatar
By cicciocb
#42639 Hi Mike,
put this function inside "Functions_and_var_management.ino" and
Code: Select allString DoubleToString(double d)
{
  //Convert a double to string with 5 decimals and then removes the trailing zeros (and eventually the '.')
  String z = String(d, 5);
  char *p;
  p = (char*) z.c_str()+ z.length() -1;
  while (*p == '0')
  {
    *p-- = '\0';
  }
  if (*p == '.')
    *p = '\0';
  return z;
}


then replace each time you convert numbers to string with this function.
For example,
if (FunctionName == F("len")) MyOut = String(MyOut.length()); -===> if (FunctionName == F("len")) MyOut = DoubleToString(MyOut.length());

or
if (FunctionName == F("int"))
{
MyOut = String(Param0.toInt()); ===> MyOut = DoubleToString(Param0.toInt());
}

You need to repeat this to all the numerical functions.

This should fix the problem of the numbers displayed all the time with 2 decimals.

Regards,
CiccioCB

P.S. I'm actually working for a String parser :-;
User avatar
By Mmiscool
#42652 Integrating it now. Changed from double to float.

Putting up a new build as I type. Will be uploaded to the git hub momentarily.
User avatar
By cicciocb
#42702 Hi Mike, I'm progressing on the parser.
I'm working actually on visual studio C++, not yet integrated into the ESP but the results are not bad.
I'm able to do things like :
beta = "The quick brown fox jumps over the lazy dog"
mid(right(beta, 8),1,4) ==> lazy

or like that :
mid(right(beta, 4*2),1,4) ==> lazy

or like that
mid(right(beta, 4*2),1,log(16)/log(2)) ==> lazy

or like that
var4 = 4
mid(right(beta, 4*2),1,log(var4^2)/log(2)) ==> lazy


Stay tuned .....

CiccioCB
User avatar
By cicciocb
#42716 Good progress so far.
I was able to integrate the new parser in the ESP8266 Basic code.
It works like a charm! :D

This is the kind of code that can be executed right now :
Code: Select allprint eval("aaa"+"bbb")

print eval(mid("ABCDEFGH",1,3))

let beta = "The Quick Brown"
let delta = " Fox Jumps Over The Lazy Dog"

let sum = eval(beta+delta)
print sum

print eval(left(sum,5))

print eval(left(beta+delta,5))

let j = 15;
print eval(hex(255*16+j))
let k = 7
print eval(oct(511*8+k))

print eval(len(delta)+100)

print eval(instr(beta+delta,"Lazy"))
print eval(instr(upper(beta+delta),"LAZY"))
let aa = "This"
let bb = "is"
let cc = "the"
let dd = "new parser"
let ee = "FOR ESP"
let ff = "basic"

print eval(aa+" "+bb+" "+cc+" "+dd+" "+lower(ee)+" "+upper(ff))

and this is the result
Code: Select allaaabbb
ABC
The Quick Brown Fox Jumps Over The Lazy Dog
The Q
The Q
fff
7777
128
36
36
This is the new parser for esp BASIC


I'll try to put the code on github tomorrow.

Have a good day.

CiccioCB