[Tutor] Language parsing

dman dsh8290@rit.edu
Tue, 27 Nov 2001 23:32:25 -0500


On Wed, Nov 28, 2001 at 03:49:22AM +0000, Allan Crooks wrote:
| Hi,
| 
| I'm planning to write a program which uses configuration files 
| similar to those of fetchmail (an example of which can be found 
| here: http://www.tuxedo.org/~esr/fetchmail/fetchmail-man.html#24)
| 
| I was wondering if anyone could recommend tools to help me 
| process the configuration file (something which would require me to 
| define a grammar and so on), 

SPARK is pretty popular.  There are others too, just search for "lex"
in the Vaults of Parnassus.

| or whether it's a lot easier to write my own parser?

No.

In my Comp. Sci. 4 class we had a project to make an interpreter in
C++ for a language that was ridiculously simple.  It took quite a bit
of effort in design and implementation (also not using regexes because
I didn't know them at the time, nor do I know of any C++ regex
libraries now).

The following year in my Prog. Lang. Concepts class we were introduced
to Lex and Yacc and given the assignment (not project) to make a
calculator that would support C-style comments and be flexible about
whitespace in the same way all modern programming languages are.
These requirements are extremely similar to the interpreter from CS4,
except the input rules were less strict (the CS4 project required
whitespace around all tokens, etc).  It only took a couple of hours
to implement this program in C because lex and yacc did all the hard
work of parsing and tokenizing the input.

The moral is to go with a parser-generator, don't reinvent the wheel.

(unless the grammar is so ridiculously simple that it isn't a wheel,
but merely a spoke)

| I should point out that I what I intend to write would actually be a 
| replacement for fetchmail, so if I could find some simple tool to 
| understand it's syntax as well, that would be wonderful. :)

The more consistent a grammar is, the easier it is to make a parser.
The fetchmailconf grammar is pretty loose, but I don't think it will
too bad since most of the looseness is in noise words.

HTH,
-D

-- 

the nice thing about windoze is - it does not just crash,
it displays a dialog box and lets you press 'ok' first.