=item 'char constant'
Are delimited by B<'>. They are taken to be C<ascii> encoded. No escape
sequences are processed.
But in fact B<'> behaves like B<"> without escapes or encoding/charset
prefixes:
rogers@rgrjr> cat foo.pir
.sub _main @MAIN
S1 = 'xyzzy\n'
print S1
print ascii:"\n"
.end
rogers@rgrjr> parrot foo.pir
xyzzy\n
rogers@rgrjr>
A syntax for specifying multiple characters without escapes seems like a
useful thing, a la Perl5, but being unable to specify an encoding or
charset seems less useful, even for a single character. In fact, I was
expecting a single character to be represented as an integer internally,
or at least to be easily converted to one, so I was surprised that this
didn't print "120\n":
rogers@rgrjr> cat bar.pir
.sub _main @MAIN
I1 = 'x'
print I1
print "\n"
.end
rogers@rgrjr> parrot bar.pir
0
rogers@rgrjr>
That would seem to be the one reasonable use for character constants,
but 'x' behaves no differently from "x" in this example.
So what should 'x' mean in PIR? I would suggest:
1. B<'> in PIR is like B<'> in Perl5, i.e. accept the status quo,
but add encoding/charset prefix syntax, and fix the doc; and
2. Support character constants via either string syntax by defining
I1 = 'x'
mean the equivalent of
S1 = 'x'
I1 = ord S1
to match my naive assumption. Does that sound reasonable?
-- Bob Rogers
http://rgrjr.dyndns.org/
> A syntax for specifying multiple characters without escapes seems like a
> useful thing, a la Perl5, but being unable to specify an encoding or
> charset seems less useful, even for a single character.
This is probably rather simply to fix: attach the same lexer rules to
CHARCONSTANT as done with STRINGCONSTANT and the verify and create a
string with the given encoding and charset.
> ... In fact, I was
> expecting a single character to be represented as an integer internally,
> or at least to be easily converted to one, so I was surprised that this
> didn't print "120\n":
>
> rogers@rgrjr> cat bar.pir
> .sub _main @MAIN
> I1 = 'x'
This is also not a big deal, mk_const() or such can handle this.
leo