Exemple #1
0
static void read_numeral(LexState *ls, TValue *tv)
{
  lua_assert(lj_ctype_isdigit(ls->current));
  do {
    save_and_next(ls);
  } while (lj_ctype_isdigit(ls->current) || ls->current == '.');
  if (check_next(ls, "Ee"))  /* `E'? */
    check_next(ls, "+-");  /* optional exponent sign */
  while (lj_ctype_isident(ls->current))
    save_and_next(ls);
  save(ls, '\0');
  if (!lj_str_numconv(ls->sb.buf, tv))
    lj_lex_error(ls, TK_number, LJ_ERR_XNUMBER);
}
Exemple #2
0
ASTNode* parse_literal(std::vector<token> &tokens, tokIter &it) {
  START_PARSE(LiteralNode);
  //IF WE ADD A "LITERAL" TOKEN TYPE, FIX THIS!
  READ_OF_TYPE(IDENT);
  int value = 0;
  std::string text = it->text;
  try {
       if (text != "double") throw 1;
       if (!check_next(tokens,it,IDENT)) throw 1;
       it++; text = it->text;
       double dvalue = std::stod(text);
       node->value = (int) (dvalue * (1 << 16));
       SUCCEED_PARSE;
  } catch(...) {};
  try {
          value = std::stoi(text);
          //NOTE: above stoi has some quirks. "123abc" -> 123, even though there is text.
          //POSSIBLY DO SOME BOUNDS CHECKING?
          node->value = value<<16;
          SUCCEED_PARSE;
  } catch (...) {
    //stoi exception when it fails.
    PARSE_ERR(text + " was not any expression?");
  }
  return nullptr;
}
Exemple #3
0
void record_var::parse(proto_info &, cursor &c) {
    const std::string str = get_to_sep(c, ';');
    check_next(c, ';');
    auto pos = str.rfind(' ');
    pimpl->type = str.substr(0, pos);
    pimpl->name = str.substr(pos+1);
}
Exemple #4
0
int	check_builts(char *cmd, char **arg, char **env)
{
  int	ret;

  ret = 0;
  if (my_strcmp("setenv", arg[0]) == 0)
    {
      if (arg == NULL || arg[0] == NULL || arg[1] == NULL || arg[2] == NULL)
	printf("Usage : setenv [NAME] [VALUE] \n");
      else
	my_setenv(env, arg[1], arg[2]);
      ++ret;
    }
  if (my_strcmp("unsetenv", arg[0]) == 0)
    {
      if (arg && arg[0] && arg[1])
	my_unsetenv(env, arg[1]);
      else
	printf("Usage : unsetenv [NAME] \n");
      save_my_env(env);
      ++ret;
    }
  ret += check_next(cmd, arg, env);
  if (ret == 0)
    printf("%s : Command not found\n", arg[0]);
  return (ret);
}
Exemple #5
0
static void	sort_hint(t_hint *hint, int *i, int j)
{
	int	var;
	t_range	rg;

	bzero_rangval(&rg);
	init_rangval(&rg, hint->lst_data, j);
	var = ((t_pile*)(((t_list*)(*(hint->lst_a)))->content))->val;
	if (var >= rg.one && var < rg.two)
	{
		p_local(hint->lst_a, hint->lst_b, hint->mark);
		r_local(hint->lst_b, hint->mark);
		(*i)++;
	}
	else if (var >= rg.three && var < rg.four)
	{
		p_local(hint->lst_a, hint->lst_b, hint->mark);
		if (ft_lstcount(*(hint->lst_b)) > 1)
		{
				if (!check_next(*(hint->lst_b)))
					s_local(hint->lst_b, hint->mark);
		}
		(*i)++;
	}
	else
	{
		hint->mark->asc = 1;
		if (check_rothint(hint, rg))
			r_local(hint->lst_a, hint->mark);
		else
			rev_local(hint->lst_a, hint->mark);
		hint->mark->asc = 0;
	}
}
Exemple #6
0
ASTNode* parse_phi(std::vector<token> &tokens, tokIter &it) {
  START_PARSE(PhiNode);
  READ_TEXT("phi");
  while(check_next(tokens,it,OPENBRACE)) {
    it++;
    ASTNode* expr = parse_expression(tokens,it);
    if (!expr) PARSE_ERR("phi node had a bad value?");
    if (!check_next(tokens,it,VAR)) { delete expr; PARSE_ERR("phi node had bad predecessor?");}
    it++;
    std::string pred = it->text;
    if (!check_next(tokens,it,CLOSEBRACE)) { delete expr; PARSE_ERR("phi node format...");};
    it++;
    node->values.push_back(ASTsubtree(expr));
    node->source_blocks.push_back(current_function+pred);
  }
  SUCCEED_PARSE;
}
Exemple #7
0
void set_sensitive_dep(int start_bool, int finish_bool, int suspend_bool, int abort_bool, char *set_false)
{
  peos_sense.start = start_bool;
  peos_sense.finish = finish_bool;
  peos_sense.suspend = suspend_bool;
  peos_sense.abort = abort_bool;
  if(set_false == NULL) {
  	peos_sense.next = check_next();
  	peos_sense.prev = check_prev();
  } else {
  	peos_sense.next = FALSE;
  	peos_sense.prev = FALSE;
  }
}
Exemple #8
0
void record_proc::parse(proto_info &, cursor &c) {
    pimpl->req_name = get_to_sep(c, ' ', '-');
    check_next(c, '-');
    check_next(c, '>');
    pimpl->handler_name = get_to_sep(c, ' ', ':');
    check_next(c, ':');
    check_next(c, proc_sig_open_char);
    pimpl->sig = get_to_sep(c, proc_sig_close_char);
    check_next(c, proc_sig_close_char);
    check_next(c, proc_sig_close_dotcomma_char);
}
Exemple #9
0
// sub routine for searching current pattern
// is recursive
// tests for pattern by testing one meta char after the other
// o if firstmatch == 0 then if first char of lineptr doesnt match pattern
//   return failure
// o  returns pointer to first match in firstmatch and
//    -1 (failure) or 2 (success)
int Regexpr::_search(char **firstmatch)
{
  char *oldlineptr,*oldpatptr,*prevpatptr;
  int err,index;

    index = 0;
    oldpatptr = patptr;
    oldlineptr = lineptr;
    if (firstmatch)
        *firstmatch = lineptr;

    while (1) {
        prevpatptr = patptr;
        if ((err = check_next()) == 0) {    // pattern element not found
            if (!firstmatch || (*(lineptr-1) == eol)) {
                // fixed_mode or end of line reached -> failed (forever)
test_next:
                patptr = prevpatptr;
                if ((oldpatptr = scan_behind('|')) == NULLPTR)
                    return -1;
                index = -1;
                oldpatptr++;    // skip |
            }
            patptr = oldpatptr;
            lineptr = oldlineptr+(++index); // -> try with next character
            if (firstmatch)
                *firstmatch = lineptr;
            continue;
        }
        // -1 is returned a) when syntax error (patptr-1 == 0) occurred
        // b) pattern impossible
        if (err == -1) {    // if for some reason -1 came back
            if (*(patptr-1) == 0)   // try next pattern if possible
                return -1;  // not possible because illegal end
            goto test_next;
        }
        if (err == 2)       // return success
            return 2;
    }
}
Exemple #10
0
TokenType Lexer::getToken()
{
	while(true)
	{
        next();
        switch(current_)
        {
        case EOF:
            return ENDFILE;
        case ' ' : case '\f' : case '\t' : case '\v' :
            break;
        case '\n' :
            increase_line();
            break;
        case '=' :
            if(check_next('='))
                return EQ;
            return ASSIGN;
        case '<' :
            if(check_next('='))
                return LE;
            return LT;
        case '+' :
            return ADD;
        case '-' :
            return SUB;
        case '*' :
            return MUL;
        case '(' :
            return LP;
        case ')' :
            return RP;
        case ';' :
            return SEMI;
        case '/' :
            if(check_next('/'))
            {
                if(skip_comment() == false)
                    return ERROR;
                break;
            }

            if(check_next('*'))
            {
                if(skip_comment2() == false)
                    return ERROR;
                break;
            }

            return DIV;
        case '0': case '1': case '2': case '3': case '4':
        case '5': case '6': case '7': case '8': case '9':
            read_num();
            return NUM;
        default :
            if(read_id())
            {
                auto iter = reserve_word.find(id_);
                if(iter != reserve_word.end())
                    return iter->second;
                return ID;
            }
            else
                return ERROR;
        }
    }
}
Exemple #11
0
int main(int argc, char ** argv) {
    pyrebloomctxt ctxt;
    uint32_t i;
    time_t start, end;
    uint32_t count = 1000000;

    init_pyrebloom(&ctxt, "bloom", count, 0.01, "localhost", 6379, "", 0);
    int L=0;
    
    srand(0);
    time(&start);
    for (i = 0; i < count; ++i) {
        int r = rand();
        char c[32];
        sprintf(c, "%08X", r);
        // printf("%s", c);
        L += strlen(c);
        add(&ctxt, c, strlen(c));
    }
    add_complete(&ctxt, count);
    time(&end);
    printf("ADD %f\n", difftime(end,start));
    
    // printf("\n");
    // printf("----------------------------\n");
    // printf("size: %d\n", L);
    // printf("----------------------------\n");

    // srand(0);
    time(&start);
    for (i = 0; i < count; ++i) {
        int r = rand();
        // rand();
        char c[32];
        sprintf(c, "%08X", r);
        // printf("%s", c);
        check(&ctxt, c, strlen(c));
    }

    int cnt = 0;
    for (i = 0; i < count; ++i) {
        int res = check_next(&ctxt);
        if(res) cnt++; 
    }
    time(&end);
    printf("CHECK %f\n", difftime(end,start));

    printf("count: %d false positive:%d prob: %f %%\n", count, cnt, 100.0/count*cnt);
    //delete(&ctxt);
    free_pyrebloom(&ctxt);

    // time(&start);
    // for (i = 0; i < count; ++i) {
    //     redisAppendCommand(ctxt.ctxt, "SADD testing2 hello");
    // }
    // add_complete(&ctxt, count / 4);
    // time(&end);
    // printf("sadd      : %f\n", difftime(end, start));

    return 0;
}
Exemple #12
0
static int llex(LexState *ls, TValue *tv)
{
  lj_str_resetbuf(&ls->sb);
  for (;;) {
    if (lj_ctype_isident(ls->current)) {
      GCstr *s;
      if (lj_ctype_isdigit(ls->current)) {  /* Numeric literal. */
	read_numeral(ls, tv);
	return TK_number;
      }
      /* Identifier or reserved word. */
      do {
	save_and_next(ls);
      } while (lj_ctype_isident(ls->current));
      s = lj_parse_keepstr(ls, ls->sb.buf, ls->sb.n);
      if (s->reserved > 0)  /* Reserved word? */
	return TK_OFS + s->reserved;
      setstrV(ls->L, tv, s);
      return TK_name;
    }
    switch (ls->current) {
    case '\n':
    case '\r':
      inclinenumber(ls);
      continue;
    case ' ':
    case '\t':
    case '\v':
    case '\f':
      next(ls);
      continue;
    case '-':
      next(ls);
      if (ls->current != '-') return '-';
      /* else is a comment */
      next(ls);
      if (ls->current == '[') {
	int sep = skip_sep(ls);
	lj_str_resetbuf(&ls->sb);  /* `skip_sep' may dirty the buffer */
	if (sep >= 0) {
	  read_long_string(ls, NULL, sep);  /* long comment */
	  lj_str_resetbuf(&ls->sb);
	  continue;
	}
      }
      /* else short comment */
      while (!currIsNewline(ls) && ls->current != END_OF_STREAM)
	next(ls);
      continue;
    case '[': {
      int sep = skip_sep(ls);
      if (sep >= 0) {
	read_long_string(ls, tv, sep);
	return TK_string;
      } else if (sep == -1) {
	return '[';
      } else {
	lj_lex_error(ls, TK_string, LJ_ERR_XLDELIM);
	continue;
      }
      }
    case '=':
      next(ls);
      if (ls->current != '=') return '='; else { next(ls); return TK_eq; }
    case '<':
      next(ls);
      if (ls->current != '=') return '<'; else { next(ls); return TK_le; }
    case '>':
      next(ls);
      if (ls->current != '=') return '>'; else { next(ls); return TK_ge; }
    case '~':
      next(ls);
      if (ls->current != '=') return '~'; else { next(ls); return TK_ne; }
    case '"':
    case '\'':
      read_string(ls, ls->current, tv);
      return TK_string;
    case '.':
      save_and_next(ls);
      if (check_next(ls, ".")) {
	if (check_next(ls, "."))
	  return TK_dots;   /* ... */
	else
	  return TK_concat;   /* .. */
      } else if (!lj_ctype_isdigit(ls->current)) {
	return '.';
      } else {
	read_numeral(ls, tv);
	return TK_number;
      }
    case END_OF_STREAM:
      return TK_eof;
    default: {
      int c = ls->current;
      next(ls);
      return c;  /* Single-char tokens (+ - / ...). */
    }
    }
  }
}
Exemple #13
0
void record_class::parse(proto_info &, cursor &c) {
    pimpl->name = get_to_sep(c, ' ', class_close_dotcomma_char);
    check_next(c, class_close_dotcomma_char);
}
Exemple #14
0
void record_namespace::parse(proto_info &, cursor &c) {
    pimpl->name = get_to_sep(c, ' ', namespace_close_dotcomma_char);
    check_next(c, namespace_close_dotcomma_char);
}
Exemple #15
0
void record_struct::parse(proto_info &info, cursor &c) {
    pimpl->name = get_to_sep(c, ' ', struct_base_classes_separator, struct_body_open_char);

    skipws(c);
    // process list of base structs
    if ( curch(c) == struct_base_classes_separator ) {
        nextch(c);
        skipws(c);

        cursor tc = c;
        std::string base;
        bool flag = false;

        while ( ! flag ) {
            char ch = nextch(c);
            switch ( ch ) {
            case '/': {
                prevch(c);
                skipws(c);
                continue;
            }
            case ' ':
            case ',': {
                if ( ch == ',' && base.empty() )
                    YARMI_THROW(
                        "bad char '%c', expected name of base struct in %s"
                        ,ch
                        ,c.format()
                    );

                if ( !struct_already_declared(info, base) )
                    YARMI_THROW(
                        "base struct '%s'(%s) is not declared"
                        ,base
                        ,tc.format()
                    );

                pimpl->base.push_back(base);
                base.clear();
                skipws(c);
                if ( curch(c) == ',' ) {
                    nextch(c);
                    skipws(c);
                }
                tc = c;
                continue;
            }
            case struct_body_open_char: {
                flag = true;
                prevch(c);
                break;
            }
            default: {
                base.push_back(ch);
            }
            }
        }
    }

    check_next(c, struct_body_open_char);
    skipws(c);

    for ( ;; ) {
        const iterator it = c.it;
        const std::string kword = get_to_sep(c, ' ');
        const bool is_type = is_type_name(kword);
        c.it = (is_type ? it : c.it);

        record_ptr o = record_factory((is_type ? "var" : kword));
        if ( !o )
            YARMI_THROW(
                "bad keyword \"%s\" in %s"
                ,kword
                ,c.format()
            );

        o->parse(info, c);
        pimpl->members.push_back(std::move(o));

        skipws(c);
        const char ch = curch(c);
        if ( ch == struct_body_close_char )
            break;
    }
    check_next(c, struct_body_close_char);
    check_next(c, struct_body_close_dotcomma_char);
}
Exemple #16
0
void record_using::parse(proto_info &, cursor &c) {
    pimpl->name = get_to_sep(c, ' ', using_assign_char);
    check_next(c, using_assign_char);
    pimpl->type = get_to_sep(c, using_close_dotcomma_char);
    check_next(c, using_close_dotcomma_char);
}