How Do You Construct a Parse Tree for the Expression (a, (a, a))?

  • Thread starter Thread starter toothpaste666
  • Start date Start date
  • Tags Tags
    Tree
Click For Summary

Discussion Overview

The discussion revolves around constructing a parse tree for the expression (a, (a, a)) based on a specified grammar. Participants explore the implications of the grammar rules, the meaning of commas and parentheses, and how to visually represent the parse tree.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant questions whether the starting symbol for the parse tree should be S or L and seeks clarification on the meaning of commas in the expression.
  • Another participant attempts to draw the parse tree but is uncertain about how to represent the connections with arrows.
  • A later reply asserts that parentheses and commas are merely symbols without special significance, suggesting that the grammar would remain consistent even if the symbols were different.
  • It is noted that removing the parentheses around L would lead to ambiguity in the parse tree, potentially resulting in an infinitely large structure.
  • One participant expresses intent to draw arrows connecting each substitution in their parse tree representation.

Areas of Agreement / Disagreement

Participants express uncertainty regarding the starting symbol and the representation of the parse tree. There is a consensus that parentheses do not hold special meaning, but the implications of their removal lead to differing views on the resulting grammar's ambiguity.

Contextual Notes

Participants highlight the potential ambiguity in the grammar if parentheses are omitted, indicating that this could affect the structure of the parse tree. The discussion also reflects a lack of clarity on how to visually represent the parse tree, particularly concerning the use of arrows.

toothpaste666
Messages
517
Reaction score
20

Homework Statement



Consider the grammar
S←(L)
S←a
L←L,S
L←S

draw a parse tree for the expression (a, (a, a))

The Attempt at a Solution


I can't tell if the starting symbol should be S or L. Also what do the commas mean? The examples we did in class had plus and minus signs and stuff like that but we didn't have an example of what to do when there is a comma. Also is there a difference if the parenthesis weren't there around the L in the first one?
 
Physics news on Phys.org
attachment.php?attachmentid=69448&d=1399323730.jpg
This is my attempt at drawing it so far. I don't know how the arrows connecting them should be drawn though.
 

Attachments

  • parsetree.jpg
    parsetree.jpg
    7.1 KB · Views: 498
There is nothing special about the parentheses and commas. They are just symbols. The question would be exactly the same if the grammar was
S←xLy
S←a
L←LzS
L←S
and the string was xazxazayy.

Also is there a difference if the parenthesis weren't there around the L in the first one?
Since there is nothing special about the parentheses, the answer is clearly "yes". Without the parentheses, the grammar would have two rules
S←L
L←S
so the parse tree would be ambiguous, and could be infinitely big.

Your attempt looks OK. Check your course notes or textbook for how you are expected to draw the tree including arrows.
 
  • Like
Likes   Reactions: 1 person
thank you! I think I will draw an arrow connecting each substitution.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 26 ·
Replies
26
Views
2K
Replies
5
Views
5K
Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K