for in D versus C and C++
Sean Kelly
sean at invisibleduck.org
Sat Mar 21 11:09:54 PDT 2009
Walter Bright wrote:
> Georg Wrede wrote:
>> Sometimes I need to have a command line UI in a program. Such programs
>> usually have 5 to 10 commands, with their parameters. One command per
>> line.
>>
>> So far I have tested and split the command line with regular
>> expressions, because using a parser generator has felt like shooting
>> mosquitos with a shotgun.
>>
>> What would your strategy be?
>
> If it's 5 or 10, you can get by with ad-hoc. But if you find yourself
> repeatedly fixing bugs in the parsing, it's time to consider a more
> principled approach.
I've found that once I created one lexer it could be re-used pretty
easily for other languages too. And recursive descent parsers are
trivial to write. It may be overkill for command-line parameters, but
for anything remotely structured it's generally worth using.
More information about the Digitalmars-d
mailing list