是否有用于此符号翻译/转换的现有算法?
系统有一种表示法,需要将 (A+B)*C
之类的表达式编写为 #MUL(#ADD(A,B),C)
。是否已经有一种算法可以进行这种符号转换,以便用户可以以更常规的方式输入? 换句话说,从中缀转换的算法 ->我的记号。第一个问题是我不知道我的符号的确切名称......它类似于反向抛光但不完全一样。每个运算符都被编码为带有参数的函数。
A system has a notation that would require writing an expression like (A+B)*C
as #MUL(#ADD(A,B),C)
. Is there already an algorithm to do this kind of notation conversion so users can enter in a more conventional way?
In other words an algorithm to convert from infix -> my notation. First issue is I don't know an exact name for my notation... it's similar to reverse-polish but not quite. Every operator is encoded as a function taking arguments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Shunting-yard 算法 可用于解析中缀表示法。
Shunting-yard algorithm can be used to parse infix notation.
这里有一些 Lisp 尝试使用中缀 ->前缀转换。它可以作为一个有用的起点。
Here's some Lisp that attempts the infix -> prefix transformation. It could serve as a useful starting point.
使用 Lex 和 Yacc(Flex 和 Bison 的,它们是相同的)很容易解析这些简单的表达式。谷歌搜索“Yacc 计算器”。
我发现的一个例子是 http://www.indiastudychannel .com/resources/56696-IMPLMENTATION-OF-CALCULATOR-USING-YACC.aspx 但您不应计算结果,而应构建最终字符串。例如,像这样(伪代码):
It's easy to parse these simple expressions using Lex and Yacc (of Flex and Bison, they're the same). Google for "Yacc calculator".
One example I found is http://www.indiastudychannel.com/resources/56696-IMPLEMENTATION-OF-CALCULATOR-USING-YACC.aspx but instead of calculating the results, you should build up the final string. For example, like this (pseudocode):