Exercise 34:

Hierarchic Graphs
Note: this exercise is taken from the Compilers subject at Barcelona School of Informatics.

Design a grammar to describe hierarchic graphs. The set of tokens is {graph, endgraph, IDENT, (, ), ,, ;, >}. The token IDENT refers to identifiers, such as graph names, i.e., non-empty sequences of alphanumeric characters and underscore, not starting by a digit.

Example input:
  graph F(in, out)
    in > a > out;
    in > b > a;
    b > out;
  endgraph

  graph G(a, b, c, d)
    a > x > y > x;
    b > x; y > c; y > d;
  endgraph

  graph top(x1, x2, y)
    x1 > n1; x1 > n2;
    G(n1, n2, n8, n5);
    G(n3, n4, n6, n7);
    x2 > n3; x2 > n4;
    F(n7, n11);
    G(n5, n6, n9, n10);
    G(n8, n9, n12, n13);
    G(n10, n11, n14, n15);
    n13 > y; n14 > y;
    n15 > n12;
  endgraph
Remarks:
Authors: Nil Mamano / Documentation:
To be able to submit you need to either log in, register, or become a guest.