[fpc-pascal]absolute identifier
Full_Name
memsom at post.interalpha.co.uk
Wed Apr 10 17:31:48 CEST 2002
Quoting Jonas Maebe <jonas at zeus.rug.ac.be>:
>
> On dinsdag, maart 26, 2002, at 04:43 , ron wilson wrote:
>
> > so in my application, yyleng is referencing the length of the string,
> > yytext, by using the absolute identifier. i thought i could change
> all
> > references to yyleng to length(yytext), but the lexer often assigns
> > yyleng
> > manually (ugh!), e.g. yyleng:=n; OR inc(yyleng);.
>
> You can use setlength(yytext,n) and setlength(yytext,length(yytext)+1)
> in those cases. But when you're using ansistrings, make sure you do
> those length adaptions *before* you write anything past the previous
> end-of-string, since otherwise you'll get segmentation faults.
This is why I suggested using a class earlier. If he used a property he could
have an internal variable that did the job.
Actually, inc-ing an absolute is stupid in this respect, because pascal will
not allow you to read past the end of the string anyway (not in Delphi 5)
try the following:
var
s: string[10];
sa: Byte absolute s;
a: Integer;
procedure Test
begin
s := '1234567890';
Inc(sa);
a := sa;
s[a] := 'a';
ShowMessage(IntToStr(Length(s)) + ' ' + s + ' ' + s[a]);
Inc(sa);
a := sa;
s[a] := 'b';
ShowMessage(IntToStr(Length(s)) + ' ' + s + ' ' + s[a]);
end;
The above works up to a point, but is really unstable. The second showmessage
is unable to resolve s[a] to be a value.
--
"Computer games don't affect kids; I mean if Pac-Man affected us as kids,
we'd all be running around in darkened rooms, munching magic pills and
listening to repetitive electronic music."
Kristian Wilson,
Nintendo, Inc, 1989
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s+++:+ a- C++ UL+ P L++ E---- W- N+ o+ K- w
O- M V PS PE-- Y PGP- t- 5-- X- R- tv+ b+ DI++ D+
G e++ h--- r+++ y+++
------END GEEK CODE BLOCK------
More information about the fpc-pascal
mailing list