Atwood, Robert C said: ... (snobal text removed) ... > > Any thoughts on using a tool like lex/yacc / flex/bison for parser > generation?
For the parser that I am working on, I am using Python. I have the complete parser working now, using simpleparse, which uses an EBNF description as its input. I am currently working on the API and filling in the data structures from the callbacks. The basic structure of my parser is this: A) Run a preprocessor that does the following: 1) Determine if I am looking at pre-2.0 ABC or not. 2) Remove line continuations (doing it correctly depending on the ABC version) 3) Remove all % style comments (not %% directives) and store them for later use (if needed). 4) In pre-2.0 ABC files, if ! is used as a decoration marker (!ff!), then change it to 2.0 syntax: +ff+. 5) If an H: field is found in the header, then any lines that follow it that do not start with '%%' or have ':' as the second character will be changed to have 'H: ' before them. (I believe that this is a problem in the 2.0 specification, which says that the H: is a multiline header - it is a royal pain to do this nicely in the BNF, do I handle it here). 6) The %% syntax is irrelevant with the new I: format. As such, the %% syntax is removed and replaced with I: format. B) Use an EBNF description to completely parse the file. I am using an EBNF that I wrote that is based on the ABC 2.0 ABNF written by Henrik Norbeck. I added a couple of things to the EBNF to allow parsing older ABC files and corrected a number of mistakes and places where the grammar was ambiguous. C) The parser calls callbacks in python which I use to populate the data structures. I am still working on the data structures that I use. So far, I have been able to parse all of the ABC files in my small test suite (about 10 ABC files, including a couple of very large files). You can find the code as it stands right now at: http://www.purecode.com/~tsatter/python/ tom -- tom satter - or just plain old tom (303) 543-7623 (home) To subscribe/unsubscribe, point your browser to: http://www.tullochgorm.com/lists.html