Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String to Command?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
The_Bean




PostPosted: Wed Sep 17, 2008 9:14 pm   Post subject: String to Command?

Is there anyway to convert a string to a command?

example:
for a drawing program
the user inputs "Draw.FillOval(...)"
then have turing converts the string to a command and actually draws the circle

I actually need it for a graphing calculator, but that example is a bit easier to understand
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Wed Sep 17, 2008 9:28 pm   Post subject: RE:String to Command?

Mostly you would just use conditional statements for something like this, unless you're planning to create your own Turing interpreter in Turing. If your goal is to create a graphing calculator, though, why do you need this at all? Just get the function (say) that you want to graph and use the appropriate drawing commands accordingly.
Tony




PostPosted: Wed Sep 17, 2008 9:44 pm   Post subject: RE:String to Command?

Though the function would still have to be interpreted. Which is more involving than simply conditional statements.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
The_Bean




PostPosted: Wed Sep 17, 2008 9:48 pm   Post subject: Re: String to Command?

when the user inputs:
y=(x-4)(x-3)^2(x+2)

and then somehow get from a string into

for x : -25..25
y:=(x-4)*(x-3)**2*(x+2)
Draw.Dot(x,y,7)
end for
Tony




PostPosted: Wed Sep 17, 2008 11:31 pm   Post subject: RE:String to Command?

you're going to need a scanner -- fairly easy since there are very few symbols.

you're going to need a parser build a parse tree of the expression

you're going to need a way to evaluate that tree (should also be easy -- recursion + eval of basic algebra operations)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: