/*
 *  MODULE:  bintab.h
 *  binary tree operations
{*  last modification:  09.07.92  12:33   }
 *  uli 11.02.91 : binqueue added
 * Dima 13.02.91:  binparcompare & binncoers moved to idtab
		   compatible is named typ_compatible and made global
 *  uli 30.04.91 : binend, binf_stm added
 *  uli 06.05.91 : bincpool added
 *  uli 14.05.91 : binend, binstm, bincpool must be extern, not global
 * Dima 17.06.91 : tlist, tlistend added
 *  uli 18.06.91 : bin_istm, bin_fstm, deleted, binlist added.
 * Dima 15.07.91 : binlist made void
 * Dima 22.11.91 : typ_compatible moved to optab
 * PJ   09.07.92 : prototype definition for function binupdate deleted
                   ( there is no complete definition and it is never used ! )
*/


    /* global variables for the token read by the scanner: */

/*     postype  pos ;  is declared in scan.h                    */
global symctype symc ;      /* symbol code of the symbol read   */
global symptr   sym ;       /* pointer to symtab   "            */
global longint  symvalue ;  /* value of integer or char constant */
global char   * symstring;  /* value of string or real constant */

    /* global binptr variables used by the temp. vars. stack:    */
extern binptr  tlist ;
extern binptr  tlistend  ;

    /* global binptr variables used by the parser: */
extern binptr  bincurr ;     /* pointer to node created last */
extern binptr  binprev ;     /* pointer to node inserted into tree */
extern binptr  binqueue;     /* pointer to look ahead queue created by errecy */

    /* global binptr variables used by the semantic analysis: */
global binptr  bindecl ;     /* pointer where declarations may be inserted */

extern binptr  binstm  ;     /* pointer to statements to be inserted */
			     /* before the current statement */
extern binptr  binend  ;     /* pointer to statements to be appended */
			     /* behind the current statement */
extern binptr  bincpool ;    /* pointer to the constant pool */

global binptr  binroot ;     /* pointer to program or module node */

    /* Entries: */
#ifdef LINT_ARGS
						/* node creation */
global void    binget      (void) ;
global binptr  bincreate   (symctype symc);
global binptr  binidcreate (symctype symc, idptr id);
global binptr  binsycreate (symptr sym);
						/* tree modification */
global void    binsuffix   (void) ;
global void    bininfix    (void);
global void    binopinfix  (void);
global void    binprefix   (void);
global void    binpostfix  (void);
global binptr  binappend   (binptr p,binptr q);
global binptr  bininsert   (binptr p,binptr q);
global binptr  binlside    (binptr p,binptr q);
global void    binexchange (binptr);
global binptr  bindelete   (binptr p);
global void    binkill     (binptr p);
global void    binldelete  (binptr p);
global void    bintdelete  (binptr * p);
global void    binfunc     (binptr p,symptr sym);
global binptr  binproc     (binptr p);
global binptr  bintemp     (binptr p, symptr tempsym);
global void    binlift     (binptr p);
						/* moving thru tree */
global void    gofather    (void);
global void    goleft      (void);
global void    goright     (void); /* changes binprev */
global binptr  binfather   (binptr p);
global binptr  binleft     (binptr p);
global binptr  binright    (binptr p);
global binptr  bincont     (binptr p);
global binptr  binnext     (binptr p);
						/* node access */
global symctype binsymc     (binptr p);
global postype  binpos      (binptr p);
global symptr   binsym      (binptr p);
global idptr    binid       (binptr p);
global blockptr binblk      (binptr p);
global long int binvalue    (binptr p);
global char *   bincharp    (binptr p);
global opptr    binop       (binptr p);

						/* node modification */
global void    binchange   (binptr p, symctype symc) ;
global void    binuppos    (binptr p, postype  pos);
global void    binupsym    (binptr p, symptr   sym);
global void    binupid     (binptr p, idptr    id);
global void    binupblk    (binptr p, blockptr blk);
global void    binupvalue  (binptr p, long int value);
global void    binupcharp  (binptr p, char   * charp);
global void    binupop     (binptr p, opptr    op);
global void    binllink    (binptr p,binptr q);
global void    binrlink    (binptr p,binptr q);
global void    dump        (binptr p);
global boolean bincompare  (binptr, binptr);
global binptr  bincopy     (binptr);

						/* node request */
global binptr   unname      (binptr p);
global binptr   subtype     (binptr typ) ;
  /* returns the base type of a subrange or */
  /*  returns unname(typ), if not a subrange. */
global boolean  binisvariable (binptr p);
						/* decl generation */
global void     baptize     (binptr p); /* inserts a temp type decl. */
global binptr   tempdecl    (char prefix[2], binptr datyp) ;
						/* statement insertion */
global void   binlist     (binptr exp, binptr * root);

#else

global void    binget      () ;
global binptr  bincreate   ();
global binptr  binidcreate (/* symc, id */);
global binptr  binsycreate (/* sym */);
global void    binsuffix   () ;
global void    bininfix    ();
global void    binopinfix  ();
global void    binprefix   ();
global void    binpostfix  ();
global binptr  bininsert   (/* p,binptr q */);
global void    binexchange ();
global binptr  bindelete   (/* p */);
global void    binkill     (/* p */);
global void    binldelete  (/* p */);
global void    bintdelete  (/* *p */);
global binptr  binappend   (/* p,binptr q */);
global binptr  binlside    (/* p,binptr q */);
global void    binllink    (/* p,binptr q */);
global void    binrlink    (/* p,binptr q */);
global void    binfunc     (/* p,symptr sym */);
global binptr  binproc     (/* p */);
global binptr  bintemp     (/* binptr p, symptr */);
global void    binchange   () ;
global void    binuppos    ();
global void    binupsym    ();
global void    binupid     ();
global void    binupblk    ();
global void    binupvalue  ();
global void    binupcharp  ();
global void    binupop     ();

global void     gofather    ();
global void     goleft      ();
global void     goright     ();
global binptr   binfather   ();
global binptr   binleft     ();
global binptr   binright    ();
global binptr   bincont     ();
global binptr   binnext     ();
global symctype binsymc     ();
global postype  binpos      ();
global symptr   binsym      ();
global idptr    binid       ();
global blockptr binblk      ();
global long int binvalue    ();
global char *   bincharp    ();
global opptr    binop       ();
global void     baptize     ();
global binptr   unname      ();
global binptr   subtype     () ;
global boolean  binisvariable ();
global void     dump        (/* p */);
global boolean  bincompare  ();
global binptr   bincopy     ();
global binptr   tempdecl    ();
global void     binlift     ();
global void     binlist     ();

#endif


#define NIL (binptr)0



/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
/* The following declaration is necessary to satisfy forward declaration. */
/* Do not use the following names globally. */

typedef struct bin
  { struct bin *father, *right ; /* right = next = index = param = dummy */
    postype    pos ;
    byte      symc ;
    union
    { symptr      sym ;
      long int    value ;
      char *      charp ;
      idptr       id ;
      blockptr    blk ;
      opptr       op ;
      struct bin *left ; /* left = cont */
    } pt ;
  } binrecord ;


