一个字符串转换在C线code的 [英] Converting a string to a line of code in C
问题描述
我试图找到一种方法将字符串转换到我的code的线。
I am trying to find a way to convert a string to the lines of my code.
例如,我想尝试成才这样的:
For example, i want to try someting like this:
int x=3;
char str[80];
gets(str); // Assuming the user gives input: "x + 3"
y = str;
printf("%d",y); // Output: "6" (3 + 3)
因此,该程序输出6(3 + 3)。
我想这对于建立一个函数绘图仪..但在这里我卡住,无法找到任何办法。请你告诉我一个方法将这些字符串转换为code线?
So that this program outputs "6" (3+3). I want to this for building a function plotter.. But here I get stuck and can't find any way. Would you please show me a way to convert these strings to lines of code?
推荐答案
您想要做的是什么前pression评价即可。我建议2种方法这或许有助于你更接近预期的解决方案。
What you want to do is expression evaluation. I suggest 2 methods which perhaps help you to get closer to the expected solution.
-
评估前pression用二叉树:构建树至极重presents除权pression和运营商之间的precedence。
Evaluate the expression with a binary tree: build a tree wich represents the expression and the precedence among the operators.
可能有人如上所述。波兰的形式,基于堆栈的评价。首先构建一个堆栈原来前pression的抛光形式,而且比再次评估波兰形式与栈。而最后:使用谷歌与这些keywoards:)
May be it was mentioned above. Polish-form, stack-based evaluation. First build the polish-form of the original expression with a stack, and than evaluate the polish-form with a stack again. And the last: use google with these keywoards :)
这篇关于一个字符串转换在C线code的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!