home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lr.zip / SAMPLE.C < prev    next >
Text File  |  1993-05-15  |  4KB  |  99 lines

  1.  
  2.  
  3.  #include "sample.h"
  4.  /*
  5.   ╔════════════════════════════════════════════════════════════════════════════╗
  6.   ║ Copyright (C) Transcendental Automation, 1993.                             ║
  7.   ╟────────────────────────────────────────────────────────────────────────────╢
  8.   ║ SAMPLE.C - The main file of project.                                       ║
  9.   ╟────────────────────────────────────────────────────────────────────────────╢
  10.   ║ This file contains next functions:                                         ║
  11.   ║                                                                            ║
  12.   ║ void main(void)                                                            ║
  13.   ║ void InitAll(char *s) - Initialize all resources and load file passed as   ║
  14.   ║                         first argument of prgram or (if nothing was passed ║
  15.   ║                         to programm) 'sample.txt'.                         ║
  16.   ║                                                                            ║
  17.   ║ void FreeAll(void)   - Rlease all resources                                ║
  18.   ╟────────────────────────────────────────────────────────────────────────────╢
  19.   ║ Description of program:                                                    ║
  20.   ║ This program is an interpreter of simple grammar.                          ║
  21.   ║ First program initialize stack of float , vartable ,load compiled grammar  ║
  22.   ║ and so on. Then it launch parsing of the text contained in file passed as  ║
  23.   ║ argument or 'sample.txt'.Then program free all allocated resources.        ║
  24.   ╚════════════════════════════════════════════════════════════════════════════╝
  25.  
  26.  Requred files:
  27.  
  28.        TABLE.C
  29.  
  30.        COMMANDS.C
  31.  
  32.        SAMPLE.H
  33.  
  34.        SAMPLE.MAK
  35.  
  36.        SAMPLE.GR
  37.  
  38.   */
  39.  
  40.  LRSAF cmd[SAMPLE_n];
  41.  SAMPLE_NPS NTPS;             // nonterminal pointer set
  42.  LR2      *grammar;          // Pointer to compiled grammar
  43.  
  44.  void    InitAll(char *);
  45.  void    FreeAll();
  46.  char    *parse_text;              // text to parse
  47.  
  48.  /*
  49.  ___________________________________________________________________________
  50.   The main function
  51.  ___________________________________________________________________________
  52.  */
  53.  int main(int e,char **s)
  54.   {puts("Copyright (C) Transcendental Automation, 1993.");
  55.    if(s[1]==0)
  56.      puts("Usage : sample [input_file]");
  57.    InitAll(s[1]);
  58.    puts("Processing...");                                                                                                /**/
  59.    lrx_parse(0,0,cmd,(LRX_PT*)&NTPS,grammar,parse_text,STACK_SIZE,0);//launch parsing of text
  60.                                                        //then semantics action.                                                                                                /**/
  61.    FreeAll();
  62.  }
  63.  /*
  64.  ______________________________________________________________________________
  65.   This function initializes all needed resources.
  66.  ______________________________________________________________________________
  67.  */
  68.  void InitAll(char *name)
  69.   {//initialize internal tables.
  70.    InitTable       (); // initializing vartable.
  71.    InitFloatStack  (); // initializing stack of floats.
  72.    InitCmdTable    (); // initializing table of semantic actions.                                                                                               /**/
  73.    lr2_open(&grammar,"sample.lrs"); //open compiled grammar
  74.    parse_text = u_load_ds( name ? name : "sample.txt" );//load file to memory                                                                                                                                     /**/
  75.    printf("Input file : %s\n",name ? name : "sample.txt");
  76.    if(!parse_text)
  77.     {puts("Error : unable to open input file.");
  78.      exit(3452);
  79.     }
  80.    puts("Input text :");
  81.    puts(parse_text);
  82.   }
  83.  
  84.  /*
  85.  ______________________________________________________________________________
  86.   This function releases all allocated resources.
  87.  ______________________________________________________________________________
  88.  */
  89.  
  90.  void  FreeAll(void)                                                                              /**/
  91.   {u_free_ds(parse_text);    // free alocated memory
  92.    lr2_free(grammar);  // release compiled grammar                                                                                 /**/
  93.    FreeTable       (); // free vartable.
  94.    FreeFloatStack  (); // freestack of floats
  95.  
  96.   }
  97.  
  98.  
  99.