Re: Unquoted strings in BASIC
"James K. Lowden" <[email protected]> Tue, 3 Dec 2024 15:24:12 -0500
| Newsgroups | gmane.comp.parsers.bison.general |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 3 Dec 2024 17:57:13 +0100 Hans =C5berg <[email protected]> wrote: > In general, one tries to exploit tokens to do special things, which > is also useful in a Bison parser when adding mid-rule actions. That's good advice, hard-won. =20 > > it seems it is much easier to parse everything in the data section > > as a string I think you mean to lex each element in the DATA line, removing the quotes, but not distinguish between number and string? IIUC that will work fine. Those elements don't *have* a type until they're assigned to a variable; until then, they're just data, just as is true for any other kind of input. =20 It occurs to me you could have an exclusive start condition that could look like this: DATA[[:blank:]]+{ yy_push_state(data); ... } <data>{ ["][^"]*["] | ['][^']*['] { /* use yytext +1, minus trailing quote */ } [,]$ { /* return empty string */ } [,]/[,] { /* return empty string */ } [,]=20 [^,\r\n]+ { return yytext as string */ [\r]?[\n] { yy_pop_state(); } } There is a difficulty: an erroneous DATA line. You have to allow for missing closing quotes e.g.,=20 DATA "hello,2 That means you needs patterns like ["][^"]*$ { return ERROR_TOKEN; } to tell the parser the DATA is borked. =20 We have certainly flogged this horse good and well. I hope it's been helpful and that your BASIC interpreter soldiers on. =20 --jkl