Re: Unquoted strings in BASIC

Maury Markowitz <[email protected]> Sun, 1 Dec 2024 21:10:31 -0500
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
> On Nov 30, 2024, at 8:42=E2=80=AFPM, James K. Lowden =
<[email protected]> wrote:
> I'm just a bit skeptical.  If the rule is that=20
>=20
>> DATA 10,20,"HELLO,WORLD!"
> and
>> DATA 10,20,HELLO,WORLD!

> Or is it the case that the quoted equivalent would be=20
>=20
>> DATA 10,20,"HELLO","WORLD!"

This. It's basically CSV, and given the company in question, I'm sure =
that's where MS CVS comes from.

> DATA { yy_push_state(data); }

Is there a difference between yy_push_state(data) and BEGIN(data)?

> then define the start condition and its rules:
>=20
> <data>{
>  [[:alpha:]]/[^,\r\n] { /* ... */ return STRING; }
>  [\r]?[\n] { yy_pop_state(); }
> }

There's some syntax here that's new to me. I believe [:alpha:} is only =
A-Za-z, yes? If so that is not correct, as 'one', 'one!' and 'one1' are =
all valid.

The / I had not seen before. If I understand it correctly it means "the =
thing on the left, but only if it's followed by the one on the right". =
Is that correct? So in this case the string 'one,"two"' would initially =
match the alpha 'o' and the continue matching n and e, then stopping =
because it hit the comma. If so, this appears to be what I need, but =
when I tried it, it never matched. I changed [:alpha;] to A-Za-z as =
maybe the :alpha: was a problem in clang, but that didn't match either. =
For fun I removed the ^, and then did match, but it matched only one the =
'o', which I *assume* was the trailing o in 'two'.

I had managed to get to this point for testing the conditional states:

<DATA>[^0-9][A-Za-z]*[,:\n] {
            yytext[strlen(yytext) - 1] =3D '\0';
            yylval.s =3D str_new(yytext + 1);
            return STRING;
          }

Used on:

10100 DATA "one",two,"three"

It correctly passes "one" and "three" using the normal quoted string =
rule, but when it gets 'two' I get ',two,' (with leading and trailing =
commas). This means it no longer matches the bison rule that has an =
expression ',' expression. Is there a way to "rewind" one character to =
emit the commas? I think that might do it.=