symbol *symbol_table::lookup(const string &name, uint16_t offset) { auto _symbol = lookup_table.find(full_name(name, offset)); if (_symbol == lookup_table.end()) { throw undefined_symbol_error(name); } return &_symbol->second; }
static void look_up_string_variable (const char *s, parser *p) { char *val = get_string_by_name(s + 1); if (val != NULL) { p->idstr = gretl_strdup(s + 1); if (p->idstr == NULL) { p->err = E_ALLOC; } else { p->uval = val; p->sym = USTR; } } else { undefined_symbol_error(s, p); } }
static void look_up_dollar_word (const char *s, parser *p) { if ((p->idnum = dvar_lookup(s)) > 0) { p->sym = DVAR; } else if ((p->idnum = const_lookup(s)) > 0) { if (p->idnum == CONST_SYSINFO) { p->sym = BUNDLE; p->idstr = gretl_strdup("$sysinfo"); p->uval = get_sysinfo_bundle(&p->err); } else { p->sym = CON; } } else if ((p->idnum = mvar_lookup(s)) > 0) { p->sym = MVAR; } else { undefined_symbol_error(s, p); } #if LDEBUG fprintf(stderr, "look_up_dollar_word: '%s' -> %d\n", s, p->idnum); #endif }
static void look_up_word (const char *s, parser *p) { int fsym, err = 0; fsym = p->sym = function_lookup_with_alias(s); if (p->sym == 0 || p->ch != '(') { p->idnum = const_lookup(s); if (p->idnum > 0) { p->sym = CON; } else { p->idnum = dummy_lookup(s); if (p->idnum > 0) { p->sym = DUM; } else { GretlType vtype = 0; char *bstr; if ((p->idnum = current_series_index(p->dset, s)) >= 0) { p->sym = UVEC; p->idstr = gretl_strdup(s); } else if (!strcmp(s, "time")) { p->sym = DUM; p->idnum = DUM_TREND; } else if ((p->uval = user_var_get_value_and_type(s, &vtype)) != NULL) { if (vtype == GRETL_TYPE_DOUBLE) { p->sym = UNUM; } else if (vtype == GRETL_TYPE_MATRIX) { p->sym = UMAT; } else if (vtype == GRETL_TYPE_BUNDLE) { p->sym = BUNDLE; } else if (vtype == GRETL_TYPE_STRING) { p->sym = USTR; } else if (vtype == GRETL_TYPE_LIST) { p->sym = ULIST; } else if (vtype == GRETL_TYPE_STRING) { p->sym = USTR; } p->idstr = gretl_strdup(s); } else if ((bstr = get_built_in_string_by_name(s))) { /* FIXME should use $-accessors? */ p->sym = STR; p->idstr = gretl_strdup(bstr); } else if (gretl_get_object_by_name(s)) { p->sym = UOBJ; p->idstr = gretl_strdup(s); } else if (get_user_function_by_name(s)) { p->sym = UFUN; p->idstr = gretl_strdup(s); } else if (p->targ == LIST && varname_match_any(p->dset, s)) { p->sym = WLIST; p->idstr = gretl_strdup(s); } else if (!strcmp(s, "t")) { /* if "t" has not been otherwise defined, treat it as an alias for "obs" */ p->sym = DVAR; p->idnum = R_INDEX; } else if (maybe_get_R_function(s)) { /* note: all "native" types take precedence over this */ p->sym = RFUN; p->idstr = gretl_strdup(s + 2); } else if (parsing_query) { p->sym = UNDEF; p->idstr = gretl_strdup(s); } else { err = E_UNKVAR; } } } } if (err) { if (fsym) { function_noargs_error(s, p); } else { undefined_symbol_error(s, p); } } }