Drawing Annotated Parse Tree for Syntax Directed Definition [closed]

Im trying to draw an annotated parse tree for 3*5+4n, the text book shows the following:

[Compilers - Principles, techniques and tools (Dragon Book) by Aho, p308]

I have a few questions regarding this

1. Why is 3*5+4 considered as a single string? Can't I draw a parse tree something like for the same string ie:with operator at the node

2. What is the need for giving T.VAL=3 and then giving another child F.VAL=3. (I understand that the integer attribute for digit needs to be supplied by the lexical analyzer)

closed as unclear what you're asking by D.W.♦, András Salamon, Luke Mathieson, Juho, Guy CoderFeb 3 '14 at 0:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• I don't understand your question 1; the string you state is clearly decomposed in the syntax tree? Also, the tree you give seems to belong to an entirely different string. – Raphael Jan 30 '14 at 11:15
• @Raphael The second figure is not of the string which i have stated earlier.I wanted to ask why is the parse tree drawn as in figure 1 rather than using the approach shown in figure 2 – techno Jan 30 '14 at 12:17
• I don't know how you can expect us to answer the question without showing us the corresponding context-free grammar. I suggest you edit your question to make it self-contained (i.e., provide this information, and everything else needed to understand the situation). – D.W. Jan 31 '14 at 4:12
• @D.W. see this link to get all details books.google.com/… – techno Jan 31 '14 at 7:08
• @techno, please add all relevant information to the question (and not just a link, but the grammar itself). The question needs to be self-contained, without reading/following other links, resources, books, etc. It's your job to make the question self-contained. Yes, sometimes this takes work: our expectation is that you will put in a serious effort to make your question clear and thorough. The purpose of this site is to generate an archive of high-quality questions and answers that will be useful to others. – D.W. Jan 31 '14 at 7:47

The Dragon book style starts with the parse tree of the expression, i.e., the root (I think the very top is a mistake, the expression is an error as written) is the step $E \Rightarrow E + T$. The tree is then decorated giving the attributes their value (like $E.val = 19$). In an attributed grammar you give the grammar and the attributes, so that the grammar looks in part as (subindices mark diferent uses of the same symbol, left to right): \begin{eqnarray} E \rightarrow T \quad E.val \leftarrow T.val \\ E \rightarrow E + T \quad E_0.val \leftarrow E_1.val + T.val \end{eqnarray} You see that the answer to your second question is that the value of the child $F$ is used to compute the value of $T$.