flat assembler
Message board for the users of flat assembler.

Index > Main > I can't address a variable given its name as a string?

Author
Thread Post new topic Reply to topic
bougainville



Joined: 27 Mar 2006
Posts: 8
bougainville 27 Mar 2006, 01:44
I am trying to parse a simple string that says an arithmetic expression, and then evaluate the result.
I already have:
var1 dd 5
var2 dd6
The expression says to add the two existing variables. After parsing lets suppose I get the following:
sz1 dd 'var1'
sz2 dd 'var2'
sz3 dd '+'
Note that the string operands have the names of the variables that I want to add.
How can I obtain the values in var1 and var2 from the names written in sz1 and sz2?
Post 27 Mar 2006, 01:44
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 27 Mar 2006, 04:47
var1 is source label and does not binded with sz1 "var1" noway. if you wish to use such naming you need additional table where sz1 should have reference to var1.

regards!
Post 27 Mar 2006, 04:47
View user's profile Send private message Visit poster's website Reply with quote
bougainville



Joined: 27 Mar 2006
Posts: 8
bougainville 28 Mar 2006, 00:14
Thankyou shoorick. Yes, a table seems to be the way to go. I guess I was hoping that there might be an easier way because a table will get very big for many more variables. Also, there's the problem of adding to the table if a new variable comes by.
As I am essentially trying to parse an expression to perform arithmetic, perhaps there may be another completely different approach?
Post 28 Mar 2006, 00:14
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1614
Location: Ukraine
shoorick 28 Mar 2006, 08:02
i'm not ready to answer fast and full, but it does not look like a simple parser, much like simple HLL. there should be minimal set of functions: detecting vars, creating list of them, then, when they used in expression, replace them with their values, etc.
i would suggest you walk through the forth - it is excellent language to understand how expressions are solved and calculated.
Post 28 Mar 2006, 08:02
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.