|
UnixReview.com
September 2005
Regular Expressions: Two Easy Steps Better Than One Hard One
by Cameron Laird and Kathryn Soraiz
This year, Regular
Expressions has frequently commented on the advantages of learning the idioms
specific to a particular language. Let's look now at a few underappreciated
approaches to parsing that apply to a broad class of languages and how they
might benefit your own development.
Two overdone parsing techniques are yacc
and complicated regular
expressions (REs). Powerful as they are — the name of this column
hints at our appreciation of the latter — they also poorly fit many of
the situations where incompletely educated programmers try to apply them. Phaseit
just finished a string of several months of consulting with successive clients
whose coincidental overreliance on REs made trouble for them.
Structuring program and data
One engaging alternative to "normal-form"-oriented
parsing is "partial evaluation" (PE) or "active data". Several distinct labels
capture parts of the ideas at work in this area; we'd welcome help from readers
on more precise or at least widely recognized names. PE, as we'll present it
here, is most accessible in "scripting
languages", Lisp, Forth, m4, and others that expose programmatic access
to the language parser.
|