I have a a txt file representing a tree that is defined in the following BNF like format:
branches : '(' <value1> <value2> <n_children> <branches> ')'
| ''
Each node for the tree has two values value1
and value2
that are integers, number of children that is an integer, and branches.
an example of a subset of the file looks like:
(1796161 2205411 3
(1796288 2205425 0 )
(1811141 2205419 1
(1811652 2205480 1
(1812161 2205496 4
(1812288 2205521 1
(1812415 2205526 0 ))
(1812034 2205516 0 )
(1827651 2205510 2
(1827906 2205581 2
(1843777 2205588 2
(1844032 2205626 1
(1844159 2205632 0 ))
(1843138 2205617 0 ))
(1828288 2205591 1
(1828161 2205597 0 )))
(1827012 2205563 0 ))
(1811907 2205511 0 ))))
(1796034 2205420 0 ))
Is there a nice way to parse this data using regular expression(s) that wouldn't involve me manually reading the file character by character keeping track of all the parantheses and preserves the relationship (parent-child) ordering.