Author |
Message |
The_Bean

|
Posted: 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

|
|
 |
[Gandalf]

|
Posted: 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

|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
The_Bean

|
Posted: 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

|
Posted: 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) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
|