I'm trying to parse a legacy language (which is similar to 'C') using FLEX and BISON. Everything is working nicely except for matching strings.
This rather odd legacy language doesn't support quoting characters in string literals, so the following are all valid string literals:
"hello"
""
"\"
I'm using the following rule to match string literals:
\".*\" { yylval.strval = _strdup( yytext ); return LIT_STRING; }
Unfortunately this is a greedy match, so it matches code like the following:
"hello", "world"
As a single string (hello", "world
).
The usual non-greedy quantifier .*?
doesn't seem to work in FLEX. Any ideas?