Convert a string to a code line?

Is there a way to get a string from the serial, and then in some way to create a line of code from it to be executed on runtime ?

Or, is there any other way to get strings and "elastically" create a code lines from them?
The only way i see is to write a program that get some known strings and then call functions according to it, while this method is not elastic and requires all kinds of conversions of strings to vars, etc.

Any idea?

Do you mean like an interpreter?
Like Forth or TinyBasic?

For example to get some Json or some structure over serial, then to create lines of code that will be performed live, for example somehow to turn this String "digitalWrite(1, HIGH)" , to the real command that output this.

(even not all the IDE commands, even only the basic ones )

Is there a way to get a string from the serial, and then in some way to create a line of code from it to be executed on runtime ?

No. The code is compiled and cannot be changed on the fly.

Or, is there any other way to get strings and "elastically" create a code lines from them?

Not sure what you mean by elastically but you cannot enter arbitrary code to be run via Serial.

You could, as you suggest, include code in your program to parse Serial input and call functions depending on the input. Converting input to values to be used in the functions is not that difficult.

for example somehow to turn this String "digitalWrite(1, HIGH)" , to the real command that output this.

should be relatively simple, but using pin 1 would not be a good idea !

@UKHeliBob , I think everyone knows you can't change lines of code from serial, I am trying to be more creative here .

AWOL gave me a solution which i think might work if i get it right, there are interpreters , that let you program the AVR on real time.

I think everyone knows you can't change lines of code from serial,

That was not evident from your original post.

Is there an interpreter that allows you to run Arduino code, which is what you seem to be looking for ?

You could start with a simple interpreter that reads commands of the serial port and executes Arduino instructions like pinMode/digitalRead/digitalWrite.

Look at the Synopsis example in the documentation for the Automaton command machine which does exactly that:

Firmata?

gil22:
For example to get some Json or some structure over serial, then to create lines of code that will be performed live, for example somehow to turn this String "digitalWrite(1, HIGH)" , to the real command that output this.

(even not all the IDE commands, even only the basic ones )

Sure.
If you want to build your own engine, then you need to capture the input character by character, identify the CR/LF, then parse. This example is terribly old and I have not updated it, but take from it what you will:
Scientific Calculator

Ray

gil22:
Is there a way to get a string from the serial, and then in some way to create a line of code from it to be executed on runtime ?

C/C++ is a compiler language which is compiled to machine language at compile time, then uploaded, then executed at runtime.

What you are talking about is related to interpreter languages only;
Interpreter languages are analyzing and executing interpreter code at runtime.

You are free to create your own interpreter language in Arrduino if you like.

Some months ago I posted a vry simple command interpreter which can be fed by commands from Serial like that

LED1 ON
MOTOR1 OFF
PUMP2 ON
LED5 CLICK 2500

where the ON and OFF commands will switch certain pins HIGH or LOW and the CLICK command takes a three parameters and acts like that:

swith a certain device ON and then OFF after the time in milliseconds has passed, given in the third parameter.