|
-
Nov 4th, 2000, 03:32 PM
#1
Thread Starter
Hyperactive Member
okok, im writing a scripting language (for animations).
i can parse the code typed in and create an instruction stream from it for my VM to execute.
Now i'm writing the VM, and i need the best and fastest way of evaluating something like
x = y / (somefunc(a * b, foo))
that's just an example, but u should get what i mean
what i'm thinking is: go thru the line, and execute any functions first, then * and / then + - (from rule of order of operations in maths).
anyone have any other ideas, or any way to implement this?
i expect i can figure it out, but i'd like some other ways of doing it.
buzzwords are the language of fools
-
Nov 4th, 2000, 05:53 PM
#2
transcendental analytic
I've done a scipting language myself some years ago but it looks really messy and i don't want to maintain it now, theres the scripting control so i don't need to. But anyway, here's some of the ideas:
1. You need to make an order of operators to work by
a) functions that are written after the expression like x³ x! and 90º
b) exponents and roots
c) functions that are written like sin(ecpression)
d) multiplication and division
e) addition and substraction
f) logical comparators >=, =, < and others
g) And
h) or, xor, imp...
2. you use instr to search for these in the expression, and operates in the order from a to h, except ( ) that should be evaluated first. you operate the first match of all operators in the same group, like if x/y*z you operate x/y first. then the result * z. To do this you need to make the evaluation function recursive so that you call it from itself to evaluate internal values.
3. When a value is evaluated correctly it should return a number, so when each sub-evaluation is done it returns a number, therefore the next evaluation can continue with single expressions like 5/3 or sin(42). should be easy enought to parse out and do the operation.
4. If you have variables involved you replace them with number, the first thing you do, this check should only be done the first time, not in the recursive procedure so you place it in a main call from which you call the recursive procedure.
5. To assign a variable, like in vb you use "X=" or "Let X =" you do as if it was a programming language, youre not evaluating the values, instead you check what statement is used, a variable left of a = operator means what's on the right side is evaluated and assigned to the variable. all "=" right of the first should be considered as operators in the expression....
Well there's some stuff to think about, Good luck
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 5th, 2000, 05:35 AM
#3
Thread Starter
Hyperactive Member
thanks 
for speed, in the parser, i've kind of compiled the code; at least the main instruction stream isn't a string, so I have all the operators separated already..
also im using "==" for comparison and "=" for assignment like C..basically for easyness so i don't have to spend time figuring out when youre trying to compare and when youre assigning.
buzzwords are the language of fools
-
Nov 5th, 2000, 09:41 PM
#4
transcendental analytic
Ah well thats the way to go KENNNY, BTW, are you using an array for the main instruction stream?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 6th, 2000, 02:34 PM
#5
Thread Starter
Hyperactive Member
buzzwords are the language of fools
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|