Making a File Parser

  • I am trying to make a parser for an ASCII file format, so that I can
    make an easy to use GUI editor for this format. I am trying to make
    the parser with yacc/lex. I understand much of how these parsers
    work, but I am having issues with actually using them to dynamically
    edit the file. I am planning on taking the text and making objects
    with it, which are used by the editor.

    The problem is I don't quite understand how to get the information
    from the file, to the objects via yacc. I can parse the files, but
    the only way I have been able to devise of getting the information
    into the program is using a complex system of global variables that
    output the information. This way seems inelegant and prone to
    problems. I also don't see how I can sync changes to the file without
    rewriting it.

    I also have a vague concept of modifying the YYSTYPE to be my
    objects, and not dealing with constantly outputting to global
    variables. This seems more elegant, but I don't know how I would do
    it. I don't know if it is possible.

    Is there any good guide to this, or a simple explanation that I am
    missing?
  • Any lex or yacc tutorial should do (e.g. "Compilers: Principles,
    Techniques, and Tools" by Aho, Sethi and Ullman.) Global variables
    should not be necessary*.

    Typically the thing your parser produces is a graph of objects. Your
    program can then edit the object graph directly, instead of re-writing
    and re-parsing the file. (Being able to re-write the file from the
    object graph will stil be necessary when you're saving the file
    though.)

    Hope this helps. I think this is more of a yacc/lex question than a
    Mac OS X question, so perhaps you would like to reply to me directly
    instead of the list if you need more information.

    Hope this helps,

    Dominic Cooney

    * Using lex/yacc implies some global variables, so ignoring those.

    On 10/26/06, Henry Skelton <dimensiondude.oss...> wrote:
    > I am trying to make a parser for an ASCII file format, so that I can
    > make an easy to use GUI editor for this format. I am trying to make
    > the parser with yacc/lex. I understand much of how these parsers
    > work, but I am having issues with actually using them to dynamically
    > edit the file. I am planning on taking the text and making objects
    > with it, which are used by the editor.
    >
    > The problem is I don't quite understand how to get the information
    > from the file, to the objects via yacc. I can parse the files, but
    > the only way I have been able to devise of getting the information
    > into the program is using a complex system of global variables that
    > output the information. This way seems inelegant and prone to
    > problems. I also don't see how I can sync changes to the file without
    > rewriting it.
    >
    > I also have a vague concept of modifying the YYSTYPE to be my
    > objects, and not dealing with constantly outputting to global
    > variables. This seems more elegant, but I don't know how I would do
    > it. I don't know if it is possible.
    >
    > Is there any good guide to this, or a simple explanation that I am
    > missing?
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
  • On Oct 26, 2006, at 8:43 PM, Henry Skelton wrote:

    > I am trying to make a parser for an ASCII file format, so that I
    > can make an easy to use GUI editor for this format. I am trying to
    > make the parser with yacc/lex. I understand much of how these
    > parsers work, but I am having issues with actually using them to
    > dynamically edit the file. I am planning on taking the text and
    > making objects with it, which are used by the editor.
    >
    > The problem is I don't quite understand how to get the information
    > from the file, to the objects via yacc. I can parse the files, but
    > the only way I have been able to devise of getting the information
    > into the program is using a complex system of global variables that
    > output the information. This way seems inelegant and prone to
    > problems. I also don't see how I can sync changes to the file
    > without rewriting it.
    >
    > I also have a vague concept of modifying the YYSTYPE to be my
    > objects, and not dealing with constantly outputting to global
    > variables. This seems more elegant, but I don't know how I would do
    > it. I don't know if it is possible.
    >
    > Is there any good guide to this, or a simple explanation that I am
    > missing?

    yacc/lex will allow you to read/parse the file (using a grammar) but
    not write it.  I think it's better to write an OO parser which
    creates an object graph that you can read/write/modify.  There may be
    some frameworks that help you do this.  I usually roll my own.  BTW -
    GNU flex/bison are more modern implementations of lex/yacc.
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today