R – Best modern text parsing? AKA When to use Lex and Yacc

lexparsingregexyacc

I have as input blocks of text with commands and arguments, one per line, such as

XYZ ARG1,ARG2,ARG3,...,ARGN

And I want to verify that the arguments to XYZ are well formed for that particular command and execute the correct block of code if they are. There are something like ~100 commands, some of which have variable numbers of arguments, different relationships (i.e. if command XYZ was called then I need to have command ABC called as well).

Also commands exist such as:

COMMAND
XYZ ARG1
BEF ARG1 ARG2
ENDCOMMAND

It is important that the text is contained within COMMAND and ENDCOMMAND.

Typically for something like this I would use Lex and Yacc rather than regex's, but is there anything more modern? The code is written in C#. Is there anything in MSDN that does this rather than old school C Lex and Yacc?

Best Solution

If you are looking for an alternative to Lex/Yacc, check out ANTLR. It supports code generation in a variety of lanagages, including C#.

Related Question