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

I have input blocks of text with commands and arguments, one per line, for example

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

And I want to check that the arguments for are XYZwell-formed for this particular command and execute the correct block of code, if any. There is something like ~ 100 commands, some of which have a variable number of arguments, different relationships (i.e. if a command was called XYZ, then I also need to call the command ABC).

There are also commands:

COMMAND
XYZ ARG1
BEF ARG1 ARG2
ENDCOMMAND

It is important that the text is contained in COMMANDand ENDCOMMAND.

Usually 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 on MSDN that does this, and not the old C Lex and Yacc school?

+3
source share
6 answers

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

+5
source

ANTLR , , # ( Java, ++ Python). , . , YACC.

+4

, "", , - C-ish #. Boost newfangled.

, , - , Grammatica Spart ( Google)

EDIT: , , ANTLR #. ANTLR , LEX/YACC, .

+1

. , , . - , ANTLR .

+1
+1

.NET Framework , .

, , . , .

0
source

Source: https://habr.com/ru/post/1707821/


All Articles