I want to parse a tree from a file that will describe this tree (which actually is a taxonomy).
I am looking for examples of grammar (ideally lex/yacc files) that provides description of trees. It would be better if that described trees were not binary search trees but instead trees where each node (possibly) has several children (is it called a family tree? planar tree?).
Ideally, it would be perfect if this lex/yacc would actually be included in an OCaml library. But any good grammar for tree description will satisfy me.
I tried to find examples through Google or Stackoverflow but research results are overwhelmed by parse tree-related questions. I could make a grammar myself but I would like to see example first in order to do have a good starting point.
Here is my attempt at creating a minimal example of parsing a tree:
I assume trees are represented as
name_of_the_node(child(...), other_child(...), ...)
. For instance, here is a simple tree with a root and 3 leaves:root(first_leaf(), second_leaf(), third_leaf())
.lexer.mll
parser.mly
tree.ml
to compile:
to test into toplevel:
and then: