I''d like to know if anyone knows of a good way to parse IF-THEN-ELSE statements. I''m open to any suggestions. Secondly I''d like to know if running a script every time through the game loop would cause a large performance hit. Before you answere that, here is an example to show how my scripting language works:
An example script:
EXTERN
FUNC PrintMessage[ STR:message ]
FUNC MultiplyAndPrint[ NUM:a, NUM:b ]
ENDEXTERN
PROGRAM
NUM total
NUM x
NUM y
STR string
PRINT "PLEASE ENTER A NUMBER FOR X:"
INPUT x
PRINT "PLEASE ENTER A NUMBER FOR Y:"
INPUT y
total = x + y
IF total == 5 THEN
string = total + " EQUALS 5\n"
PRINT string
ELSE
string = total + " DOES NOT EQUAL 5\n"
PRINT string
ENDIF
CALL PrintMessage[ string ]
CALL MultiplyAndPrint[ total, total ]
ENDPROGRAM
This script is then converted to "virtual" assembly like so:
START:
PUSH PLEASE ENTER A NUMBER FOR X:
PRINT
PUSH x
INPUT
PUSH PLEASE ENTER A NUMBER FOR Y:
PRINT
PUSH y
INPUT
PUSH x
PUSH y
ADD
PUSH total
ASGN
PUSH 5
PUSH total
CMP
JNE
PUSH EQUALS 5
PUSH total
ADD
PUSH string
ASGN
PUSH string
PRINT
JMP
LABEL
PUSH DOES NOT EQUAL 5
PUSH total
ADD
PUSH string
ASGN
PUSH string
PRINT
LABEL
PUSH string
CALL PrintMessage
PUSH total
PUSH total
CALL MultiplyAndPrint
I plan to use this in a 2D game and since the script is simply exicuted by going through the op codes and colling "execute" I don''t see how it sould cause a problem. I''m just looking for other opinions.
Obviously the example above is not to be used a script in a game. It''s just one I wrote to test the language thus far.