"Fossies" - the Fresh Open Source Software Archive

Member "gretl-2020b/lib/src/genparse.h" (7 Apr 2020, 20242 Bytes) of package /linux/misc/gretl-2020b.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "genparse.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2020a_vs_2020b.

    1 /*
    2  *  gretl -- Gnu Regression, Econometrics and Time-series Library
    3  *  Copyright (C) 2001 Allin Cottrell and Riccardo "Jack" Lucchetti
    4  *
    5  *  This program is free software: you can redistribute it and/or modify
    6  *  it under the terms of the GNU General Public License as published by
    7  *  the Free Software Foundation, either version 3 of the License, or
    8  *  (at your option) any later version.
    9  *
   10  *  This program is distributed in the hope that it will be useful,
   11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  *  GNU General Public License for more details.
   14  *
   15  *  You should have received a copy of the GNU General Public License
   16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17  *
   18  */
   19 
   20 /* shared private header for all 'genr' related modules */
   21 
   22 #include "libgretl.h"
   23 #include "uservar.h"
   24 #include "gretl_func.h"
   25 #include "gretl_bundle.h"
   26 #include "gretl_array.h"
   27 
   28 #define GENDEBUG 0
   29 
   30 /* operators, types, punctuation */
   31 
   32 enum {
   33               U_NEG = 1,
   34               U_POS,
   35               U_NOT,
   36               U_ADDR,
   37               U_MAX,      /* SEPARATOR: end of unary operators */
   38               B_ASN,
   39               B_ADD,
   40               B_SUB,
   41               B_MUL,
   42   /* 10 */    B_DIV,
   43               B_MOD,
   44               B_POW,
   45               B_EQ,
   46               B_LT,
   47               B_GT,
   48               B_LTE,
   49               B_GTE,
   50               B_NEQ,
   51               B_AND,
   52   /* 20 */    B_OR,
   53               B_TRMUL,
   54           B_RANGE,
   55               B_DOTMULT,
   56           B_DOTDIV,
   57           B_DOTPOW,
   58               B_DOTADD,
   59               B_DOTSUB,
   60               B_DOTEQ,
   61               B_DOTLT,
   62   /* 30 */    B_DOTGT,
   63           B_DOTLTE,
   64           B_DOTGTE,
   65           B_DOTNEQ,
   66               B_DOTASN,
   67               B_KRON,     /* Kronecker product */
   68               B_HCAT,     /* horizontal concatenation */
   69               B_VCAT,     /* vertical concatenation */
   70           B_LCAT,     /* list concatentation */
   71           B_LDIV,     /* matrix left division */
   72   /* 40 */    B_ELLIP,    /* list-generating ellipsis */
   73           B_JOIN,     /* list-joining with separator */
   74           OP_MAX,     /* SEPARATOR: end of binary operators */
   75               G_LPR,      /* grouping: left paren */
   76           G_RPR,      /* right paren */
   77               G_LBR,      /* left bracket */
   78               G_RBR,      /* right bracket */
   79               G_LCB,      /* left curly bracket */
   80           G_RCB,      /* right curly bracket */
   81           P_COM,      /* punctuation: comma */
   82   /* 50 */    P_DOT,      /* period */
   83           P_SEMI,     /* semi-colon */
   84           P_COL,      /* colon */
   85               PUNCT_MAX,  /* SEPARATOR: end of grouping and punctuation marks */
   86           NUM,        /* scalar */
   87           SERIES,     /* series */
   88           LIST,       /* list of series */
   89           MAT,    /* matrix */
   90           BUNDLE,     /* gretl bundle (hash table) */
   91           ARRAY,      /* generic array object */
   92   /* 60 */    STR,    /* string */
   93           CNUM,   /* constant (literal) numeric value */
   94           CSTR,       /* constant (literal) string */
   95           CON,    /* named numeric constant */
   96           DUM,    /* dummy variable */
   97           UOBJ,   /* user-defined object (e.g. model) */
   98           NUM_P,      /* user scalar++ */
   99           NUM_M,      /* user scalar-- */
  100           OBS,    /* observation from a series */
  101               MSL,    /* matrix plus subspec */
  102   /* 70 */    DMSTR,      /* "dollar" matrix plus string subspec */
  103           MSLRAW,     /* unevaluated matrix subspec */
  104           MSPEC,      /* evaluated matrix subspec */
  105           SUBSL,      /* row or column component of MSPEC */
  106           MDEF,   /* explicit matrix definition {...} */
  107               LAG,        /* variable plus lag length */
  108           DVAR,   /* $ "dataset" variable (mostly scalar or series) */
  109           MVAR,   /* $ model var (scalar, series, or matrix) */
  110           LISTVAR,    /* variable in list, dot syntax */
  111           DBUNDLE,    /* $ bundle accessor */
  112   /* 80 */    BMEMB,      /* member of bundle */
  113           DBMEMB,     /* member of $ bundle */
  114           MMEMB,      /* member of named model */
  115           FARGS,      /* set of n function arguments */
  116               WLIST,      /* wildcard list spec */
  117               EMPTY,      /* "null" or empty arg slot */
  118           UNDEF,      /* undefined (allowed in "query" context only) */
  119           DTYPE_MAX,  /* SEPARATOR: end of "bare" types */
  120           UFUN,   /* user-defined function */
  121           RFUN,       /* GNU R function */
  122   /* 90 */    IVEC,       /* array of ints, not a varlist */
  123           OSL,        /* "slice" of object other than matrix */
  124           USERIES,    /* named series (defined only for error reporting) */
  125           SUB_ADDR,   /* "address" of (e.g.) array element */
  126               INC,        /* increment */
  127               DEC,        /* decrement */
  128           QUERY,      /* ternary "?" expression */
  129           PTR,        /* miscellaneous pointer */
  130           EOT,    /* end of transmission */
  131           UNK
  132 };
  133 
  134 /* functions: don't collide with the enumeration above */
  135 
  136 enum {
  137     F1_MIN = 1 << 8,
  138     F_ABS,
  139     F_CEIL,
  140     F_FLOOR,
  141     F_SIN,
  142     F_COS,
  143     F_TAN,
  144     F_ASIN,
  145     F_ACOS,
  146     F_ATAN,
  147     F_SINH,
  148     F_COSH,
  149     F_TANH,
  150     F_ASINH,
  151     F_ACOSH,
  152     F_ATANH,
  153     F_LOG,
  154     F_LOG10,
  155     F_LOG2,
  156     F_EXP,
  157     F_SQRT,
  158     F_GAMMA,
  159     F_LNGAMMA,
  160     F_DIGAMMA,
  161     F_INVMILLS,
  162     F_ROUND,
  163     F_CNORM,
  164     F_DNORM,
  165     F_QNORM,
  166     F_CARG,
  167     F_CMOD,
  168     F_REAL,
  169     F_IMAG,
  170     F_LOGISTIC,
  171     FP_MAX,      /* separator: end of pointerized functions */
  172     F_CONJ,
  173     F_TOINT,
  174     F_DIFF,   /* first difference */
  175     F_LDIFF,      /* log difference */
  176     F_SDIFF,      /* seasonal difference */
  177     F_SORT,   /* ascending sort */
  178     F_DSORT,      /* descending sort */
  179     F_RANKING,
  180     F_ODEV,   /* orthogonal deviation */
  181     F_NOBS,
  182     F_CUM,
  183     F_MISSING,
  184     F_DATAOK,
  185     F_MISSZERO,
  186     F_ZEROMISS,
  187     F_MEDIAN,
  188     F_GINI,
  189     F_SUM,
  190     F_SUMALL,
  191     F_MEAN,
  192     F_MIN,
  193     F_MAX,
  194     F_SD,
  195     F_VCE,    /* variance */
  196     F_SKEWNESS,
  197     F_KURTOSIS,
  198     F_SST,
  199     F_SUMR,
  200     F_SUMC,
  201     F_PRODR,
  202     F_PRODC,
  203     F_MEANR,
  204     F_MEANC,
  205     F_CHOL,
  206     F_INV,
  207     F_INVPD,
  208     F_GINV,
  209     F_DIAG,
  210     F_TRANSP,
  211     F_VEC,
  212     F_VECH,
  213     F_UNVECH,
  214     F_ROWS,
  215     F_COLS,
  216     F_DET,
  217     F_LDET,
  218     F_TRACE,
  219     F_NORM1,
  220     F_INFNORM,
  221     F_RCOND,
  222     F_RANK,
  223     F_OBSNUM,
  224     F_ISDISCR,
  225     F_ISDUMMY,
  226     F_TYPEOF,
  227     F_EXISTS,
  228     F_NELEM,
  229     F_PDF,
  230     F_PVAL,
  231     F_CDF,
  232     F_INVCDF,
  233     F_CRIT,
  234     F_URCPVAL,
  235     F_RANDGEN,
  236     F_MRANDGEN,
  237     F_RANDGEN1,
  238     F_VALUES,
  239     F_UNIQ,
  240     F_NULLSPC,
  241     F_MEXP,
  242     F_MINC,
  243     F_MAXC,
  244     F_MINR,
  245     F_MAXR,
  246     F_IMINC,
  247     F_IMAXC,
  248     F_IMINR,
  249     F_IMAXR,
  250     F_FFT,
  251     F_FFT2,
  252     F_FFTI,
  253     F_UPPER,
  254     F_LOWER,
  255     F_POLROOTS,
  256     F_OBSLABEL,
  257     F_BACKTICK,
  258     F_STRLEN,
  259     F_VARNAME,
  260     F_VARNAMES,
  261     F_VARNUM,
  262     F_TOLOWER,
  263     F_TOUPPER,
  264     F_IRR,
  265     F_ERRMSG,
  266     F_GETENV,
  267     F_NGETENV,
  268     F_PSHRINK,
  269     F_PEXPAND,
  270     F_FREQ,
  271     F_ISNAN,
  272     F_TYPESTR,
  273     F_STRSTRIP,
  274     F_REMOVE,
  275     F_ATOF,
  276     F_MPI_RECV,
  277     F_EASTER,
  278     F_CURL,
  279     F_NLINES,
  280     F_ARRAY,
  281     F_TRAMOLIN,
  282     F_CNUMBER,
  283     F_ECDF,
  284     F_SLEEP,
  285     F_GETINFO,
  286     F_CDUMIFY,
  287     F_GETKEYS,
  288     F_MCORR,
  289     F_ISCMPLX,
  290     F_CTRANS,
  291     F_MLOG,
  292     F_BARRIER,
  293     HF_JBTERMS,
  294     F1_MAX,   /* SEPARATOR: end of single-arg functions */
  295     HF_LISTINFO,
  296     F_ARGNAME,
  297     F_T1,
  298     F_T2,
  299     F_COV,
  300     F_SDC,
  301     F_CDEMEAN,
  302     F_MCOV,
  303     F_DUMIFY,
  304     F_SORTBY,
  305     F_RUNIFORM,
  306     F_RNORMAL,
  307     F_FRACDIFF,
  308     F_BOXCOX,
  309     F_ZEROS,
  310     F_ONES,
  311     F_MUNIF,
  312     F_MNORM,
  313     F_QFORM,
  314     F_QR,
  315     F_EIGSYM,
  316     F_QUANTILE,
  317     F_CMULT,      /* complex multiplication */
  318     F_HDPROD,     /* horizontal direct product */
  319     F_CDIV,   /* complex division */
  320     F_MXTAB,
  321     F_MRSEL,
  322     F_MCSEL,
  323     F_WMEAN,
  324     F_WVAR,
  325     F_WSD,
  326     F_STRSTR,
  327     F_INSTRING,
  328     F_CNAMESET,
  329     F_RNAMESET,
  330     F_LJUNGBOX,
  331     F_MSORTBY,
  332     F_MSPLITBY,
  333     F_LINCOMB,
  334     F_IMHOF,
  335     F_XMIN,
  336     F_XMAX,
  337     F_FCSTATS,
  338     F_FRACLAG,
  339     F_MREV,
  340     F_DESEAS,
  341     F_PERGM,
  342     F_NPV,
  343     F_DSUM,
  344     F_POLYFIT,
  345     F_INLIST,
  346     F_ISCONST,
  347     F_INBUNDLE,
  348     F_CNAMEGET,
  349     F_RNAMEGET,
  350     F_PNOBS,
  351     F_PMIN,
  352     F_PMAX,
  353     F_PSUM,
  354     F_PMEAN,
  355     F_PXSUM,
  356     F_PXNOBS,
  357     F_PSD,
  358     F_RANDINT,
  359     F_MREAD,
  360     F_BREAD,
  361     F_GETLINE,
  362     F_ISODATE,
  363     F_JULDATE,
  364     F_READFILE,
  365     F_PRINTF,
  366     F_SPRINTF,
  367     F_MPI_SEND,
  368     F_BCAST,
  369     F_ALLREDUCE,
  370     F_GENSERIES,
  371     F_KPSSCRIT,
  372     F_STRINGIFY,
  373     F_SQUARE,
  374     F_SEASONALS,
  375     F_DROPCOLL,
  376     F_KSIMDATA,
  377     F_HFDIFF,
  378     F_HFLDIFF,
  379     F_NAALEN,
  380     F_KMEIER,
  381     F_NORMTEST,
  382     F_COR,
  383     F_LRCOVAR,
  384     F_JSONGETB,
  385     F_JSONGETA,
  386     F_FIXNAME,
  387     F_ATAN2,
  388     F_CCODE,
  389     F_LSOLVE,
  390     F_STRFTIME,
  391     F_STRPTIME,
  392     F_CONV2D,
  393     F_FLATTEN,
  394     F_IMAT,
  395     F_COMPLEX,
  396     F_RANDPERM,
  397     F_STDIZE,
  398     F_CSWITCH,
  399     F_PSDROOT,
  400     F_INSTRINGS,
  401     F_STRVALS,
  402     F_FUNCERR, /* legacy */
  403     F_ERRORIF,
  404     F2_MAX,   /* SEPARATOR: end of two-arg functions */
  405     F_LLAG,
  406     F_HFLAG,
  407     F_PRINCOMP,
  408     F_BFGSMAX,
  409     F_MSHAPE,
  410     F_SVD,
  411     F_TRIMR,
  412     F_TOEPSOLV,
  413     F_CORRGM,
  414     F_SEQ,
  415     F_REPLACE,
  416     F_STRNCMP,
  417     F_BESSEL,
  418     F_WEEKDAY,
  419     F_MONTHLEN,
  420     F_EPOCHDAY,
  421     F_KDENSITY,
  422     F_SETNOTE,
  423     F_BWFILT,
  424     F_CHOWLIN,
  425     F_VARSIMUL,
  426     F_STRSUB,
  427     F_REGSUB,
  428     F_MLAG,
  429     F_EIGSOLVE,
  430     F_SIMANN,
  431     F_HALTON,
  432     F_MWRITE,
  433     F_BWRITE,
  434     F_AGGRBY,
  435     F_IWISHART,
  436     F_SSCANF,
  437     F_SUBSTR,
  438     F_REDUCE,
  439     F_SCATTER,
  440     F_MWEIGHTS,
  441     F_MGRADIENT,
  442     F_MLINCOMB,
  443     F_HFLIST,
  444     F_NMMAX,
  445     F_GSSMAX,
  446     F_NPCORR,
  447     F_DAYSPAN,
  448     F_SMPLSPAN,
  449     F_FDJAC,
  450     F_NUMHESS,
  451     F_STRSPLIT,
  452     F_HPFILT,
  453     F_XMLGET,
  454     F_JSONGET,
  455     F_FEVD,
  456     F_LRVAR,
  457     F_BRENAME,
  458     F_ISOWEEK,
  459     F_BKW,
  460     F_FZERO,
  461     F_EIGGEN,
  462     F_EIGEN,
  463     F_SCHUR,
  464     F_RESAMPLE,
  465     F_STACK,
  466     HF_REGLS,
  467     F3_MAX,       /* SEPARATOR: end of three-arg functions */
  468     F_BKFILT,
  469     F_MOLS,
  470     F_MPOLS,
  471     F_MRLS,
  472     F_FILTER,
  473     F_MCOVG,
  474     F_KFILTER,
  475     F_KSMOOTH,
  476     F_KDSMOOTH,
  477     F_KSIMUL,
  478     F_NRMAX,
  479     F_LOESS,
  480     F_GHK,
  481     F_QUADTAB,
  482     F_ISOCONV,
  483     F_QLRPVAL,
  484     F_BOOTCI,
  485     F_BOOTPVAL,
  486     F_MOVAVG,
  487     F_DEFARRAY,
  488     F_DEFBUNDLE,
  489     F_DEFLIST,
  490     F_KSETUP,
  491     F_BFGSCMAX,
  492     F_SVM,
  493     F_IRF,
  494     F_NADARWAT,
  495     F_FEVAL,
  496     F_HYP2F1,
  497     HF_CLOGFI,
  498     FN_MAX,   /* SEPARATOR: end of n-arg functions */
  499 };
  500 
  501 enum {
  502     CONST_PI = 1,
  503     CONST_NA,
  504     CONST_INF,
  505     CONST_NAN,
  506     CONST_WIN32,
  507     CONST_EPS,
  508     CONST_HAVE_MPI,
  509     CONST_MPI_RANK,
  510     CONST_MPI_SIZE,
  511     CONST_N_PROC,
  512     CONST_TRUE,
  513     CONST_FALSE,
  514     CONST_SYSINFO
  515 };
  516 
  517 enum {
  518     DUM_NULL = 1,
  519     DUM_DIAG,
  520     DUM_UPPER,
  521     DUM_LOWER,
  522     DUM_REAL,
  523     DUM_IMAG,
  524     DUM_DATASET,
  525     DUM_TREND
  526 };
  527 
  528 #define GENSTRLEN 128
  529 #define NO_VNUM -1
  530 
  531 #define unary_op(s)  (s >= 1 && s < U_MAX)
  532 #define binary_op(s) (s > U_MAX && s < OP_MAX)
  533 #define bool_comp(s) (s >= B_EQ && s <= B_OR)
  534 #define dot_op(s)    (s >= B_DOTMULT && s <= B_DOTNEQ)
  535 
  536 #define func1_symb(s) (s > F1_MIN && s < F1_MAX)
  537 #define func2_symb(s) (s > F1_MAX && s < F2_MAX)
  538 #define func3_symb(s) (s > F2_MAX && s < F3_MAX)
  539 #define funcn_symb(s) (s > F3_MAX && s < FN_MAX)
  540 
  541 #define bnsym(s) (s == MDEF || s == FARGS)
  542 
  543 #define alias_reversed(n) (n->flags & ALS_NODE)
  544 
  545 /* function with single string argument */
  546 #define string_arg_func(s) (s == F_ISDISCR || s == F_OBSNUM || \
  547                 s == F_BACKTICK || s == F_VARNUM || \
  548                 s == F_EXISTS || s == F_REMOVE || \
  549                 s == F_ISCMPLX)
  550 
  551 /* function with multiple args, string for first arg */
  552 #define str0_func(s) (s == F_PVAL || s == F_CDF || s == F_INVCDF || \
  553               s == F_CRIT || s == F_RANDGEN || s == F_PDF || \
  554               s == F_BESSEL || s == F_MRANDGEN || s == F_RANDGEN1)
  555 
  556 /* functions taking a string arg in last position */
  557 #define string_last_func(s) (s == F_DESEAS || s == F_AGGRBY || \
  558                  s == F_PRINTF || s == F_SPRINTF || \
  559                  s == F_ALLREDUCE || s == F_NORMTEST || \
  560                  s == F_SSCANF || s == F_NPCORR || \
  561                  s == F_INBUNDLE || s == F_GENSERIES)
  562 
  563 /* functions taking string arg in middle position */
  564 #define string_mid_func(s) (s == F_REDUCE || s == F_SCATTER)
  565 
  566 /* functions taking one or more "fncall" (string) arguments */
  567 #define fncall_func(s) (s == F_BFGSMAX || s == F_NRMAX || \
  568             s == F_FDJAC || s == F_SIMANN || \
  569             s == F_BFGSCMAX || s == F_NMMAX || \
  570             s == F_GSSMAX || s == F_NUMHESS || \
  571             s == F_FZERO)
  572 
  573 /* functions with "reversing" aliases */
  574 #define als_func(s) (s == F_BFGSMAX || s == F_NRMAX || \
  575              s == F_SIMANN || s == F_BFGSCMAX || \
  576              s == F_NMMAX || s == F_GSSMAX || \
  577              s == F_EXISTS)
  578 
  579 /* functions where the right-hand argument is actually a return
  580    location */
  581 #define r_return(s) (s == F_QR || s == F_EIGSYM || s == F_EIGEN || \
  582                      s == F_MOLS || s == F_MPOLS || s == F_SVD || \
  583              s == F_EIGGEN)
  584 
  585 /* functions where the middle argument is actually a return
  586    location */
  587 #define m_return(s) (s == F_SVD || s == F_EIGEN)
  588 
  589 #define reusable(p) (p->flags & (P_COMPILE | P_EXEC))
  590 
  591 typedef struct node NODE;
  592 
  593 struct branchn {
  594     int n_nodes;
  595     NODE **n;
  596 };
  597 
  598 union val {
  599     struct branchn bn;
  600     int idnum;
  601     char *str;
  602     double xval;
  603     double *xvec;
  604     int *ivec;
  605     gretl_matrix *m;
  606     matrix_subspec *mspec;
  607     gretl_bundle *b;
  608     gretl_array *a;
  609     void *ptr;
  610 };
  611 
  612 enum node_flags {
  613     AUX_NODE = 1 << 0, /* auxiliary: free on exit */
  614     TMP_NODE = 1 << 1, /* temporary: free content on exit */
  615     SVL_NODE = 1 << 2, /* holds string-valued series */
  616     PRX_NODE = 1 << 3, /* aux node is proxy (don't reuse!) */
  617     LHT_NODE = 1 << 4, /* node holds terminal of LHS */
  618     MSL_NODE = 1 << 5, /* (scalar) node is matrix element */
  619     MUT_NODE = 1 << 6, /* node is inherently mutable in type */
  620     ALS_NODE = 1 << 7  /* function subject to "reversing" alias */
  621 };
  622 
  623 struct node {
  624     gint16 t;        /* type identifier */
  625     guint8 flags;    /* AUX_NODE etc., see above */
  626     int vnum;        /* associated series ID number */
  627     char *vname;     /* associated variable name */
  628     user_var *uv;    /* associated named variable */
  629     union val v;     /* value (of whatever type) */
  630     NODE *L, *M, *R; /* up to three child nodes */
  631     NODE *aux;       /* auxiliary (result) node */
  632     int refcount;    /* reference counter, used by aux nodes */
  633 };
  634 
  635 enum parser_flags {
  636     P_DISCARD = 1 <<  0, /* compute and print, don't save */
  637     P_START   = 1 <<  1, /* first round of evaluation */
  638     P_AUTOREG = 1 <<  2, /* expression is autoregressive */
  639     P_DECL    = 1 <<  3, /* statement is actually a declaration */
  640     P_PRIV    = 1 <<  4, /* generating a "private" or internal var */
  641     P_COMPILE = 1 <<  5, /* compiling the parse tree */
  642     P_EXEC    = 1 <<  6, /* evaluating a compiled tree */
  643     P_NATEST  = 1 <<  7, /* testing for NAs in expression */
  644     P_UFRET   = 1 <<  8, /* returning value generated by user function */
  645     P_QUIET   = 1 <<  9, /* don't print any messages or labels */
  646     P_GETSTR  = 1 << 10, /* state: flag acceptance of plain strings */
  647     P_SLAVE   = 1 << 11, /* running as "slave" of NLS/MLE/GMM */
  648     P_MMASK   = 1 << 12, /* genr result is masked matrix */
  649     P_SLICING = 1 << 13, /* state: calculating object slice (temporary) */
  650     P_LAGPRSE = 1 << 14, /* state: parsing lag spec (temporary) */
  651     P_DELTAN  = 1 << 15, /* flag for change in series length */
  652     P_CATCH   = 1 << 16, /* "catch" is in force */
  653     P_NODECL  = 1 << 17, /* type of result was not specified */
  654     P_LISTDEF = 1 << 18, /* expression defines a list */
  655     P_ANON    = 1 << 19, /* generating an anonymous object */
  656     P_VOID    = 1 << 20, /* function call, no assignment */
  657     P_NOEXEC  = 1 << 21, /* just compile, don't evaluate */
  658     P_MSAVE   = 1 << 22, /* trying for reuse of an aux matrix */
  659     P_OBSVAL  = 1 << 23, /* generating value of observation in series */
  660     P_ALIASED = 1 << 24, /* state: handling aliased object (temporary) */
  661     P_AND     = 1 << 25, /* state: working on right-hand term of B_AND */
  662     P_STACK   = 1 << 26, /* executing stack() */
  663     P_ALTINP  = 1 << 27  /* the input string has been substituted */
  664 };
  665 
  666 struct lhinfo {
  667     int t;                 /* type of pre-existing LHS variable, if any */
  668     char name[VNAMELEN];   /* name of LHS variable */
  669     char *label;           /* descriptive string for series */
  670     int vnum;              /* ID number of pre-existing LHS series */
  671     user_var *uv;          /* address of pre-existing LHS variable */
  672     char *expr;            /* expression on left */
  673     GretlType gtype;       /* gretl type of LHS array, if any, or
  674                   of LHS bundle member */
  675     gretl_matrix *mret;    /* matrix output (possibly under bundle or array) */
  676 };
  677 
  678 typedef struct parser_ parser;
  679 
  680 struct parser_ {
  681     const char *input; /* complete input string */
  682     const char *point; /* remaining unprocessed input */
  683     const char *rhs;   /* for use in labelling */
  684     DATASET *dset;     /* convenience pointer to dataset */
  685     PRN *prn;          /* for printing messages */
  686     PRN *errprn;       /* for storing error message in case @prn is NULL */
  687     int flags;         /* various attributes (see @parser_flags above) */
  688     int targ;          /* target type */
  689     int op;            /* assignment operator (possibly inflected) */
  690     struct lhinfo lh;  /* left-hand side info */
  691     NODE *lhtree;      /* LHS syntax tree, if needed */
  692     NODE *lhres;       /* result of eval() on @lhtree */
  693     NODE *tree;        /* RHS syntax tree */
  694     NODE *ret;         /* result of eval() on @tree */
  695     /* below: parser state variables */
  696     NODE *aux;         /* convenience pointer to current auxiliary node */
  697     int callcount;
  698     int dset_n;
  699     int obs;
  700     int sym;
  701     int upsym;
  702     int ch;
  703     double xval;
  704     int idnum;
  705     char *idstr;
  706     void *data;
  707     int err;
  708 };
  709 
  710 int parser_getc (parser *p);
  711 void parser_ungetc (parser *p);
  712 void parser_advance (parser *p, int n);
  713 int parser_char_index (parser *p, int c);
  714 int parser_print_input (parser *p);
  715 void lex (parser *s);
  716 NODE *new_node (int t);
  717 NODE *expr (parser *s);
  718 NODE *newdbl (double x);
  719 NODE *newempty (void);
  720 NODE *newb2 (int t, NODE *l, NODE *r);
  721 NODE *obs_node (parser *p);
  722 const char *getsymb (int t);
  723 const char *getsymb_full (int t, const parser *p);
  724 void set_parsing_query (int s);
  725 void set_doing_genseries (int s);
  726 
  727 int parser_ensure_error_buffer (parser *p);
  728 void context_error (int c, parser *p, const char *func);
  729 void undefined_symbol_error (const char *s, parser *p);
  730 
  731 int realgen (const char *s, parser *p, DATASET *dset,
  732          PRN *prn, int flags, int targtype);
  733 void gen_save_or_print (parser *p, PRN *prn);
  734 void gen_cleanup (parser *p);
  735 void parser_free_aux_nodes (parser *p);
  736 
  737 /* name lookup functions */
  738 const char *constname (int c);
  739 const char *dvarname (int t);
  740 const char *mvarname (int t);
  741 const char *bvarname (int t);
  742 const char *dumname (int t);
  743 int is_gretl_accessor (const char *s);
  744 int mvar_lookup (const char *s);
  745 
  746 int install_function_override (const char *funname,
  747                    const char *pkgname,
  748                    gpointer data);
  749 int delete_function_override (const char *funname,
  750                   const char *pkgname);
  751 
  752 /* handling declarations of variables */
  753 int check_declarations (char ***pS, parser *p);
  754 
  755 /* in genfuncs.c, used only internally */
  756 int cross_sectional_stat (double *x, const int *list,
  757               const DATASET *dset,
  758               int f);
  759 int x_sectional_weighted_stat (double *x, const int *list,
  760                    const int *wlist,
  761                    const DATASET *dset,
  762                    int f);
  763 
  764 /* in geneval.c, used only internally */
  765 double dvar_get_scalar (int i, const DATASET *dset);
  766 int *node_get_list (NODE *n, parser *p);
  767 
  768 /* in genmain.c, used only internally */
  769 int stack_update_parser_input (parser *p);
  770 
  771 /* helper functions for manual, gretl.lang file */
  772 int gen_func_count (void);
  773 const char *gen_func_name (int i);
  774 int model_var_count (void);
  775 const char *model_var_name (int i);
  776 int data_var_count (void);
  777 const char *data_var_name (int i);
  778 int bundle_var_count (void);
  779 const char *bundle_var_name (int i);
  780 int gretl_const_count (void);
  781 const char *gretl_const_name (int i);