(1) stmt -> directive? (2) directive -> left | right
(1) stmt -> directive+ (2) directive -> left | right
(1) stmt -> directive* (2) directive -> left | right
(1) stmt -> directive number (, directive number)* (2) directive -> left | right
bison -v exp.yacc
bison -v sections.yacc
stmt : assignmentList edgeList
assignmentList : assignmentList assignment
|
;
edgeList : edgeList edge
|
;
assignment : ID EQUALS ID
;
edge : ID ARROW ID
;
Now I cannot rewrite the grammar to reduce the shift/reduce conflict.
What could I instead add to the grammar in order to eliminate
the shift/reduce conflict? Describe informally what you would do and then
write the one production that you would change. You only need to add
something to one production in order for the grammar to become unambiguous.
You will need to modify and submit your "graph.lex" file from homework 2 so that it works with graph.yacc. You may use my solution for graph.lex if yours did not work (see the homework 2 solutions). If you choose to recognize the simpler grammar, you need to eliminate those portions of graph.lex that contain tokens which are not in the simplified grammar. Here are some additional problem specifications:
Here is the simplified grammar that is worth 50 points:
adjacencyList => nodeAdjacencyList+
nodeAdjacencyList => NODE_NAME -> NODE_NAME "EDGE_LABEL"?
(, NODE_NAME "EDGE_LABEL"?)* ;
It specifies the list of edges for a graph, along with optional edge labels for edges.
It assumes that the NODE_NAME will also be the label for the node.
Here is the complete graph grammar that is worth 65 points:
graph => direction? nodeStyleList edgeStyleList nodeLabelList adjacencyList
direction => DIRECTION = VERTICAL ;
| DIRECTION = HORIZONTAL ;
nodeStyleList => (nodeStyle ;)*
edgeStyleList => (edgeStyle ;)*
nodeLableList => (nodeLabel ;)*
nodeStyle => NODESTYLE STYLE_NAME? [ attributeList ] nodelist
edgeStyle => EDGESTYLE STYLE_NAME [ attributeList ]
attributeList => attribute (, attribute)*
attribute => COLOR = PROPERTY_NAME
| SHAPE = PROPERTY_NAME
| FONTNAME = PROPERTY_NAME
| FONTSIZE = NUMBER
nodeList => NODE_NAME+
nodeLabel => NODE_NAME = "NODE_LABEL"
adjacencyList => nodeAdjacencyList+
nodeAdjacencyList => NODE_NAME -> NODE_NAME "EDGE_LABEL"? STYLE_NAME?
(, NODE_NAME "EDGE_LABEL"? STYLE_NAME?)* ;
Here are a few notes to help you interpret the grammar: