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

Moderator: Mmiscool

User avatar
By cicciocb
#42784 Little update.
Still in testing.
It works much better now; I fixed some snags and introduced a lot of functions directly into eval.
I added the "+" operator for the strings, the % (modulo) for numbers, the comparison between strings (== and !=), the operators shift left << and >>shift right.
you can write code like this:
Code: Select allmemclear
print eval(replace("abcdef","c","d"))

print eval("Number of wifi avail : "+str(wifi.scan()))

print eval("First Network Available: "+wifi.ssid(1)+" "+wifi.rssi(1))

print eval("What is My IP ? "+ip())

print eval("First part of my IP "+mid(ip(),1,3))

print eval("What is the char 65? :"+chr(65))

print eval("What is the ascii code of the char A? "+str(asc("A")))

let a = 50

for i = 0 to 200
let k = eval(sin(5*i)*cos(5*log(i)))
serialprintln ramfree()
delay(1)
next i


print eval((a+b)*c)
let L = 2048
print eval("Nb of bits for "+str(L)+" :"+str(log(L)/log(2)))

print eval(8<<2)
print eval(255>>3)


Still work in progress.

Cicciocb
User avatar
By Mmiscool
#42790 This is really good stuff.

Right now I have been working on taking all of the language reference off of the site and make it in to some thing that can be upload to git hub. That way people could submit fixes for problems with it or wording issues. :-)
User avatar
By cicciocb
#42915 Hi Mike,
I updated my fork with the new parser.
I changed a lot it, in order to manage the Strings.
The variables are still "handled" as strings but there is a little (very little) intelligence inside that try to understand if the string represent a number and handle it properly .
There are some new operators: << for shift left and >> for shift right;
there is also the % for modulo but for the moment the char % is wrongly interpreted so don't works.
The strings can be joined with the "+" (not the &).
The strings can be compared also with the c-like "==" or "!=" and the result will be 1 or 0 if true or false.
Example :
serialprint eval("abc"=="abc") ===> 1
serialprint eval("abc"=="def") ===> 0
serialprint eval("abc"!="def") ===> 1

I still haven't sync my version with your but you can integrate it easily.
Look at the new Eval.ino that contains the new function management.
We could start to modify the structure in order to implement the parser by default, removing the functions from Functions_and_var_management.ino
Hoping this will give a good feeback,

Regards

CiccioCB
It works not so bad,
User avatar
By Mmiscool
#42929 I played a bit in integrating the parcer in to the getmethatvar() function. And I found the reason why it was not allowing the parameters to be parced properly. I think a bit of head way was made.

Been running in to some problems with crashes.

This will allow things like

print 5+5
or
print 3(2+7)

to run.


Fix that needs to be in your version. Replace the SetMeThatVar() to fix a big but. It would over write a blank variable if one was found.
Code: Select allvoid SetMeThatVar(String VariableNameToFind, String NewContents)
{
  NewContents = GetRidOfurlCharacters(NewContents);
  byte varnotset = 1;
  for (byte i = 0; i < 50; i++)
  {
    if (AllMyVaribles[i][0] == VariableNameToFind)
    {
      AllMyVaribles[i][1] = NewContents;
      varnotset = 0;
    }
  }

  if (varnotset == 1)
  {
    for (byte i = 0; i < 50; i++)
    {
      if (AllMyVaribles[i][0] == "")
      {
        AllMyVaribles[i][0] = VariableNameToFind;
        AllMyVaribles[i][1] = NewContents;
        i = 51;
      }
    }
  }
}


Quick hack to have the eval function evaluate any time a variable is looked for.
Code: Select allString GetMeThatVar(String VariableNameToFind)
{
  delay(0);

  return evaluate(VariableNameToFind);
}



Fix for the basic parcer to send strings that include quotation marks to be evaluated by the eval function.
Code: Select allString getValue(String data, char separator, int index)
{
  data = String(data + "           ");
  int maxIndex = data.length() - 1;
  int j = 0;
  byte WaitingForQuote;
  String chunkVal = "";
  String ChunkReturnVal;
  for (int i = 0; i <= maxIndex && j <= index; i++)
  {
    if (data[i] == '\"' )
    {
      chunkVal.concat(data[i]);
      i++;
     
      while (i <= maxIndex && data[i] != '\"' ) {
        chunkVal.concat(data[i]);
        i++;
        delay(0);
      }
      chunkVal.concat(data[i]);
    }
    else if (data[i] == '|' )
    {
      i++;
      while (i <= maxIndex && data[i] != '|' ) {
        chunkVal.concat(data[i]);
        i++;
        delay(0);
      }
    }
    else
    {
      if (data[i] != separator) chunkVal.concat(data[i]);
    }

    if (data[i] == separator & data[i - 1] != separator)
    {
      j++;
      if (j > index)
      {
        //chunkVal.trim();
        if (chunkVal != String(separator))
        {
          ChunkReturnVal = chunkVal;
          break;
        }
      }
      chunkVal = "";
    }
  }
  //    Serial.println("index");
  //    Serial.println(index);
  //    Serial.println(j);

  if (j == index + 1)
  {

    return ChunkReturnVal;
  }
}