More or less I have the same problem. I don't know if I have to open another topic or not. I add my question here becouse usually, in forums, admins like to have same questions in same topics.
I need to program, like jbrooksuk, an INTERPRETER (not a parser) of my own script. I read (before enterning here) bison documentations but Bison cannot solve my problems.
Bison is fine if you have to add a syntax check of your script. But I don't need error checking (becouse scripts will be produced with a program, so errors are impossible to do).
The most great problem is one that Bison DON'T solve... is the runtime interpreting (even if you use Bison you have to write it by your own so it is useless to use Bison) and, most of all, Conditional Brantches (if you read documentations it says only "find your way. Is too much hard to explain").
for example if I have this script code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
command 1
command 2
if (condition 1) {
command 3
command 4
if (condition 2) {
command 5
loop(1) {
command 6
command 7
if (condition 3) {
endloop(1)
}
}
}
}
| |
This is only an example... it could be also in XML grammar. The problem is not the final structure of the script. Is to execute end interpreting it correctly in run-time.
for example command 3 will be executed only if condition 1 is true
for example if condition 1 is true ALL the code inside its { } will be execute (other conditional brantches will be evalued and if true executed, if false skipped).
Loop and endloop works as IDs loop(ID) is a while(1) that will be executed until an endloop(ID) encountered (so loop(1) ended when find endloop(1) and quit out of { } of loop(1) )
Any suggestion will be appreciated. It is fine also a solution that suggest to "build" a script if it is too hard to interpret it directly from source (like C++ do when first compile and after link). In this case I need suggestion how to "build" a binary that reproduces all conditions and loop that is easyer to be interpreted in runtime.