Re: Feedback for compiler project

iddekingej@lycos.com (J.van Iddekinge)
13 Oct 2001 23:10:16 -0400

          From comp.compilers

Related articles
Feedback for compiler project iddekingej@lycos.com (2001-09-20)
Re: Feedback for compiler project joachim_d@gmx.de (Joachim Durchholz) (2001-10-06)
Re: Feedback for compiler project iddekingej@lycos.com (2001-10-10)
Re: Feedback for compiler project joachim_d@gmx.de (Joachim Durchholz) (2001-10-12)
Re: Feedback for compiler project vbdis@aol.com (2001-10-12)
Re: Feedback for compiler project dmitry@elros.cbb-automation.de (2001-10-13)
Re: Feedback for compiler project iddekingej@lycos.com (2001-10-13)
| List of all articles for this month |
From: iddekingej@lycos.com (J.van Iddekinge)
Newsgroups: comp.compilers
Date: 13 Oct 2001 23:10:16 -0400
Organization: http://groups.google.com/
References: 01-10-027 01-10-050
Keywords: design, OOP
Posted-Date: 13 Oct 2001 23:10:16 EDT

vbdis@aol.com (VBDis) wrote in message news:01-10-050...
> iddekingej@lycos.com (J.van Iddekinge) schreibt:


If I look at the reaction of mine post, i think i need some more
explenation of what dynamic routines are. I had hoped that the text
somewhere at the Elaya home page (www.elaya.org) was enough. Please
look at the following text and give feedback. (This text is only a
small part, first i want feedback on this text)


Dynamic Routines.
=================


For understanding what Dynamic Routines are, just look at the
name. Dynamic Routiesare << Routines >>. They have nothing todo with
Objects/Classes. The only relationship with object/classes is the
same as normal routine/methods have with oop. Normal routines can be
used in procedural programming and as methods in classes. The same is
valid for dynamic routines. Next follow examples , wich show what
dynamic routine are used in procedural sitation. Forget everthing
about objects for a while. First if we look at a normal routine in
procedural programming, wich displays a file(In pascal):


procedure ShowTextFile(ParFileName : string);
var
vlFile : text;
begin
assign(vlFIle,ParFileName);
reset(vlFile);
if ioresult <> 0 then exit;
while not(eof(vlFile)) do begin
readln(vlFile,vlStr);
if ioresult <> 0 then break;
writeln(vlStr);
end;
close(vlFile);
end;


A routine wich access a file looks follow nearly the same sequence of steps:
1) Openfile
2) Do something
3) Closefile.


(It is also necessary to add some error checking, wich in many cases
isn't done properly.) All file operations follow above 3 steps. Every
time we must program the open the fileand close the file and code the
error checking. When normal routines are used we must program all
these steps. For this type of operation we can also use dynamic
routines:




procedure ProcessTextFile(virtual ParFileName :string);root;
protected
var
          vlFile:text;
protected


      function ReadLine(var pArStr):boolean;
      begin
readln(vlFile,ParStr)
if ioresult <> 0 then exit(true);
      end;


      function Eof:boolean;
      begin
exit(eof(vlFile));
      end;


      function DoSomeTHing:boolean;virtual;
      begin
exit(false);
      end;


      procedure Error;virtual;
      begin
      end;


begin
    Assign(vlFile,ParFileName);
    if ioresult <> 0 then begin
          Error;
    end else begin
          if DoSomeThing then Error;
          close(vlFile);
    end;
end;




The routines 'Readln', 'DoSomeThing' and 'Error' are defined inside
the routine 'ProcessTextFile'. These routine are only visible inside
the routine, and can access local variabels and the parameters. It is
not necessary too pass the a file variable when using readln, because
it can directly access the 'vlFile'.


Whe can now define a new dynamic routine, wich is based on above.
This is also done by 'inheritation'. When used in a dynamic routine a
new routine is created based on the parent routine. (Note:The
'inherited' has nothing to do whith 'inheritation' of an object.!!)


procedure PrintFile;inherit ProcessTextFile('me.cfg');
protected
var
vlLineCnt:long;
            function DoSomeThing:boolean;override;
var
vlStr : string;
            begin
vlLineCnt := 0;
while not eof do begin
readline(vlStr);
writeln(vlStr);
vlLineCnt := vlLineCnt + 1;
end;
exit(false);
            end;
begin
inherited of main;
writeln('Lines : ',vlLineCnt);
end;


The above routine means :
* Create a new routine wich is the same processtextfile but the routine
DoSomeThing is replace by a new one.
* The "('me.cfg')" is the parameter mapping. THis doesn't mean that
the parent is called with some parameter. The parameter 'ParFileName' in
ProcessTextFile is declared virtual. WHen a new Routine is derived from
ProcessTextFile this parameter can be removed from from the parameter list,
and initilized with a constand. (Parameter mapping is more complicated,
for more information see web site www.elaya.org)


In the above example it is not necesary to open,close the file and check
for error (Partly). It is also possible to cluster ReadLine,vlLineCnt, wich
makes it use easier. etc etc
Dynamic routines and even normal routines represents processen.
A process is 'A series of actions or operations used in making or
manufacturing or achieving something'.
The advantage of a dynamic routine is the same as object/classes, but
not regarding object but processes.


This is nicely showen when dynamic routines are used as a method in a class.
If we have a class TList, with childeren TNumberList and TStringList.
All these classes can contain the following methods :
      FindLargestValue
      ValidateValue
      PrintValue.


Dynamic routine/Class form a 2 dimension relations ship.
One dimension is 'class':
TList.LargestValue, TNumberList.FindLargestValue and TStringList.FindLargestValue
(Same for other mehods)


And the other dimension is 'dynamic routine'
FindLargestValue, ValidateValue and PrintValue.is where dynamic routine is used.


The reason why this is the same for both : Similarities (inherit), differences
(virtual),abstraction etc...


The usage of dynamic routine in 'OOP' is different as in procedural programming.
When thinking of 'but this can also be done with classes' remember that
you can choose of :Procedural, Procedural+Dynamic routine,OOP andOOP+Dynamic
routine. Beside that look at the following comparision.


Some comparision between dynamic routines and classes:
* Dynamic routine represnts processes and object/classes objects
* Dynamic routines don't need much RTL support and no dynamic memmory.
* From the outside a dynamic routine looks exactly the same as a normal routine.
* A dynamic routine can change its parameter
* Dynamic routine don't need to be Created and destroyd .


This text only is a introduction to dynamic routines. It took me a wile to
  understand the advantages and differences between using and combining classes
  and dynamic routines.(Warning the 'elaya' compiler doesn't contain OOP!! usage
of dynamic routines in classes are still theorie)
More information : www.elaya.org.


Greez,
Jer.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.