Reserved word...

Hello,

Pascal script. Any way to ask the scripter if a word is reserved?

Thanks,

Mark

Unfortunately not. But you can copy and paste from scripter source code itself.

The following code is used to check if the id is valid one.

   result := (id<>'begin') and
             (id<>'end') and
             (id<>'var') and
             (id<>'try') and
             (id<>'except') and
             (id<>'finally') and
             (id<>'do') and
             (id<>'if') and
             (id<>'then') and
             (id<>'while') and
             (id<>'for') and
             (id<>'repeat') and
             (id<>'until') and
             (id<>'case') and
             (id<>'with') and
             (id<>'not') and
             (id<>'and') and
             (id<>'or') and
             (id<>'xor') and
             (id<>'div') and
             (id<>'mod') and
             (id<>'shl') and
             (id<>'shr') and
             (id<>'is') and
             (id<>'as') and
             (id<>'procedure') and
             (id<>'function') and
             (id<>'program') and
             (id<>'to') and
             (id<>'step') and
             (id<>'const') and
             (id<>'forward');

Thank you.

I added a few more words to my list:

break
const
continue
downto
exit
unit
uses
If anyone wanted/needed.

function TLogicMain.IsWordReserved(const aWord: string): boolean;
const
 reserved:array [0..37] of string = ('and','as','begin','break','case','const','continue',
                                     'div','do','downto','end','except','exit','finally',
                                     'for','forward','function','if','is','mod','not','or',
                                     'procedure','program','repeat','shl','shr','step','then',
                                     'to','try','unit','until','uses','var','while','with',
                                     'xor');
var
 i:integer;
 lowered:string;
begin
 result:=false;
 lowered:=LowerCase(aWord);
 for i:=0 to high(reserved) do
  if (lowered = reserved) then
   begin
    result:=true;
    Break;
   end;
end;

Not sure why the editor removed the

When I preview the post it ( [ i ] ) is removed.

This line : if (lowered = reserved) then
is really: if (lowered = reserved [ i ] ) then :

Forum bug?
Plus why is there not a formatting option for code, like other programming forums?

BBCodes does a simple formatting.

you can write your code in the [ CODE ] block.


function TLogicMain.IsWordReserved(const aWord: string): boolean;
const
 reserved:array [0..37] of string = ('and','as','begin','break','case','const','continue',
                                     'div','do','downto','end','except','exit','finally',
                                     'for','forward','function','if','is','mod','not','or',
                                     'procedure','program','repeat','shl','shr','step','then',
                                     'to','try','unit','until','uses','var','while','with',
                                     'xor');
var
 i:integer;
 lowered:string;
begin
 result:=false;
 lowered:=LowerCase(aWord);
 for i:=0 to high(reserved) do
  if (lowered = reserved [ i ] ) then
   begin
    Result := true;
    Break;
   end;
end;