[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Unquoted strings in BASIC
From: |
James K. Lowden |
Subject: |
Re: Unquoted strings in BASIC |
Date: |
Tue, 3 Dec 2024 15:24:12 -0500 |
On Tue, 3 Dec 2024 17:57:13 +0100
Hans Åberg <hans.aberg_1@icloud.com> 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.
> > 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.
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 */ }
[,]
[^,\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.,
DATA "hello,2
That means you needs patterns like
["][^"]*$ { return ERROR_TOKEN; }
to tell the parser the DATA is borked.
We have certainly flogged this horse good and well. I hope it's been
helpful and that your BASIC interpreter soldiers on.
--jkl
- Re: Unquoted strings in BASIC, (continued)
- Re: Unquoted strings in BASIC, EML, 2024/12/01
- Re: Unquoted strings in BASIC, James K. Lowden, 2024/12/01
- Re: Unquoted strings in BASIC, Maury Markowitz, 2024/12/01
- Re: Unquoted strings in BASIC, Hans Åberg, 2024/12/02
- Re: Unquoted strings in BASIC, James K. Lowden, 2024/12/02
- Re: Unquoted strings in BASIC, Hans Åberg, 2024/12/02
- Re: Unquoted strings in BASIC, Maury Markowitz, 2024/12/03
- Re: Unquoted strings in BASIC, Hans Åberg, 2024/12/03
- Re: Unquoted strings in BASIC,
James K. Lowden <=
- Re: Unquoted strings in BASIC, Hans Åberg, 2024/12/04
- Re: Unquoted strings in BASIC, Maury Markowitz, 2024/12/04