"Fossies" - the Fresh Open Source Software Archive

Member "gretl-2020e/lib/src/genparse.h" (25 Oct 2020, 20477 Bytes) of package /linux/misc/gretl-2020e.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: 2020d_vs_2020e.

    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_SGN,
  140     F_CEIL,
  141     F_FLOOR,
  142     F_SIN,
  143     F_COS,
  144     F_TAN,
  145     F_ASIN,
  146     F_ACOS,
  147     F_ATAN,
  148     F_SINH,
  149     F_COSH,
  150     F_TANH,
  151     F_ASINH,
  152     F_ACOSH,
  153     F_ATANH,
  154     F_LOG,
  155     F_LOG10,
  156     F_LOG2,
  157     F_EXP,
  158     F_SQRT,
  159     F_GAMMA,
  160     F_LNGAMMA,
  161     F_DIGAMMA,
  162     F_INVMILLS,
  163     F_ROUND,
  164     F_CNORM,
  165     F_DNORM,
  166     F_QNORM,
  167     F_CARG,
  168     F_CMOD,
  169     F_REAL,
  170     F_IMAG,
  171     F_LOGISTIC,
  172     FP_MAX,      /* separator: end of pointerized functions */
  173     F_CONJ,
  174     F_TOINT,
  175     F_DIFF,   /* first difference */
  176     F_LDIFF,      /* log difference */
  177     F_SDIFF,      /* seasonal difference */
  178     F_SORT,   /* ascending sort */
  179     F_DSORT,      /* descending sort */
  180     F_RANKING,
  181     F_ODEV,   /* orthogonal deviation */
  182     F_NOBS,
  183     F_CUM,
  184     F_MISSING,
  185     F_DATAOK,
  186     F_MISSZERO,
  187     F_ZEROMISS,
  188     F_MEDIAN,
  189     F_GINI,
  190     F_SUM,
  191     F_SUMALL,
  192     F_MEAN,
  193     F_MIN,
  194     F_MAX,
  195     F_SD,
  196     F_VCE,    /* variance */
  197     F_SKEWNESS,
  198     F_KURTOSIS,
  199     F_SST,
  200     F_SUMR,
  201     F_SUMC,
  202     F_PRODR,
  203     F_PRODC,
  204     F_MEANR,
  205     F_MEANC,
  206     F_CHOL,
  207     F_INV,
  208     F_INVPD,
  209     F_GINV,
  210     F_DIAG,
  211     F_TRANSP,
  212     F_VEC,
  213     F_VECH,
  214     F_UNVECH,
  215     F_ROWS,
  216     F_COLS,
  217     F_DET,
  218     F_LDET,
  219     F_TRACE,
  220     F_NORM1,
  221     F_INFNORM,
  222     F_RCOND,
  223     F_RANK,
  224     F_OBSNUM,
  225     F_ISDISCR,
  226     F_ISDUMMY,
  227     F_TYPEOF,
  228     F_EXISTS,
  229     F_NELEM,
  230     F_PDF,
  231     F_PVAL,
  232     F_CDF,
  233     F_INVCDF,
  234     F_CRIT,
  235     F_URCPVAL,
  236     F_RANDGEN,
  237     F_MRANDGEN,
  238     F_RANDGEN1,
  239     F_VALUES,
  240     F_UNIQ,
  241     F_NULLSPC,
  242     F_MEXP,
  243     F_MINC,
  244     F_MAXC,
  245     F_MINR,
  246     F_MAXR,
  247     F_IMINC,
  248     F_IMAXC,
  249     F_IMINR,
  250     F_IMAXR,
  251     F_FFT,
  252     F_FFT2,
  253     F_FFTI,
  254     F_UPPER,
  255     F_LOWER,
  256     F_POLROOTS,
  257     F_OBSLABEL,
  258     F_BACKTICK,
  259     F_STRLEN,
  260     F_VARNAME,
  261     F_VARNAMES,
  262     F_VARNUM,
  263     F_TOLOWER,
  264     F_TOUPPER,
  265     F_IRR,
  266     F_ERRMSG,
  267     F_GETENV,
  268     F_NGETENV,
  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_PSHRINK,
  359     F_RANDINT,
  360     F_MREAD,
  361     F_BREAD,
  362     F_GETLINE,
  363     F_ISODATE,
  364     F_JULDATE,
  365     F_READFILE,
  366     F_PRINTF,
  367     F_SPRINTF,
  368     F_MPI_SEND,
  369     F_BCAST,
  370     F_ALLREDUCE,
  371     F_GENSERIES,
  372     F_KPSSCRIT,
  373     F_STRINGIFY,
  374     F_SQUARE,
  375     F_SEASONALS,
  376     F_DROPCOLL,
  377     F_KSIMDATA,
  378     F_HFDIFF,
  379     F_HFLDIFF,
  380     F_NAALEN,
  381     F_KMEIER,
  382     F_NORMTEST,
  383     F_COR,
  384     F_LRCOVAR,
  385     F_JSONGETB,
  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     F_BINCOEFF,
  405     F_ASSERT,
  406     F2_MAX,   /* SEPARATOR: end of two-arg functions */
  407     F_LLAG,
  408     F_HFLAG,
  409     F_PRINCOMP,
  410     F_BFGSMAX,
  411     F_MSHAPE,
  412     F_SVD,
  413     F_TRIMR,
  414     F_TOEPSOLV,
  415     F_CORRGM,
  416     F_SEQ,
  417     F_REPLACE,
  418     F_STRNCMP,
  419     F_BESSEL,
  420     F_WEEKDAY,
  421     F_MONTHLEN,
  422     F_EPOCHDAY,
  423     F_KDENSITY,
  424     F_SETNOTE,
  425     F_BWFILT,
  426     F_VARSIMUL,
  427     F_STRSUB,
  428     F_REGSUB,
  429     F_MLAG,
  430     F_EIGSOLVE,
  431     F_SIMANN,
  432     F_HALTON,
  433     F_MWRITE,
  434     F_BWRITE,
  435     F_AGGRBY,
  436     F_IWISHART,
  437     F_SSCANF,
  438     F_SUBSTR,
  439     F_REDUCE,
  440     F_SCATTER,
  441     F_MWEIGHTS,
  442     F_MGRADIENT,
  443     F_MLINCOMB,
  444     F_HFLIST,
  445     F_NMMAX,
  446     F_GSSMAX,
  447     F_NPCORR,
  448     F_DAYSPAN,
  449     F_SMPLSPAN,
  450     F_FDJAC,
  451     F_NUMHESS,
  452     F_STRSPLIT,
  453     F_HPFILT,
  454     F_XMLGET,
  455     F_JSONGET,
  456     F_FEVD,
  457     F_LRVAR,
  458     F_BRENAME,
  459     F_ISOWEEK,
  460     F_BKW,
  461     F_FZERO,
  462     F_EIGGEN,
  463     F_EIGEN,
  464     F_SCHUR,
  465     F_RESAMPLE,
  466     F_STACK,
  467     F_GEOPLOT,
  468     HF_REGLS,
  469     F3_MAX,       /* SEPARATOR: end of three-arg functions */
  470     F_BKFILT,
  471     F_MOLS,
  472     F_MPOLS,
  473     F_MRLS,
  474     F_FILTER,
  475     F_MCOVG,
  476     F_KFILTER,
  477     F_KSMOOTH,
  478     F_KDSMOOTH,
  479     F_KSIMUL,
  480     F_NRMAX,
  481     F_LOESS,
  482     F_GHK,
  483     F_QUADTAB,
  484     F_ISOCONV,
  485     F_QLRPVAL,
  486     F_BOOTCI,
  487     F_BOOTPVAL,
  488     F_MOVAVG,
  489     F_DEFARRAY,
  490     F_DEFBUNDLE,
  491     F_DEFLIST,
  492     F_DEFARGS,
  493     F_BPACK,
  494     F_KSETUP,
  495     F_BFGSCMAX,
  496     F_SVM,
  497     F_IRF,
  498     F_NADARWAT,
  499     F_FEVAL,
  500     F_CHOWLIN,
  501     F_TDISAGG,
  502     F_HYP2F1,
  503     F_MMULT,
  504     HF_CLOGFI,
  505     FN_MAX,   /* SEPARATOR: end of n-arg functions */
  506 };
  507 
  508 enum {
  509     CONST_PI = 1,
  510     CONST_NA,
  511     CONST_INF,
  512     CONST_NAN,
  513     CONST_WIN32,
  514     CONST_EPS,
  515     CONST_HAVE_MPI,
  516     CONST_MPI_RANK,
  517     CONST_MPI_SIZE,
  518     CONST_N_PROC,
  519     CONST_TRUE,
  520     CONST_FALSE,
  521     CONST_SYSINFO
  522 };
  523 
  524 enum {
  525     DUM_NULL = 1,
  526     DUM_DIAG,
  527     DUM_UPPER,
  528     DUM_LOWER,
  529     DUM_REAL,
  530     DUM_IMAG,
  531     DUM_DATASET,
  532     DUM_TREND
  533 };
  534 
  535 #define GENSTRLEN 128
  536 #define NO_VNUM -1
  537 
  538 #define unary_op(s)  (s >= 1 && s < U_MAX)
  539 #define binary_op(s) (s > U_MAX && s < OP_MAX)
  540 #define bool_comp(s) (s >= B_EQ && s <= B_OR)
  541 #define dot_op(s)    (s >= B_DOTMULT && s <= B_DOTNEQ)
  542 
  543 #define func1_symb(s) (s > F1_MIN && s < F1_MAX)
  544 #define func2_symb(s) (s > F1_MAX && s < F2_MAX)
  545 #define func3_symb(s) (s > F2_MAX && s < F3_MAX)
  546 #define funcn_symb(s) (s > F3_MAX && s < FN_MAX)
  547 
  548 #define bnsym(s) (s == MDEF || s == FARGS)
  549 
  550 #define alias_reversed(n) (n->flags & ALS_NODE)
  551 
  552 /* function with single string argument */
  553 #define string_arg_func(s) (s == F_ISDISCR || s == F_OBSNUM || \
  554                 s == F_BACKTICK || s == F_VARNUM || \
  555                 s == F_EXISTS || s == F_REMOVE || \
  556                 s == F_ISCMPLX)
  557 
  558 /* function with multiple args, string for first arg */
  559 #define str0_func(s) (s == F_PVAL || s == F_CDF || s == F_INVCDF || \
  560               s == F_CRIT || s == F_RANDGEN || s == F_PDF || \
  561               s == F_BESSEL || s == F_MRANDGEN || s == F_RANDGEN1)
  562 
  563 /* functions taking a string arg in last position */
  564 #define string_last_func(s) (s == F_DESEAS || s == F_AGGRBY || \
  565                  s == F_PRINTF || s == F_SPRINTF || \
  566                  s == F_ALLREDUCE || s == F_NORMTEST || \
  567                  s == F_SSCANF || s == F_NPCORR || \
  568                  s == F_INBUNDLE || s == F_GENSERIES)
  569 
  570 /* functions taking string arg in middle position */
  571 #define string_mid_func(s) (s == F_REDUCE || s == F_SCATTER)
  572 
  573 /* functions taking one or more "fncall" (string) arguments */
  574 #define fncall_func(s) (s == F_BFGSMAX || s == F_NRMAX || \
  575             s == F_FDJAC || s == F_SIMANN || \
  576             s == F_BFGSCMAX || s == F_NMMAX || \
  577             s == F_GSSMAX || s == F_NUMHESS || \
  578             s == F_FZERO)
  579 
  580 /* functions with "reversing" aliases */
  581 #define als_func(s) (s == F_BFGSMAX || s == F_NRMAX || \
  582              s == F_SIMANN || s == F_BFGSCMAX || \
  583              s == F_NMMAX || s == F_GSSMAX || \
  584              s == F_EXISTS)
  585 
  586 /* functions where the right-hand argument is actually a return
  587    location */
  588 #define r_return(s) (s == F_QR || s == F_EIGSYM || s == F_EIGEN || \
  589                      s == F_MOLS || s == F_MPOLS || s == F_SVD || \
  590              s == F_EIGGEN)
  591 
  592 /* functions where the middle argument is actually a return
  593    location */
  594 #define m_return(s) (s == F_SVD || s == F_EIGEN)
  595 
  596 #define reusable(p) (p->flags & (P_COMPILE | P_EXEC))
  597 
  598 typedef struct node NODE;
  599 
  600 struct branchn {
  601     int n_nodes;
  602     NODE **n;
  603 };
  604 
  605 union val {
  606     struct branchn bn;
  607     int idnum;
  608     char *str;
  609     double xval;
  610     double *xvec;
  611     int *ivec;
  612     gretl_matrix *m;
  613     matrix_subspec *mspec;
  614     gretl_bundle *b;
  615     gretl_array *a;
  616     void *ptr;
  617 };
  618 
  619 enum node_flags {
  620     AUX_NODE = 1 << 0, /* auxiliary: free on exit */
  621     TMP_NODE = 1 << 1, /* temporary: free content on exit */
  622     SVL_NODE = 1 << 2, /* holds string-valued series */
  623     PRX_NODE = 1 << 3, /* aux node is proxy (don't reuse!) */
  624     LHT_NODE = 1 << 4, /* node holds terminal of LHS */
  625     MSL_NODE = 1 << 5, /* (scalar) node is matrix element */
  626     MUT_NODE = 1 << 6, /* node is inherently mutable in type */
  627     ALS_NODE = 1 << 7  /* function subject to "reversing" alias */
  628 };
  629 
  630 struct node {
  631     gint16 t;        /* type identifier */
  632     guint8 flags;    /* AUX_NODE etc., see above */
  633     int vnum;        /* associated series ID number */
  634     char *vname;     /* associated variable name */
  635     user_var *uv;    /* associated named variable */
  636     union val v;     /* value (of whatever type) */
  637     NODE *L, *M, *R; /* up to three child nodes */
  638     NODE *aux;       /* auxiliary (result) node */
  639     int refcount;    /* reference counter, used by aux nodes */
  640 };
  641 
  642 enum parser_flags {
  643     P_DISCARD = 1 <<  0, /* compute and print, don't save */
  644     P_START   = 1 <<  1, /* first round of evaluation */
  645     P_AUTOREG = 1 <<  2, /* expression is autoregressive */
  646     P_DECL    = 1 <<  3, /* statement is actually a declaration */
  647     P_PRIV    = 1 <<  4, /* generating a "private" or internal var */
  648     P_COMPILE = 1 <<  5, /* compiling the parse tree */
  649     P_EXEC    = 1 <<  6, /* evaluating a compiled tree */
  650     P_NATEST  = 1 <<  7, /* testing for NAs in expression */
  651     P_UFRET   = 1 <<  8, /* returning value generated by user function */
  652     P_QUIET   = 1 <<  9, /* don't print any messages or labels */
  653     P_GETSTR  = 1 << 10, /* state: flag acceptance of plain strings */
  654     P_SLAVE   = 1 << 11, /* running as "slave" of NLS/MLE/GMM */
  655     P_MMASK   = 1 << 12, /* genr result is masked matrix */
  656     P_SLICING = 1 << 13, /* state: calculating object slice (temporary) */
  657     P_LAGPRSE = 1 << 14, /* state: parsing lag spec (temporary) */
  658     P_DELTAN  = 1 << 15, /* flag for change in series length */
  659     P_CATCH   = 1 << 16, /* "catch" is in force */
  660     P_NODECL  = 1 << 17, /* type of result was not specified */
  661     P_LISTDEF = 1 << 18, /* expression defines a list */
  662     P_ANON    = 1 << 19, /* generating an anonymous object */
  663     P_VOID    = 1 << 20, /* function call, no assignment */
  664     P_NOEXEC  = 1 << 21, /* just compile, don't evaluate */
  665     P_MSAVE   = 1 << 22, /* trying for reuse of an aux matrix */
  666     P_OBSVAL  = 1 << 23, /* generating value of observation in series */
  667     P_ALIASED = 1 << 24, /* state: handling aliased object (temporary) */
  668     P_AND     = 1 << 25, /* state: working on right-hand term of B_AND */
  669     P_STACK   = 1 << 26, /* executing stack() */
  670     P_ALTINP  = 1 << 27, /* the input string has been substituted */
  671     P_OBJQRY  = 1 << 28, /* querying the existence of an object */
  672     P_STRVEC  = 1 << 29  /* "complex" calc with string-valued series */
  673 };
  674 
  675 struct lhinfo {
  676     int t;                 /* type of pre-existing LHS variable, if any */
  677     char name[VNAMELEN];   /* name of LHS variable */
  678     char *label;           /* descriptive string for series */
  679     int vnum;              /* ID number of pre-existing LHS series */
  680     user_var *uv;          /* address of pre-existing LHS variable */
  681     char *expr;            /* expression on left */
  682     GretlType gtype;       /* gretl type of LHS array, if any, or
  683                   of LHS bundle member */
  684     gretl_matrix *mret;    /* matrix output (possibly under bundle or array) */
  685 };
  686 
  687 typedef struct parser_ parser;
  688 
  689 struct parser_ {
  690     const char *input; /* complete input string */
  691     const char *point; /* remaining unprocessed input */
  692     const char *rhs;   /* for use in labelling */
  693     DATASET *dset;     /* convenience pointer to dataset */
  694     PRN *prn;          /* for printing messages */
  695     PRN *errprn;       /* for storing error message in case @prn is NULL */
  696     int flags;         /* various attributes (see @parser_flags above) */
  697     int targ;          /* target type */
  698     int op;            /* assignment operator (possibly inflected) */
  699     struct lhinfo lh;  /* left-hand side info */
  700     NODE *lhtree;      /* LHS syntax tree, if needed */
  701     NODE *lhres;       /* result of eval() on @lhtree */
  702     NODE *tree;        /* RHS syntax tree */
  703     NODE *ret;         /* result of eval() on @tree */
  704     /* below: parser state variables */
  705     NODE *aux;         /* convenience pointer to current auxiliary node */
  706     int callcount;
  707     int dset_n;
  708     int obs;
  709     int sym;
  710     int upsym;
  711     int ch;
  712     double xval;
  713     int idnum;
  714     char *idstr;
  715     void *data;
  716     int err;
  717 };
  718 
  719 int parser_getc (parser *p);
  720 void parser_ungetc (parser *p);
  721 void parser_advance (parser *p, int n);
  722 int parser_char_index (parser *p, int c);
  723 int parser_print_input (parser *p);
  724 void lex (parser *s);
  725 NODE *new_node (int t);
  726 NODE *expr (parser *s);
  727 NODE *newdbl (double x);
  728 NODE *newempty (void);
  729 NODE *newb2 (int t, NODE *l, NODE *r);
  730 NODE *obs_node (parser *p);
  731 const char *getsymb (int t);
  732 const char *getsymb_full (int t, const parser *p);
  733 void set_parsing_query (int s);
  734 void set_doing_genseries (int s);
  735 
  736 int parser_ensure_error_buffer (parser *p);
  737 void context_error (int c, parser *p, const char *func);
  738 void undefined_symbol_error (const char *s, parser *p);
  739 
  740 int realgen (const char *s, parser *p, DATASET *dset,
  741          PRN *prn, int flags, int targtype);
  742 void gen_save_or_print (parser *p, PRN *prn);
  743 void gen_cleanup (parser *p);
  744 void parser_free_aux_nodes (parser *p);
  745 
  746 /* name lookup functions */
  747 const char *constname (int c);
  748 const char *dvarname (int t);
  749 const char *mvarname (int t);
  750 const char *bvarname (int t);
  751 const char *dumname (int t);
  752 int is_gretl_accessor (const char *s);
  753 int mvar_lookup (const char *s);
  754 
  755 int install_function_override (const char *funname,
  756                    const char *pkgname,
  757                    gpointer data);
  758 int delete_function_override (const char *funname,
  759                   const char *pkgname);
  760 
  761 /* handling declarations of variables */
  762 int check_declarations (char ***pS, parser *p);
  763 
  764 /* in genfuncs.c, used only internally */
  765 int cross_sectional_stat (double *x, const int *list,
  766               const DATASET *dset,
  767               int f);
  768 int x_sectional_weighted_stat (double *x, const int *list,
  769                    const int *wlist,
  770                    const DATASET *dset,
  771                    int f);
  772 
  773 /* in geneval.c, used only internally */
  774 double dvar_get_scalar (int i, const DATASET *dset);
  775 int *node_get_list (NODE *n, parser *p);
  776 
  777 /* in genmain.c, used only internally */
  778 int stack_update_parser_input (parser *p);
  779 
  780 /* helper functions for manual, gretl.lang file */
  781 int gen_func_count (void);
  782 const char *gen_func_name (int i);
  783 int model_var_count (void);
  784 const char *model_var_name (int i);
  785 int data_var_count (void);
  786 const char *data_var_name (int i);
  787 int bundle_var_count (void);
  788 const char *bundle_var_name (int i);
  789 int gretl_const_count (void);
  790 const char *gretl_const_name (int i);