Postfix expression grammar analysis ---

[Soft] the second half of 2014 to test the arithmetic expression (ab) * (c + d) postfix expression is ()

 A.ab-cd *

 B.abcd - * +

 C.ab- * cd +

 D.ab-c+d*

[A]

For grammar compiler theory analysis of 1-2 points in the morning soft test questions, where the number of such title for the topic and ask postfix expression is a lot of, for doing such a topic on a lot of ways I do not feel for us to quickly solve these problems, so then I use my own ideas and methods under show you how to quickly deal with such problems.

First of all we want to test to the casual working requirements (ab) * (c + d) suffix expression we first drawn to this expression expression tree, then how to draw the expression tree painting? We follow the order of traversal of a binary tree data structure to be drawn. As follows:

After the expression tree is created in accordance with the requirements of our topic postfix expression needs to traverse through thought after traversing binary tree data structure that is sub-tree to the left and then the right sub-tree root node last.

For the above said left following method

Left sub-tree: a

Right subtree: b

Root: -

Under combination: ab-

For the right of using the same method as above,

Left subtree: c

Right subtree: d

Root: +

The combination of: cd +

The next step is up composition shown below

Left subtree: ab-

Right subtree: cd +

Root: *

The combination of: ab-cd + *

 

【to sum up】

For solving this type of topic postfix expression is follow this line of thinking, then first draw the expression tree data structure based on the binary tree traversal sequence thought to traverse, so the subject matter come before this request in accordance with the postfix the idea to solve problems will soon be able to do it.

 

He published 196 original articles · won praise 581 · views 470 000 +

Guess you like

Origin blog.csdn.net/wyf2017/article/details/90261451