[fpc-pascal]absolute identifier

the reverend the.reverend at coastgames.com
Tue Mar 26 15:43:53 CET 2002


thanks for the help.  i got it to work last night by using length(yytext)
and removing all references to yyleng.  any time the original code assigned
yyleng:=n, i replaced with setlength(yytext,n).  the code works fine.  the
only thing that is lost in function is the easy access to yyleng, but that's
not really a great loss i don't think.  i shouldn't be able to notice much
of a performance hit.

the reverend
(: the goodguys :)
icq 83250263
http://thereverend.coastgames.com/tradewars/


-----Original Message-----
From: fpc-pascal-admin at deadlock.et.tudelft.nl
[mailto:fpc-pascal-admin at deadlock.et.tudelft.nl]On Behalf Of Full_Name
Sent: Tuesday, March 26, 2002 4:49 AM
To: fpc-pascal at deadlock.et.tudelft.nl
Subject: Re: [fpc-pascal]absolute identifier


Quoting ron wilson <ron.wilson at coastgames.com>:


>   type
>     tyyvars = record
>       yyinput, yyoutput : Text;        (* input and output file *)
>       yyline            : String;      (* current input line *)
>       yylineno, yycolno : Integer;     (* current input position *)
>       yytext            : String;      (* matched text (should be
> considered
> r/o) *)
>       yyleng            : Byte         (* length of matched text *)
>         absolute yytext;
>     end;
>
> i get the following error:
> Fatal: Syntax error, ; expected but identifier ABSOLUTE found

This relies on two things. 1: you are using Pascal strings (255 chars, first
char (position 0) is length of string) and 2: that the address in memory of
yytext will be constant, hence globals. This is never going to work nicely,
but
a call to 'length(yytext);' gives the same value.

You could write a routine to do something with this info:

procedure populateyyvarsdata(var data: tyyvars);
begin
  data.yyleng := length(yytext);
end;

You could write this better as a class :

   type
     tyyvars = class(TPersistent)
     private
       fyytext            : String;
     public
       yyinput, yyoutput : Text;        (* input and output file *)
       yyline            : String;      (* current input line *)
       yylineno, yycolno : Integer;     (* current input position *)
       property yyleng : integer read getyyleng;
       property yytext : string read getyytext;
     end;

...

function getyyleng: integer;
begin
  result := length(fyytext);
end;

function getyytext: string;
begin
  result := fyytext;
end;

...

Because TPersistent is streamable, you should be able to pass it about as
text.
(ObjectBinaryToText and ObjectTextToBinary in Delphi.)

Just a thought anyways,

Matt


--

"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------

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal





More information about the fpc-pascal mailing list