Lots of problems. First, your lexer is confused, trying to recognize quoted strings and braced things as a single VALUE
as well as trying to recognize single characters like "
and {
. For quotes, it makes sense to have the lexer recognize the whole string, but for structural things that you want to parse (like braced lists), you need to return single tokens for the parser to parse. Second, when allocating space for a string, you aren't allocating space for a NUL-terminiator. Finally, your grammar looks odd, wanting parse things like = VALUE = VALUE
as a KeyValue, which doesn't correspond to anything in a bibtex file.
So first, for the lexer. You want to recognize quoted strings and identifiers, but other things should be single characters:
[A-Za-z][A-Za-z0-9]* { yylval.sval = strdup(yytext); return KEY; }
\"([^"\]|\\.)*\" { yylval.sval = strdup(yytext); return VALUE; }
[ \t\n] ; /* ignore whitespace */
[{}@=,] { return *yytext; }
. { fprintf(stderr, "Unrecognized character %c in input\n", *yytext); }
Now you need a parser for the entries:
Input: /* empty */ | Input Entry ; /* input is zero or more entires */
Entry: '@' KEY '{' KEY ',' KeyVals '}' ;
KeyVals: /* empty */ | KeyVals KeyVal ; /* zero or more keyvals */
KeyVal: KEY '=' VALUE ',' ;
That should parse the example you give.