arunhorne has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I need to build a parser for a file format shown below. I have decided to hand code it (as against constructing a parser with Lex/Yacc) as it is comparatively simple, but would be interested in any observations people could make on the best way to approach parsing this file. The file represents a graph of vertices and edges:
graph { node { title: "node1" loc {x: 10 y: 20} } node { title: "node2" loc { x: 10 y: 20 } } edge { sourcename="node1" targetname="node2" } }
As your can see from the example the file is well structured and I want to create a list of node structures and a list of edge structures from this file - node has three properties - x, y and title whilst edge just has two properties, sourcename and targetname which correspond to node titles. I am not interested in checking the file (or the graph) for validity -- these files are generated by another program and therefore are always valid.
Can anyone help me with suitable code to load this data from the file (preferably without using any Perl specific features -- I am prototyping in Perl but may have to implement this parser eventually in another language due to constraints imposed by others) or any suggestions about how to do what I want in the most simple (but clear) way possible?
Any help will be greatly appreciated, thanks in advance,
____________
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Graph File Parsing
by larsen (Parson) on Mar 10, 2003 at 13:55 UTC | |
|
Re: Graph File Parsing
by l2kashe (Deacon) on Mar 10, 2003 at 13:39 UTC | |
|
Re: Graph File Parsing
by broquaint (Abbot) on Mar 10, 2003 at 14:40 UTC | |
|
Re: Graph File Parsing
by zby (Vicar) on Mar 10, 2003 at 14:03 UTC |