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,

____________
Arun

In reply to Graph File Parsing by arunhorne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.