[lug] Advice on writing a config file (probably XML)
Bear Giles
bgiles at coyotesong.com
Mon Dec 15 23:10:22 MST 2003
Timothy C. Klein wrote:
> I don't really know what advantages XML would have
XML parsers are standard with many languages and a low-cost way of
reading in structured data. With some tools your program can work
exclusively with the DOM and let the library handle all import and
export work.
> but LEX and YACC
> (flex and bison versions from GNU) are tailor made for this job.
Ha ha ha ha!
No they aren't. LALR(1) grammars are fairly expressive - you can
write a surprisingly decent NLP parsers in yacc. That's the
technical reason why I have long felt that programming languages
*are* a human language to communicate to other programmers as much
as they're instructions to a machine - limited vocabulary and
sentence structures, but if we're honest the vast bulk of our
spoken words are LALR(1). (Mapping the sentence diagramming you
were taught in school to yacc grammars is left as an exercise for
the reader.)
But config files are simple enumerations of facts, and you don't
need a LALR(1) grammar for that. A PDA is powerful enough to
handle arbitrary nesting, and a fraction of the complexity of a
LALR(1) parser. That's what XML is.
Even if you write your own parser, if you want extensibility
you'll end up with something similiar in feel to XML anyway. I
know, I've been there when redesigning file formats in pre-XML
format. We called it nesting name-value pairs, e.g.,
(foo => bar)
(baz => (Boulder => Udall, Denver => DeGette))
but it's easily recognized as attribute-less XML with different
coloring.
More information about the LUG
mailing list