• edited by
1,523 views
1 1 vote

Since it is a Bottom Up Parser do we need to evaluate expressions following Right Hand Derivations or Left Hand Derivations,i.e. should we evaluate D -> d first or B -> B first?

Consider the following grammar and associated semantic actions :-
\[
\begin{array}{lr}
\mathrm{S} \rightarrow \mathrm{ABCD} & \{\mathrm{x}=2 \mathrm{x}+1\} \\
\mathrm{D} \rightarrow \mathrm{~d} & \{\mathrm{x}=2 \mathrm{x}-1\} \\
\mathrm{C} \rightarrow \mathrm{cc} & \{\mathrm{x}=5 \mathrm{x}+7\} \\
\mathrm{B} \rightarrow \mathrm{Bb} & \{\mathrm{x}=5 \mathrm{x}-7\} \\
\mathrm{B} \rightarrow \mathrm{~b} & \{\mathrm{x}=\mathrm{x}+1\} \\
\mathrm{A} \rightarrow \mathrm{gBa} & \{\mathrm{x}=2 * \mathrm{x}-1\}
\end{array}
\]

The variable x is a global. Assume x is initialized with " 0 " before parsing. What is the final value of $x$ in a bottom up passing of the following input "g b a b c c d"?

1 Answer

0 0 votes
A bottom up parser works by scanning the string from left to right and performing reduction when the stack top has a handle. So, the answer is 67.

The reductions are in the order as

B->b, A->gBa, B->b, C->cc, D->d and then S->ABCD
Position:
Show:

Related questions

0 0 votes
1 1 answer
741
741 views
bunty choudhary asked Feb 9, 2018
741 views
why top down parser uses left most derivation? is it mandatory or we can change it by modifying the algo?
1 1 vote
1 answers 1 answer
2.1k
2.1k views
durgesh94 asked Jun 15, 2016
2,054 views
Which of the following feature(s) is/are needed to implement top down parsingSource string marker Prediction making mechanismMatching and Backtracking me...
1 1 vote
0 0 answers
791
791 views
saxena0612 asked Nov 23, 2017
791 views
Comment on Statement:Operator precedence parser is a SR parser. :Thoughts:Though it uses Stack to evaluate input string is it this the reason we can call it as shift redu...
0 0 votes
2 2 answers
1.3k
1.3k views
prasitamukherjee asked Jul 16, 2015
1,301 views
q. 23 : can anyone explain why both statements are false? I thought option B is correct?