0
votes

I am trying to figure out how to check for the delimiting quote in a literal string. Any help is appreciated.

Here is what I have so far in my start condition.

<stringLiteral>INITIAL   {value = ""; beginLine = lineNum; beginCol = colNum; }
<stringLiteral>\\n       {cout<<"\n"; newline();}
<stringLiteral>\"        {yylval.sval = new string(value); return STRING;}
<stringLiteral>\\.       {error(linenum, colnum, string(YYText()) + " illegal token");}​
1
Nothing is obviously wrong with the \" rule. What is it that doesn't work for you? - rici
If the Literal String doesn't have a ending quote. say for example: "This is a string . - pdf2e
Unfortunately, missing characters are invisible, since they only exist in the imagination. ("What might have been is an abstraction / Remaining a perpetual possibility / Only in a world of speculation." -TS Eliot). So the scan will continue to the beginning of the next string, if any, or the end of the file. Or, if you don't allow line ends in string literals, to the end of the line. Recovering and continuing the parse is difficult, although if you forbid newlines, there is some possibility of continuing with the next line and hoping you didn't miss too much. - rici

1 Answers

0
votes

(The question was answered in the comments by @rici and copied here; see also Question with no answers, but issue solved in the comments (or extended in chat) )

Nothing is obviously wrong with the \" rule.

If the Literal String doesn't have a ending quote. say for example: "This is a string it causes a problem of an unterminated string.

Unfortunately, missing characters are invisible, since they only exist in the imagination. ("What might have been is an abstraction / Remaining a perpetual possibility / Only in a world of speculation." -TS Eliot). So the scan will continue to the beginning of the next string, if any, or the end of the file. Or, if you don't allow line ends in string literals, to the end of the line. Recovering and continuing the parse is difficult, although if you forbid newlines, there is some possibility of continuing with the next line and hoping you didn't miss too much.