为什么我们需要前缀、后缀表示法 [英] Why do we need prefix, postfix notation

查看:21
本文介绍了为什么我们需要前缀、后缀表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何将它们相互转换,但从未真正了解它们的应用程序是什么.通常的中缀操作可读性很强,但是它在哪里失败导致了前缀和后缀表示法的开始

I know how each of them can be converted to one another but never really understood what their applications are. The usual infix operation is quite readable, but where does it fail which led to inception of prefix and postfix notation

推荐答案

中缀表示法对于人类来说很容易阅读,而前/后缀表示法对于机器来说更容易解析.前置/后置表示法的一大优势是永远不会出现诸如运算符优先级之类的问题.

Infix notation is easy to read for humans, whereas pre-/postfix notation is easier to parse for a machine. The big advantage in pre-/postfix notation is that there never arise any questions like operator precedence.

例如,考虑中缀表达式1 # 2 $ 3.现在,我们不知道这些运算符的含义,因此有两种可能的对应后缀表达式:1 2 # 3 $1 2 3 $ #.在不了解这些运算符的使用规则的情况下,中缀表达式基本上毫无价值.

For example, consider the infix expression 1 # 2 $ 3. Now, we don't know what those operators mean, so there are two possible corresponding postfix expressions: 1 2 # 3 $ and 1 2 3 $ #. Without knowing the rules governing the use of these operators, the infix expression is essentially worthless.

或者,用更一般的术语来说:可以在没有任何额外知识的情况下从前/后缀表达式恢复原始(解析)树,但对于中缀表达式而言,情况并非如此.

Or, to put it in more general terms: it is possible to restore the original (parse) tree from a pre-/postfix expression without any additional knowledge, but the same isn't true for infix expressions.

这篇关于为什么我们需要前缀、后缀表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆