I'd like to be able to parse the following structure:
blah
{
"string-1",
"string-2",
...,
"string-n"
}
I'm using flex to tokenize, and that's working perfectly. I'm using yacc (bison) for the parsing.
What's the recommended way to allow this structure? Right now, in my test.y file, I've got:
blah_command:
BLAH OPEN_BRACE string_list CLOSE_BRACE
{
printf( "String list is %s\n", $3 );
}
string_list: /* empty */
|
STRING
{
return $1;
}
|
STRING COMMA string_list
{
strcat($1, ",");
strcat($1, $3);
}
I suspect the strcat() is a really, really bad idea. I'm a real novice when it comes to lex/yacc (about 3 hours experience) so a smack on the wrist and a pointer in the right direction would be great.
EDIT: The goal of this is to allow me to build a test harness for an external application. The lexing/parsing will be used to interpret a test script that the user provides. One command allows the user to send a message to the application, then I read the multi-line response and compare with the variable length list of strings the user has provided in the script. The fragment I've posted above is the way I figured I'd let the user define the possible response.
For example:
blah
{
"COMMAND EXECUTED CORRECTLY"
}
or
blah
{
"QUERY COMPLETE IN .0034 SECONDS",
"1 RECORD FOUND:",
"FOO=12345",
"--END OF LIST--"
}