CFGs and Parse Trees

What expression does this parse tree generate?

The conext-free grammar wikipedia page The conext-free grammar wikipedia page

x + y * x - z * y / x + x ( x + y ) * x - z * y / ( x + x ) ( x + y ) + x - z + y - ( x + x ) x + y + z * y + x * x

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Karleigh Moore
Jun 14, 2016

Start at the leaves of the tree and work your way up left to right. The left-most leaves are x and y and those are connected by an "+" node. This is connected to a "( )" node, so those go in parentheses. Keep following the tree this way until you hit the next branching node, which is (in this case) "S * S" where the first "S" is "(x + y)" and the second "S" is "x" --> so this yields "(x + y) * x" and so on.

is it correct

Sharanya Warrier - 1 year, 3 months ago
Biruk Mekonnen
Apr 26, 2021

using push and pop method of data structure and algorithm. stack them up and define the expression.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...