I am trying to locate the root cause of an issue. I have the following line that needs to be parsed -
sample format "string";
Where sample
and format
need to be tokenized and whatever is in the inverted commas needs to be provided to the Parser file.
There is a catch however, if I have a perl style comment #
inside the string, then I get an error.
In the lexer.l
, I have the following -
stringIdentifier [^"]+
<STRING_S>{stringIdentifier} {
strncpy(yylval.str, yytext,1023);
yylval.str[1023] = '\0';
return IDENTIFIER;
}
<*>"//".* {
}
<*>"#".* {
}
<INITIAL>{s}{a}{m}{p}{l}{e} {
BEGIN(SAMPLE_S);
return SAMPLE;
}
<SAMPLE_S>{f}{o}{r}{m}{a}{t} {
return FORMAT;
}
<SAMPLE_S>"\"" {
BEGIN(STRING_S);
return INVERTED_COMMA;
}
<STRING_S>"\"" {
BEGIN(INITIAL);
return INVERTED_COMMA;
}
In the Parser.y
I have the following rule:
pass : SAMPLE FORMAT INVERTED_COMMA IDENTIFIER INVERTED_COMMA
{
};
However, when I give sample format "abc;"
it works, however, when I add a comment character #
in the string it fails. Could you please help with this