/*************************************************************************/
/*                                                                       */
/*        token.h - Built by Eric Lavillonniere on Tandon 386 - 89  */
/*                                                                       */
/*************************************************************************/
/* This file is part of metagen                                             
   
   Metagen is a syntaxic analyser generator with backtrack.
   
   It runs on dos and unix. It generates c code. */
/* Copyright(C) 1989 Eric Lavillonniere */
/*
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 1, or (at your option)
   any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING. If not, write to 
   the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   
   */
/*
   Eric Lavillonniere - 26 January 1994 
     Add Functions for storing position in tree GetPosComment ....
   Eric Lavillonniere - 12 October 1993
     Remove arity tab since it is coded in the nodes
   Eric Lavillonniere - 4 October 1993 
     Modify *_EXIT macros. They dont call any longer sprintf
   Jean-Philippe Jouve - 29 September 1993
     Add facilities for debugging ;
     Add GetErrorLine GetErrorToken ResetError ;
   */
#ifndef TOKEN_LOADED
#define TOKEN_LOADED        1
#ifdef DOS
/* #undef __GNUG__  */
#endif
#include <stdio.h>
#ifdef DOS
#include <_string.h>
#else
#include <string.h>
#endif
#ifndef SONY
#ifndef I386
#include <malloc.h>
#endif
#endif
#ifdef SUN
#include <sys/types.h>
#include <sys/stat.h>
#ifndef DOS
#define O_BINARY        0
#endif
#if LINUX || I386
#define PARAM(y) y
#else 
#define PARAM(y) ()
#endif
#define _fastcall        
#define _far        
#define __far        
#else 
#define PARAM(y) y
#ifdef __cplusplus
#include <io.h>
#include <stdlib.h>
#endif
#endif
#if SUN
#include <unistd.h>
#endif
#if LINUX || I386 || SOLARIS
#include <stdlib.h>
#if ! SOLARIS && !DOS
#include <varargs.h>
#endif
#endif
#define RIEN       
#define DEBUT_EXT_CPLUS        extern "C++" {
#define FIN_EXT_CPLUS        }
#ifdef __cplusplus
#define DEBUT_CPLUSPLUS        extern "C" {
RIEN    DEBUT_CPLUSPLUS ;
#endif
#define UP_CASE        1
#define LO_CASE        0
#define NODE_MASK        ~(~0x3ff)
#define REF_MASK         ~(~0xfff)
#define LANG_MASK        ~(~0x03f)
#define NODE_BIT         10
#define LANG_BIT         6
#define REF_BIT          12
#define LIST               0
#define TERM_TREE          ( -2 & NODE_MASK )
#define GEO                ( -3 & NODE_MASK )
#define ENTETE_SIZE        2*sizeof(int)+2*sizeof(PPTREE)
#define MAX_TOKEN        2048 /* the number maximum of token */
extern int  tabValue ;    /* la valeur du tab */ 
extern int  rightMargin ; /* la valeur de la marge droite */ 
#define SON_POS(tree, n) ((long) tree+2 * sizeof(int)  \
                        + 2*sizeof(PPTREE) + (n - 1) * sizeof (PPTREE))
#define TAB_SPACE        tabValue
#define TAB_VALUE(col, n) ( (col) + (n) * TAB_SPACE - (col) % TAB_SPACE)
#define EQTYPE(x, y) ((x==y) || (x==POST && y == PREPOST))

typedef struct a_tree {
    int          tree1 ;
    int          nb_ref ;
    struct a_tree *father ;
    struct a_tree *the_annot ;
    struct a_tree *tree2 ;
    struct a_tree *tree3 ;
    struct a_tree *tree4 ;
    struct a_tree *tree5 ;
    struct a_tree *tree6 ;
    struct a_tree *tree7 ;
}   TREE,   *PPTREE,    *MY_TREE ;

typedef struct list_tree {
    PPTREE          tree ;
    struct list_tree *Next ;
}   LIST_TREE,  *PLIST_TREE ;

/**************************************************************
           Functions of auxpars
   ***************************************************************/
PLIST_TREE  _fastcall AllocListTree (PPTREE, PLIST_TREE) ;
void        MulFreeTree (int, ...) ;
void        _fastcall AddRef (PPTREE) ;    /* add a reference on a tree */ 
void        _fastcall RemRef (PPTREE) ;    /* del a reference on a tree */ 
void        _fastcall FreeRef (PPTREE) ;   /* del a reference on a tree and free it */ 
void        _fastcall FreeUnRef (PPTREE) ; /* free a tree not referenced */ 
PPTREE      _fastcall PSet (PPTREE, PPTREE) ;
PPTREE      _fastcall MakeTree (int, int) ;
PPTREE      _fastcall ReplaceTree (PPTREE, int, PPTREE) ;
PPTREE      _fastcall SReplaceTree (PPTREE, int, PPTREE) ;
PPTREE      _fastcall SonTree (PPTREE, int) ;
PPTREE      _fastcall FatherTree (PPTREE) ;
PPTREE      _fastcall NFatherTree (PPTREE, int) ;
PPTREE      _fastcall SFatherTree (PPTREE, int) ;
int         _fastcall NumberRef (PPTREE) ;
PPTREE      _fastcall ListElem (PPTREE) ;
PPTREE      _fastcall AddList (PPTREE, PPTREE) ;
PPTREE      _fastcall MakeString (char *) ;
PPTREE      _fastcall CommString (char *) ;
char        *_fastcall AllocString (const char *) ;
char        *_fastcall Value (PPTREE) ;
int         _fastcall ListLength (PPTREE) ;
PPTREE      ListFind (PPTREE, PPTREE) ;    /* first elem is list */ 
char        *_fastcall BrainyValue (PPTREE) ;
void        EqualTree (char *, char *, int, PPTREE, int) ;
PPTREE      _fastcall CopyTree (PPTREE) ;
char        *_fastcall NameOfNode (char *) ;
char        *_fastcall NameOfNodePlus (char *) ;
char        *_fastcall NameOfNodeStrip (char *) ;
char        *_fastcall NameLang (char *) ;
char        *_fastcall LanguageName () ;
void        _fastcall TabInt () ;
void        _fastcall TabVirtInt () ;
void        _fastcall Tab () ;
void        _fastcall NTab (int) ;
void        _fastcall Space (int) ;
void        _fastcall Mark () ;
void        _fastcall UnMarkInt () ;
void        _fastcall ClearMar () ;
void        _fastcall UnMarkVirtInt () ;
void        _fastcall UnMark () ;
void        _fastcall GotoMarkInt () ;
void        _fastcall GotoMarkVirtInt () ;
void        _fastcall GotoMark () ;
void        _fastcall GotoColInt (int) ;
void        _fastcall GotoColVirtInt (int) ;
void        _fastcall GotoCol (int) ;
int         _fastcall Beginning () ;
void        _fastcall NewLineInt () ;
void        _fastcall NewLineVirtInt () ;
void        _fastcall NewLine () ;
void        LNewLine (int) ;
int         _fastcall GetString (char *, int) ;
int         _fastcall GetStringS (char *, int) ;
char        *_fastcall GetLexString () ;
char        _fastcall NextChar () ;
void        _fastcall UnputBuf () ;
void        _fastcall UnputChar (int) ;
int         _fastcall ExtUnputBuf () ;
void        _fastcall DumpBrainyValueInt (PPTREE) ;
void        _fastcall DumpBrainyValueVirtInt (PPTREE) ;
void        _fastcall DumpBrainyValue (PPTREE) ;
int         _fastcall PosTree (PPTREE) ;
PPTREE      _fastcall AddListList (PPTREE, PPTREE) ;
void        _fastcall PrintError (char *, char *, int, int, int, int, int) ;
void        _fastcall FreeTree (PPTREE) ;
void        _fastcall FreeTreeRec (PPTREE) ;
void        _fastcall CommTerm () ;
void        _fastcall DumpError () ;
int         _fastcall GetErrorLine () ;
char        *_fastcall GetErrorToken () ;
void        _fastcall ResetError () ;
void        begin_comment () ;
void        store_comment_line (int) ;
int         AddConstVal (char *, int) ;
PPTREE      ReadInFile (int) ;
PPTREE      ReadInString (char *) ;
void        SwitchLang (char *) ;
void        Flush () ;
int         PrePost () ;
void        MetaInit () ;
void        MetaEnd () ;
char        *FindFile (char *name, char *env, int here) ;
PPTREE      ReadFile (char *) ;
void ClearStoreRef();
#define MAXLENGTH        512

typedef struct lex_struct {
    int     Value ;
    char    string [MAXLENGTH];
}   LEX_STRUCT ;

typedef struct commElem {
    int            type, collected ;
    struct commElem *next ;
    PPTREE         content ;
}   COMM_ELEM,  *PCOMM_ELEM ;

typedef struct file_position {
    char                charAhead ;
    long                position ;
    int                 oldPos, oldPosStock, lexElvalue ;
    char                *string, *stringStock, *lexElstring ;
    int                 line, col ;
    char                firstOnLine, tokenAhead, flagNewLine ;
    PPTREE              lastTree ;
    PCOMM_ELEM          comm ;
    int                 nbRef ;  /* number of references on this context */ 
    struct file_position *next ; /* next file_pos in list */ 
}   FILE_POSITION,  *PFILE_POSITION ;

extern PFILE_POSITION   lastContextPos ;
PFILE_POSITION          _fastcall SavePos () ;
int                     _fastcall RestorePos (PFILE_POSITION) ;
void                    _fastcall FreePos (PFILE_POSITION) ;
PCOMM_ELEM              _fastcall LookComm (int *) ;
void                    _fastcall AddComm (register PCOMM_ELEM, int, PPTREE, PPTREE) ;
PPTREE                  NextComm (PPTREE, int, PPTREE) ;
PPTREE                  NextCommContent (PPTREE, PPTREE) ;
void                    Frame (PPTREE) ;
#define SON_WRITE(dad, n, son) \
    LCacheWrite(((long)dad) + 2 * sizeof(int) + (n+1) * sizeof(PPTREE),(long)son)
#define SON_READ(dad, n) LCacheRead(((long)dad) + 2 * sizeof(int) + (n+1) * sizeof(PPTREE))
#define COMM_POS(node) ((long) node + 2* sizeof(int) + sizeof(PPTREE))
#define COMM_SON(node) (SonTree(tree,0))
#define COMM_FATHER_VALUE(node) (NumberTree(SonTree(node,0)) != GEO ? node :\
                     SonTree(node,0))
#define COMM_SON_VALUE(node) (SonTree(COMM_FATHER_VALUE(node),0))
#define COMM_POS_VALUE(node) (NumberTree(COMM_SON(node)) != GEO ? COMM_POS(node) :\
                     COMM_POS(COMM_SON(node)))
#define TERM_OR_META(x, y) (lexEl.Value == x || lexEl.Value ==META \
            || (PrintError(GetLexString(),y,oldLine,line,col,1,0),0))
#define BUILD_TERM_META(x) (lexEl.Value ==META ?\
    ( x =MakeTree(META,1),ReplaceTree(x,1,CommString(lexEl.string))) \
    : (x= CommString(lexEl.string)))
extern char *currentLanguage ;
extern int  ptStockBuf ;
#ifdef __cplusplus

class CPTREE {
    
private :

    PPTREE  *cStock ;
    
public :

    CPTREE ( PPTREE *pt )
    {
        cStock = pt ;
        if ( *pt ) 
            AddRef(*pt);
    }
    
    ~CPTREE ()
    {
        if ( *cStock ) 
            FreeRef(*cStock);
    }
};
/**************************************************************
           Functions of gesttok
   ***************************************************************/

typedef struct stringElem {
    struct stringElem *next ;
    int              Value ;
    char             *string ;
}   STRINGELEM ;

typedef struct keyElem {
    struct keyElem *next ;
    char          *Value ;
    char          *string ;
}   KEYELEM ;

typedef struct _node {
    char        *name ;
    int         number ;
    int         arity ;
    struct _node *next ;
}   NODE,   *PNODE ;

typedef struct {
    char    *name ;
    int     offset ;
}   OVER_LANG ;

typedef struct over__lang {
    char             *name ;
    int              offset ;
    struct over__lang *next ;
}   LOVER_LANG,     *PLOVER_LANG ;

typedef struct lang {
    char        *name ;
    
    /* EL suppression le 12/10/93
       int (* FuncArity) (); */
    int         languageMask ;
    int         *arityNode ;
    STRINGELEM  *listConst ;
    PPTREE      (*parse_entry)(int) ;
    int         nbNode ;
    struct lang  *Next ;
    OVER_LANG   *overLang ;
}   LANG,   *PLANG ;

PLANG           GetLang (char *) ;
PLANG           GetNodeLang (PPTREE) ;
void            SwitchLangPoint (PLANG) ;
void            SwitchLangMask (int) ;
void            PatchNode (PPTREE, PLANG, int) ;
extern PLANG    pCurrentLanguage ;
extern int      isVirtMod ;
extern int      currCol ;
extern int      currLine ;
extern int      firstError ;
extern int      _inhibited ;
char            *SymboName (char *, int) ;
PPTREE          AddToken (char *, char *, PPTREE) ;
char            *NameConst (int) ;
void            DumpToken (PPTREE, int, int, int) ;
void            DumpConst (STRINGELEM *) ;
int             AddConst (char *) ;
char            *AddKey (char *) ;

typedef struct descript_elem {
    int                 numb ;   /* number of elem */ 
    char                *name ;  /* name of token */ 
    int                 offset ; /* number of procedure which get it */ 
    PPTREE              proc ;   /* lex procedure which get it */ 
    struct descript_elem *next ;
}   DESCRIPT_ELEM,  *PDESCRIPT_ELEM ;

/**************************************************************
           Functions of decomp
   ***************************************************************/
void    _fastcall WriteStringInt (const char *) ;
void    _fastcall PrintString (const char *) ;
void    _fastcall WriteStringVirtInt (const char *) ;
void    _fastcall WriteString (const char *) ;
void    SepBefore () ;
void    SepAfter () ;
void    NoSep () ;
/**************************************************************
           Functions of verif
   ***************************************************************/
void    InsertDecElem (char *) ;
void    SetUse (char *) ;
void    UseParam (char *, int) ;
void    InitDecElem (char *, int) ;
int     IsDecDecElem (register char *) ;
void    FuncName (char *) ;
void    FuncFree () ;
PPTREE  PrintComm (PPTREE, int, PPTREE) ;
PPTREE  PrintCommVirt (PPTREE, int, PPTREE) ;
PPTREE  PrintCommEInt (PPTREE, int, PPTREE, char *, char *, char *) ;
PPTREE  PrintCommEVirtInt (PPTREE, int, PPTREE, char *, char *, char *) ;
PPTREE  GetComm (PPTREE) ;
PPTREE  PutComm (PPTREE, PPTREE) ;
char    *IsComm (PPTREE, int) ;
int     SizeComm (PPTREE) ;
#define PrintCommE(x, y, z, t, u, v) (\
    isVirtMod? PrintCommEVirtInt(x,y,z,t,u,v):PrintCommEInt(x,y,z,t,u,v))

typedef struct var_struct {
    char             *name ;
    PPTREE           father ;
    int              slot ;
    PPTREE           elem ;
    struct var_struct *next ;
}   VAR,    *PVAR ;

#ifdef SUN
#undef toupper
#undef tolower
#define toupper(x) ((x>='a' && x<= 'z')? x+'A'-'a':x)
#define tolower(x) ((x>='A' && x<= 'Z')? x+'a'-'A':x)
#endif
/**************************************************************
          manipulation sur les coordonnees
   ***************************************************************/
int         _fastcall GetMark () ;
void        PutCoord (PPTREE, int, int, int, int) ;
void        PutFlag (PPTREE, int) ;
int         GetCoord (PPTREE, int *, int *, int *, int *) ;
void        GetCoordAbs (PPTREE, PPTREE, int *, int *) ;
void        MarkCoordTree (PPTREE, int, int) ;
void        UnMarkCoordTree (PPTREE) ;
int         GetFlag (PPTREE, int *) ;
void        FreeCoord (PPTREE) ;
/**************************************************************
           definition necessaires pour le bon fonctionnement
           du parseur
   ***************************************************************/
/* EL le 26/1/94 rajout des methodes pour gerer les positions << */
int         store_pos_as_comment (int, int, int) ;
extern int  lexCallLex ; /* flags which tells that lex is calling lex */ 
extern int  dumpCoord ;  /* flag that says if we must put
                            coord commentaries */ 
#define POS_STUB        "\002"
#define POS_STUB_FORMAT        "\002 %d %d"
#ifdef DUMP_COORD
#define PUT_COORD_CALL        {\
    if (dumpCoord) {\
        store_pos_as_comment(oldLine,oldCol,1);\
    }}
#define PUT_COORD_AFTER_COMMENTS_CALL        {\
    if (lexCallLex && dumpCoord) \
        store_pos_as_comment (oldLineEntry, oldColEntry,0);\
    lexCallLex = 0 ;}
#else 
#define PUT_COORD_CALL        {}
#define PUT_COORD_AFTER_COMMENTS_CALL        {}
#endif
#define PUT_COORD          \
    /* put coords comment */\
    WriteString("PUT_COORD_CALL;");\
    NewLine();
#define PUT_COORD_AFTER_COMMENTS           \
    /* put coords comment */\
    WriteString("PUT_COORD_AFTER_COMMENTS_CALL;");\
    NewLine();
#define SEE_TOKEN(x, y) (lexEl.Value == x || \
        (PrintError(GetLexString(),y,oldLine,line,col,1,0),0))
#define TOKEN_EXIT(y, x) {\
        PrintError(GetLexString(),x,oldLine,line,col,1,error_free);\
        goto y ;\
    } else { \
        tokenAhead = 0 ;\
    }
#define CASE_EXIT(y, x) {\
        PrintError(GetLexString(),x,oldLine,line,col,1,error_free);\
        goto y ;\
    }
#define PROG_EXIT(y, x) {\
        PrintError(GetLexString(),x,oldLine,line,col,2,error_free);\
        goto y ;\
    }
#define LEX_EXIT_GOTO(y, x) {\
        PrintError(GetLexString(),x,oldLine,line,col,0,error_free);\
        goto y;\
}
#define LEX_EXIT(y, x) {\
        PrintError(GetLexString(),x,oldLine,line,col,0,0);\
}
#define GET_ARRAY_VALUE(_tab, nb) (_tab[(nb)>>3] & (1 << ((nb) & 0x7)))
#define SET_ARRAY_VALUE(_tab, nb) (_tab[(nb)>>3] \
                    |= (1 << ((nb) & 0x7)))
#define NOTHING       
#define PUSH_CALL(x) \
    (_filePosition = SavePos(),_value = ( x(0) != (PPTREE) -1)\
        ,RestorePos(_filePosition),FreePos(_filePosition),_value)
#define PUSH_CALL_QUICK(x) ( x(0) != (PPTREE) -1) )
#define PUSH_CALL_AFF(y, x) \
    (_filePosition = SavePos(),_value = ((y x(0)) != (PPTREE) -1)\
        ,_value || RestorePos(_filePosition),FreePos(_filePosition),_value)
#define PUSH_CALL_AFF_QUICK(y, x) ((y x(0)) != (PPTREE) -1)
#define PUSH_CALL_VERIF(x, lexOffset, lexFct, arrayEntry) \
    ((tokenAhead == lexOffset || (lexFct(),TRACE_LEX(1))),\
        (GET_ARRAY_VALUE(ptTokenArray [arrayEntry],lexEl.Value) \
              ? PUSH_CALL(x) : 0))
#define PUSH_CALL_AFF_VERIF(y, x, lexOffset, lexFct, arrayEntry) \
    ((tokenAhead == lexOffset || (lexFct(),TRACE_LEX(1))),\
        (GET_ARRAY_VALUE(ptTokenArray [arrayEntry],lexEl.Value) \
              ? /* PUSH_CALL_AFF(y,x)*/\
    (_filePosition = SavePos(),_value = ((y x(0)) != (PPTREE) -1)\
        ,_value || RestorePos(_filePosition),\
                           FreePos(_filePosition),_value) : 0))
#define QUICK_CALL(x, lexOffset, lexFct, arrayEntry) \
    ((tokenAhead == lexOffset || (lexFct(),TRACE_LEX(1))),\
        (GET_ARRAY_VALUE(ptTokenArray [arrayEntry],lexEl.Value) \
              ? x : (PPTREE) -1))
#define LEX_FUNCTION(arrayEntry, gramm) \
               (((gramm *)(rootGrammar()))->*(ptTokenFuncArray[arrayEntry]))
#define LEX_FUNCTION_OFFSET(arrayEntry) (ptTokenNbFuncArray[arrayEntry])
#define NPUSH_CALL_VERIF(x, arrayEntry, gramm) \
    ( LEX_FUNCTION_OFFSET(arrayEntry) ?\
    ((tokenAhead == LEX_FUNCTION_OFFSET(arrayEntry) \
                    || (LEX_FUNCTION(arrayEntry,gramm)(),TRACE_LEX(1))),\
        (GET_ARRAY_VALUE(ptTokenArray [arrayEntry],lexEl.Value) \
              ? PUSH_CALL(x) : 0))\
        : PUSH_CALL(x))
#define NPUSH_CALL_AFF_VERIF(y, x, arrayEntry, gramm) \
        ( LEX_FUNCTION_OFFSET(arrayEntry) ?\
        ((tokenAhead == LEX_FUNCTION_OFFSET(arrayEntry)\
                                || (LEX_FUNCTION(arrayEntry,gramm)(),TRACE_LEX(1))),\
        (GET_ARRAY_VALUE(ptTokenArray [arrayEntry],lexEl.Value) \
              ? /* PUSH_CALL_AFF(y,x)*/\
            (_filePosition = SavePos(),_value = ((y x(0)) != (PPTREE) -1)\
            ,_value || RestorePos(_filePosition),\
                           FreePos(_filePosition),_value) : 0))\
            /* PUSH_CALL_AFF(y,x)*/\
        :(_filePosition = SavePos(),_value = ((y x(0)) != (PPTREE) -1)\
            ,_value || RestorePos(_filePosition),\
                           FreePos(_filePosition),_value))
#define NQUICK_CALL(x, arrayEntry, gramm) \
    (LEX_FUNCTION_OFFSET(arrayEntry) ?\
    ((tokenAhead == LEX_FUNCTION_OFFSET(arrayEntry) \
                    || (LEX_FUNCTION(arrayEntry,gramm)(),TRACE_LEX(1))),\
        (GET_ARRAY_VALUE(ptTokenArray [arrayEntry],lexEl.Value) \
              ? x : (PPTREE) -1))\
     : x)
#define TRACE_ENTER           1
#define TRACE_RETURN          2
#define TRACE_EXIT            3
#define TRACE_MAX_DEPTH         40
#ifdef DEBUG
int _fastcall TraceRule (char *, int, PPTREE) ;
int TraceLex () ;
#define TRACE_LEX(x) TraceLex()
#define TRACE_RULE(name, state, tree) TraceRule(name,state,tree)
#else 
#define TRACE_LEX(x) 1
#define TRACE_RULE(name, state, tree) 1
#endif

/* JPJ >> */
#define PRE            1
#define POST           2
#define PREPOST            3
#define META           4
#define PRIORITY        5
#define IN_LANGUAGE            5  /* used as maximum of common node */
extern int      *tabArity ;
extern int      (*FuncArity)() ;
extern PPTREE   the_parse_entry (int) ;
#define Arity(x) (*FuncArity)(x)
#define _arityNode         tabArity
extern STRINGELEM   *listConst ;

/* definitions used by metachop generator */
#define PSET(x, y) (x = PSet(x,y))
#define NEXT_L(x) (AddRef(_nextVal= x ? SonTree( x ,1):(PPTREE)0),PSET(x , x?SonTree(x,2):(PPTREE)0),RemRef(_nextVal),_nextVal)
#define meta_father(x) (SearchVar(x))->father
#define meta_pos(x) (SearchVar(x))->slot
#define meta_elem(x) (SearchVar(x))->elem
#define foreach(x, y, z) ForeachTree(x,y,z,(PPTREE)0,-1)
#define metarep        MetaRep
#define PushTree(x) (stackTree[ptStackTree++] = x )
#define PopTree        (stackTree[--ptStackTree])
#define treearity(x) ((PPTREE)x?(CacheRead((long)(PPTREE)x+sizeof(int))>>REF_BIT)&0xf:0)
#if 0
#define forallsons(x, y) {int for_slot=1,_arity=treearity(x);PPTREE for_elem = (PPTREE) 0 ; for(;for_slot<=_arity;for_slot++) { PSET(for_elem , SonTree(x,for_slot));if (for_elem && NumberTree(for_elem) != IN_LANGUAGE) y;}FreeRef(for_elem);}
#endif
#define replacetree(x, y, z) ReplaceTree((PPTREE)x,y,(PPTREE)z)
#define sontree(x, y) SonTree((PPTREE)x,y)
#define fathertree(x) FatherTree((PPTREE)x)
#define nfathertree(x, nb) NFatherTree((PPTREE)x,nb)
#define copytree(x) CopyTree((PPTREE)x)
#define ranktree(x) PosTree((PPTREE)x)
#define numbertree(x) NumberTree((PPTREE)x)
#define gotocol(x) GotoCol(x)
#define comparetree(x, y) CompareTree(x,y,0,-1)
#define qcomparetree(x, y) QCompareTree((PPTREE)x,(PPTREE)y,(PPTREE)0,-1)
#define listlength(x) ListLength((PPTREE)x);
#define freevar        FreeVar
#define dumperror        DumpError
void    InitComp () ;
void    InitOutput () ;
#if I386 || LINUX
#ifdef __cplusplus
void    TheConstructor (int va_alist, ...) ;
#else 
void    TheConstructor (int, ...) ;
#endif
#else 
void    TheConstructor (int, ...) ;
#endif
void                AddLang (char *, int *, STRINGELEM *
    , PPTREE(*func)(int), int, OVER_LANG *) ;
extern int          oldLine ;
extern int          oldCol ;
extern int          oldLineEntry ;
extern int          oldColEntry ;
extern char         errStr [512];
extern char         *_ptString ;
extern int          _nbCharact ;
extern char         *stringlex ;
extern LEX_STRUCT   lexEl ;
extern int          line ;
extern char         c ;
extern int          tokenAhead ;
extern int          ptStockBuf ;
extern int          input ;
extern int          col ;
extern int          firstOnLine ;
extern PPTREE       _lastTree ;
extern int          _funcLevel ;
extern PCOMM_ELEM   listComm ;
extern int          input, output ;

/* virtual fonctions cannot be put in overlays */
#ifndef SUN
#define virtual       
#endif
#ifdef SUN
char    *itoa (int, char *, int) ;
#endif
#ifdef __cplusplus
#define FIN_CPLUSPLUS        }
RIEN    FIN_CPLUSPLUS ;
#endif
#ifdef __cplusplus
#define NUMBER_TREE        1
extern "C" {
#include "memges.h"
}
/**************************************************************
           GetLexString : get last string lex recognized
   ***************************************************************/
extern char stockBuf[];
extern int ptStockBuf;
inline char * GetLexString ()
{
    stockBuf [++ptStockBuf] = c ;
    stockBuf [++ptStockBuf] = '\0';
    ptStockBuf -= 2 ;
    if ( tokenAhead ) 
        return (stockBuf);
    else 
        return ("\0");
}


inline int _fastcall NumberTree ( PPTREE tree )
{
    return tree ? CacheRead((long)tree) & NODE_MASK : - 100 ;
}
#else 
int _fastcall NumberTree (PPTREE) ;
#endif
#endif
class PTREE ;
PPTREE  StoreRef (PPTREE) ;
#include "ptree.h"

inline PPTREE StoreRef ( PTREE pTree )
{
    return StoreRef((PPTREE)pTree);
}

/**************************************************************
           definitions of outil.dec
   ***************************************************************/
void    _fastcall PullComment (PPTREE) ;             /* pull comment for terminals */ 
void    _fastcall SqueezeMeta (PPTREE) ;             /* change <TERM,<META>> with <META> */ 
PTREE   MetaRep (char *, PTREE, PTREE) ;             /* replace meta in second parameter with third */ 
int     CompareTree (PTREE, PTREE, PTREE, int) ;     /* looks if two trees are equal */ 
int     QCompareTree (PPTREE, PPTREE, PPTREE, int) ; /* idem but quick */ 
void    FreeVar () ;                                 /* free meta pointer */ 
PVAR    SearchVar (register char *) ;                /* give the structure associated to a meta pointer */ 
PTREE   find (PTREE, PTREE) ;                        /* give the pointer on a PTREE matching a pattern in
                                                        in a tree */ 
PTREE   metafind (PTREE, PTREE) ;
void    replace (PTREE, PTREE, PTREE) ;              /* replace occurence of first parameter
                                                        in second parameter with third */ 
void    DumpTree (PPTREE) ;
void    DumpNode (PPTREE) ;
void    InLang (char *, PTREE) ;
char *MakeTreeGenDir ( PTREE paramTree, char *name, int level =0);


/* EL le 26/1/94 rajout des methodes pour gerer les positions << */
char    *IsPosComment (PTREE) ;
int     GetPosCommentContent (PTREE, int *, int *) ;
void    SetPosCommentContent (PTREE, int, int) ;
PTREE   DestroyComment (PTREE) ;

/* void DestroyPosComment (PTREE);*/
void    TrimPosComment (PTREE) ;
int     GetStartPos (PTREE, int *, int *) ;
int     GetEndPos (PTREE, int *, int *) ;
/*>>*/
#include "itptree.h"

inline PPTREE NextTree ( PPTREE elem, PPTREE stop )
{
    return ItPtree::NextTree(elem, stop, 1);
}

inline PPTREE SNextTree ( PPTREE elem, PPTREE stop )
{
    return ItPtree::SNextTree(elem, stop, 1);
}

inline PPTREE FSNextTree ( PPTREE elem, PPTREE stop )
{
    return ItPtree::FSNextTree(elem, stop);
}

inline PPTREE FindNext ( PPTREE elem, PPTREE start, PPTREE stop )
{
    return ItPtree::FindNext(elem, start, stop);
}

extern "C" {

void    InsertDescript (int, char *, int, PPTREE) ;
void    FreeDescriptList () ;
void    SearchToken (PTREE, int) ;
 PTREE           GetTokensFunctionName (PTREE) ;
 PTREE           GetTokensFunction (PTREE) ;
 PTREE           FuncAccelerator (PTREE) ;
 PDESCRIPT_ELEM  FindStringDescript (char *, PPTREE) ;
 void            FreeDescriptList () ;
 void            FreeArrayEntry () ;
int             LexNumber (PTREE) ;
}

void MakeTreeGenDirRec ( PTREE paramTree,int nbTreeParam = 0 );
extern PPTREE stackTree[1024];
extern int ptStackTree;


#endif
