I am trying to make a small interpreting program with JavaScript/jQuery. So what I want is that when the user enter some text in the textarea the program should interpret that text and print the output in another text area. Till now I have achieved this:
https://jsfiddle.net/7462hbv1/
With this I am able to catch each of the string that the user inputs in the text area. But now I want that when the user for example enter:
number a =1
number b=2
number sum=0
sum =a +b
print sum
the program should interpret this and the output should be 3
in this case.
Can anyone give me any idea how can I do this? I am thinking of building a two dimensional array and save there each row (for each row to have type, name, value) and then make calculation with this array.
I would appreciate any help. Thank you in advance
UPDATE
I have worked with my example and specifically with print statement. I have made it to print multiple strings or varibles(connected with +) and to print error message if + is missing. I have two problems now:
I want to have a error message when try to print undefined variable and not output undefined like in this case( I want to have that messsage in the
#errors
textarea):a = 240 b=120 print a + c
the output is240 undefined
I want to have the character
\iri
instead '\n' for the print statement to go to new line. I have done this withvar result2= result1.replace('\iri','\n');
but it does not function.
Here is my demo(DEMO)
Can you please help me?
UPDATE
I solve the second problem. Here is the DEMO. Can you please help me with the first one?