Data Structures of GRP Parser

In this section we describe data structures of the GRP parser library and give some advice how to use it.

Data structures

Parser(PParser)

Tips how to use GRP parser

PParser Parser
data: 
      PprsAppColl Apps /* collection of TprsApplication */
          |
          V
      TprsApplication
      data:
            char           *Name
            PprsGroupColl  Headers[prsthLast+1]
            PprsProcColl   ProcColl            /* Collection of TprsProcess */
            PprsWindowColl Windows
Parser object represents the GRP parser. It stores application objects in a collection. If you would like to use your own type of applications you need override TParser::MakeAppColl() method and make your special collection. TprsAppColl collection makes a lot of other objects when the parser parses the input files. If you would like to use your own types of objects you should override some virtual methods of TprsAppColl.

Parameters defined in HeaderPart are made by TprsAppColl::MakeParam() methods. There are several MakeParam methods with different type of arguments to make different type of parameters.

TprsAppColl::MakePort() method makes a port object (TprsPort). It comes from GRP's PortSection of the ProgramPart and goes into the port list of the process object. The TprsAppColl::MakePortRef() method makes a TPortRefAndSrc object which represents a reference to a port. It is used in CAI, CAO, etc. type of program items and it goes to program items' port reference list. TprsAppColl::MakeProgramItem() method makes the new program item objects. They are inserted into a list of process object.

All program items have connections to others. These connections are represented by TprsConn class which is made by TprsAppColl::MakeConnection() method.

If you would like to do something with every applications then you can do it in the following ways:

  1. You can use itarator methods of the collections. It requires a global function:
    void DoSomething(PprsApplication app, void *p)
    {
      app->...
    }
    
        .
        .
      Parser->Apps->ForEach(DoSomething, NULL);
        .
        .
    
  2. Or you can use for cycle:
        .
        .
      int i;
      PprsApplication app;
    
      for (i= 0; i < Parser->Apps->GetCount(); i++)
        {
          app= PprsApplication(Parser->Apps->At(i));
          app->...
        }
        .
        .
    
Parser->Apps->Headers[] /* Collection of TprsGroup */
     |
     V
  TprsGroup
  data:
        char        *Name
        PCollection Params /*Collection of TprsValueColl */
		      |
		      |
		      V
               TprsValueColl /* Collection of TprsParam (abstract),
                                              TprsIntParam,
                                              TprsFloatParam,
                                              TprsStringParam */

Parser->Apps->ProcColl /* Collection of TprsProcess */
     |
     V
  TprsProcess
  data:
        char         *Name
        PCollection  Globals    /* Coll of TprsSource */
        PCollection  Locals     /* Coll of TprsSource */
        PCollection  Heads      /* Coll of TprsSource */
        PprsPortColl Ports      /* Coll of TprsPort */
        PprsItemColl PrgItems   /* Coll of TprsItem */
Process objects are created by TprsProcColl::MakeProcess() method. If you would like to use your special kind of processes you need override this method. To do this In your own type of process object you can override TprsProcess::MakeItemColl() to make your special collection of program items or TprsProcess::MakePortColl() to make your port collection. At this stage of the parser you need not do this because there is not any special action is implemented by virtual methods in these collections.

If you are going to do something with every processes you can do it in the following way:

  int ia, ip;
  PprsApplication app;
  PprsProcess     proc;

    .
    .
  for (ia= 0; i < Parser->Apps->GetCount(); ia++)
    {
      app= PprsApplication(Parser->Apps->At(ia));
      for (ip= 0; i < app->ProcColl->GetCount(); ip++)
        {
          proc= PprsProcess(app->ProcColl->At(ip));
          proc->...
        }
    }
    .
    .
Or you can use iterator methods as you can see in previous examples.
Parser->Apps->ProcColl->Ports /* Collection of TprsPort */
     |
     V
  TprsPort
  data:
        prsTPortType Type
        int          SID
        char         *ProcName
        int          ToSID
        char         *TypeString /* "from","to" */
        PCollection  DataTypes   /* Coll of TPortData */

Parser->Apps->ProcColl->Ports->DataTypes /* Coll of TPortData */
     |
     V
  TPortData
  data:
        prsTDataType Type
        int          Num
Parser->Apps->ProcColl->PrgItems /* Collection of TprsItem */
     |
     V
  TprsItem
  data:
        char         *Name
        prsTProgType Type
        int          iID
        PprsSource   Source[2]     /* First 2 C-Source (or NULL) */
        PCollection  Connections   /* Coll of TprsConn */
        PCollection  Ports         /* Coll of TPortRefAndSrc */
        PprsItemColl NestedItems   /* Coll of TprsItem */
NestedItems collection holds every nested items of this item. It must be NULL unless the type of the item is ptGRAPHIC.
Back to Grapnel Compiler.