Forum Topic: Parsing [AS3]

(150 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

FiqStudios

Reply To Post Reply & Quote

Posted at: 11/12/08 10:08 PM

FiqStudios DARK LEVEL 08

Sign-Up: 12/23/07

Posts: 671

I'm working on a calculator in flash (advanced) and I've already defined functions. Now all that's left for me to do is to get flash to execute functions typed by the user, for example, If input.text = "riemann_zeta(8.5)" how will I get flash to treat it as a function and execute it?

[ Proxi ::: Life ::: AS3 ]

BBS Signature

None

CaptinChu

Reply To Post Reply & Quote

Posted at: 11/12/08 10:25 PM

CaptinChu DARK LEVEL 15

Sign-Up: 09/11/05

Posts: 3,219

Check out the indexof() function on strings. That will help a lot. indexof() finds where the first instance of a substring is within a string if that substring is in there. I believe it will help you.

Please PM me about the Riemann Zeta function. I've been very intrigued about it for a while. Also, tell me how the calculator turns out when it's all said and done.

All programming problems can be solved with Arrays!

BBS Signature

None

FiqStudios

Reply To Post Reply & Quote

Posted at: 11/12/08 11:00 PM

FiqStudios DARK LEVEL 08

Sign-Up: 12/23/07

Posts: 671

At 11/12/08 10:25 PM, CaptinChu wrote: Check out the indexof() function on strings. That will help a lot. indexof() finds where the first instance of a substring is within a string if that substring is in there. I believe it will help you.

Not really helpful. Any better ideas?

[ Proxi ::: Life ::: AS3 ]

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 11/13/08 10:17 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,418

Actionscript is compiled. You can't treat strings as code. Use regexps to tokenize the string and parse the tokens.

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Cojones893

Reply To Post Reply & Quote

Posted at: 11/13/08 10:35 AM

Cojones893 EVIL LEVEL 22

Sign-Up: 03/09/03

Posts: 2,596

You can do something like:

function test(n:String):String{
	return n;
}

trace(this["test"]("test function"));

None

DougyTheFreshmaker

Reply To Post Reply & Quote

Posted at: 11/13/08 12:37 PM

DougyTheFreshmaker NEUTRAL LEVEL 02

Sign-Up: 07/30/07

Posts: 519

At 11/12/08 10:08 PM, FiqStudios wrote: I'm working on a calculator in flash (advanced) and I've already defined functions. Now all that's left for me to do is to get flash to execute functions typed by the user, for example, If input.text = "riemann_zeta(8.5)" how will I get flash to treat it as a function and execute it?

Unfortunately, I don't think this is going to be as easy as you might expect. What you need to do is write a compiler, sans the code generation portion. If you don't know them already, looking into finite state and push-down automata would be a good place to start, along with any other compiler theory resources you could find.

We should take care not to make the intellect our god; it has, of course, powerful muscles, but no personality.
Freshmaking
Brainscrape

BBS Signature

None

FiqStudios

Reply To Post Reply & Quote

Posted at: 11/13/08 05:16 PM

FiqStudios DARK LEVEL 08

Sign-Up: 12/23/07

Posts: 671

At 11/13/08 10:35 AM, Cojones893 wrote: You can do something like:

function test(n:String):String{
return n;
}

trace(this["test"]("test function"));

Thanks a lot, that really helped.

I'll post the final when it's done. It's got a lot of upper level functions, it'll even have a base changer ( 5 = 101 base 2).

[ Proxi ::: Life ::: AS3 ]

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 07:21 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!