Example #1
0
queue<string> readfile(fstream &fin,parser &SLRparser)
{
	char line[SIZE];
	queue<string> testCases;
    while(fin.getline(line,sizeof(line),'\n')){
		string transfer(line);
		if(!strncmp(line, "#", 1)){
		}
		else if(!strncmp(line, "non-term:", 9)){
			SLRparser.storeNonTerminals(transfer.substr(9));
		}
		else if(!strncmp(line, "term:", 5)){
			SLRparser.storeTerminals(transfer.substr(5));
		}
		else if(!strncmp(line, "prod:", 5)){
			SLRparser.storeProductions(transfer.substr(5));
		}
		else if(!strncmp(line, "start:", 6)){
			SLRparser.storeStartSymbol(transfer.substr(6));
		}
		else{
			testCases.push(transfer);
		}
    }
	return testCases;
}
Example #2
0
static expr parse_notation_expr(parser & p, buffer<expr> const & locals) {
    auto pos = p.pos();
    expr r = p.parse_expr();
    r = abstract(r, locals.size(), locals.data());
    check_notation_expr(r, pos);
    return r;
}
Example #3
0
environment namespace_cmd(parser & p) {
    auto pos = p.pos();
    name n = p.check_atomic_id_next("invalid namespace declaration, atomic identifier expected");
    if (is_root_namespace(n))
        throw parser_error(sstream() << "invalid namespace name, '" << n << "' is reserved", pos);
    return push_scope(p.env(), p.ios(), n);
}
Example #4
0
    inline int _parse_quadhex(parser<Iter> &in_)
    {
        int uni_ch = 0,
            hex;

        for (int i = 0; i < 4; i++)
        {
            if ((hex = in_.getc()) == -1)
            {
                return -1;
            }

            if ('0' <= hex && hex <= '9')
            {
                hex -= '0';
            }
            else if ('A' <= hex && hex <= 'F')
            {
                hex -= 'A' - 0xa;
            }
            else if ('a' <= hex && hex <= 'f')
            {
                hex -= 'a' - 0xa;
            }
            else
            {
                in_.ungetc();
                return -1;
            }

            uni_ch = uni_ch * 16 + hex;
        }

        return uni_ch;
    }
Example #5
0
static name parse_quoted_symbol_or_token(parser & p, buffer<token_entry> & new_tokens, bool & used_default, notation_entry_group grp) {
    used_default = false;
    if (p.curr_is_quoted_symbol()) {
        environment const & env = p.env();
        auto pp_tk = p.get_name_val();
        auto tks   = utf8_trim(pp_tk.to_string());
        auto tkcs  = tks.c_str();
        check_not_forbidden(tkcs);
        p.next();
        if (p.curr_is_token(get_colon_tk())) {
            p.next();
            unsigned prec = parse_precedence(p);
            new_tokens.push_back(mk_token_entry(tkcs, prec, grp));
        } else if (!get_precedence(env, tkcs, grp)) {
            new_tokens.push_back(mk_token_entry(tkcs, LEAN_DEFAULT_PRECEDENCE, grp));
            used_default = true;
        }
        return pp_tk;
    } else if (p.curr_is_keyword()) {
        auto tk = p.get_token_info().token();
        check_not_forbidden(tk.to_string().c_str());
        p.next();
        return tk;
    } else {
        throw parser_error("invalid notation declaration, symbol expected", p.pos());
    }
}
Example #6
0
void show_usage(parser& p)
{
	cout <<desc<<"\n"<<"FORMAT KEYWORDS:\n";
	for (parser::parse_elements::iterator it = p.keywords_begin(); it != p.keywords_end() ; it++)
	{
		cout <<"\t"<<parser::_key_word_id<<(*it).first <<"\n";
	}
}
Example #7
0
static optional<unsigned> parse_optional_precedence(parser & p) {
    if (p.curr_is_token(get_colon_tk())) {
        p.next();
        return some(parse_precedence_core(p));
    } else {
        return optional<unsigned>();
    }
}
Example #8
0
static unsigned parse_binders_rbp(parser & p) {
    if (p.curr_is_token(get_colon_tk())) {
        p.next();
        return parse_precedence(p);
    } else {
        return 0;
    }
}
Example #9
0
static void load_command_variables(variables_map& variables, parser& metadata,
    int argc, const char* argv[])
{
    const auto options = metadata.load_options();
    const auto arguments = metadata.load_arguments();
    auto command_parser = command_line_parser(argc, argv).options(options)
        .positional(arguments);
    store(command_parser.run(), variables);
}
Example #10
0
void type_modifiers::parse(parser & p) {
    while (true) {
        if (p.curr_is_token(get_class_tk())) {
            m_is_class = true;
            p.next();
        } else {
            break;
        }
    }
}
Example #11
0
 void parse(parser & p) {
     while (true) {
         if (p.curr_is_token(get_parsing_only_tk())) {
             p.next();
             m_parse_only = true;
         } else if (auto prio = parse_priority(p)) {
             m_priority = *prio;
         } else {
             return;
         }
     }
 }
Example #12
0
static void parse_notation_local(parser & p, buffer<expr> & locals) {
    if (p.curr_is_identifier()) {
        name n = p.get_name_val();
        p.next();
        expr local_type = mk_Prop(); // type used in notation local declarations, it is irrelevant
        expr l = mk_local(n, local_type); // remark: the type doesn't matter
        p.add_local(l);
        locals.push_back(l);
    } else {
        throw parser_error("invalid notation declaration, identifier expected", p.pos());
    }
}
Example #13
0
    inline bool _parse_codepoint(String& out, parser<Iter>& in)
    {
        int uni_ch;

        if ((uni_ch = _parse_quadhex(in)) == -1)
        {
            return false;
        }

        if (0xd800 <= uni_ch && uni_ch <= 0xdfff)
        {
            if (0xdc00 <= uni_ch)
            {
                // a second 16-bit of a surrogate pair appeared
                return false;
            }

            // first 16-bit of surrogate pair, get the next one
            if (in.getc() != '\\' || in.getc() != 'u')
            {
                in.ungetc();
                return false;
            }

            int second = _parse_quadhex(in);

            if (!(0xdc00 <= second && second <= 0xdfff))
            {
                return false;
            }

            uni_ch = ((uni_ch - 0xd800) << 10) | ((second - 0xdc00) & 0x3ff);
            uni_ch += 0x10000;
        }

        if (uni_ch < 0x80)
        {
            out.push_back(uni_ch);
        }
        else
        {
            if (uni_ch < 0x800)
            {
                out.push_back(0xc0 | (uni_ch >> 6));
            }
            else
            {
                if (uni_ch < 0x10000)
Example #14
0
compiler::compiler(parser& p, void (*fp)(const char*)) :
  m(fp), forwards(), callback(fp)
{
  // Perform complete compilation
  while ( compile_token(p.next_token(), p) )
    ; // loop
}
Example #15
0
void parse(parser& parser)
{
 //clear
 
 clear();

 //empty

 if(parser.is_empty())
  return;

 //composite

 if(try_composite(parser))
  return;

 //assign

 if(try_assign(parser))
  return;
  
 //dereference

 if(try_dereference(parser))
  return;
  
 //annotation

 if(try_annotation(parser))
  return;
     
 //unit

 check(try_unit(parser));
}
Example #16
0
static bool load_configuration_variables(variables_map& variables,
    parser& metadata)
{
    const auto config_settings = metadata.load_settings();
    const auto config_path = get_config_option(variables);

    // If the existence test errors out we pretend there's no file :/.
    error_code code;
    if (!config_path.empty() && exists(config_path, code))
    {
        bc::ifstream file(config_path.string());
        if (!file.good())
        {
            BOOST_THROW_EXCEPTION(reading_file(config_path.string().c_str()));
        }

        const auto config = parse_config_file(file, config_settings);
        store(config, variables);
        return true;
    }

    // Loading from an empty stream causes the defaults to populate.
    std::stringstream stream;
    const auto config = parse_config_file(stream, config_settings);
    store(config, variables);
    return false;
}
Example #17
0
environment coercion_cmd(parser & p) {
    auto pos = p.pos();
    expr f   = p.parse_expr();
    if (!is_constant(f))
        throw parser_error("invalid 'coercion' command, constant expected", pos);
    if (p.curr_is_token(g_colon)) {
        p.next();
        pos = p.pos();
        expr C = p.parse_expr();
        if (!is_constant(C))
            throw parser_error("invalid 'coercion' command, constant expected", pos);
        return add_coercion(p.env(), const_name(f), const_name(C), p.ios());
    } else {
        return add_coercion(p.env(), const_name(f), p.ios());
    }
}
void parser<mcld::MCLDDirectory>::printOptionDiff(const llvm::cl::Option &O,
                                                  const mcld::MCLDDirectory &V,
                                                  parser<mcld::MCLDDirectory>::OptVal Default,
                                                  size_t GlobalWidth) const
{
  printOptionName(O, GlobalWidth);
  outs() << "= " << V.name();
  size_t VSize = V.name().size();
  size_t NumSpaces = MaxOptWidth > VSize ? MaxOptWidth - VSize : 0;
  outs().indent(NumSpaces) << " (default: ";
  if (Default.hasValue())
    outs() << Default.getValue().name();
  else
    outs() << "*no default*";
  outs() << ")\n";
}
Example #19
0
static void load_environment_variables(variables_map& variables,
    parser& metadata)
{
    const auto& environment_variables = metadata.load_environment();
    const auto environment = parse_environment(environment_variables,
        BS_ENVIRONMENT_VARIABLE_PREFIX);
    store(environment, variables);
}
static expr parse_struct_expr_core(parser & p, pos_info const & pos, bool curly_bar) {
    expr t = p.parse_expr();
    buffer<name> field_names;
    buffer<expr> field_values;
    buffer<expr> using_exprs;
    while (p.curr_is_token(get_comma_tk())) {
        p.next();
        pair<optional<name>, expr> id_e = p.parse_optional_assignment();
        if (id_e.first) {
            field_names.push_back(*id_e.first);
            field_values.push_back(id_e.second);
        } else {
            using_exprs.push_back(id_e.second);
        }
    }
    if (curly_bar)
        p.check_token_next(get_rcurlybar_tk(), "invalid structure expression, '|}' expected");
    else
        p.check_token_next(get_rdcurly_tk(), "invalid structure expression, '⦄' expected");
    buffer<expr> args;
    args.push_back(t);
    args.append(field_values);
    args.append(using_exprs);
    return p.save_pos(mk_structure_instance(to_list(field_names), args.size(), args.data()), pos);
}
Example #21
0
static void parse_filters(parser & p, buffer<std::string> & pos_names, buffer<std::string> & neg_names) {
    name plus("+"); name minus("-");
    while (p.curr_is_token(get_comma_tk())) {
        p.next();
        if (p.curr_is_token(plus)) {
            p.next();
            pos_names.push_back(p.check_id_next("invalid find_decl command, identifier expected").to_string());
        } else if (p.curr_is_token(minus)) {
            p.next();
            neg_names.push_back(p.check_id_next("invalid find_decl command, identifier expected").to_string());
        } else {
            pos_names.push_back(p.check_id_next("invalid find_decl command, '+', '-', or identifier expected").to_string());
        }
    }
}
Example #22
0
 void copy_inline_body(render_buf &output)
 {
     while (1) {
         mem_chunk buf = output.get_free_mem();
         if (!stream->read_body(buf)) {
             break;
         }
         output.write(buf);
     }
 }
Example #23
0
static environment mixfix_cmd(parser & p, mixfix_kind k, bool overload, notation_entry_group grp, bool persistent) {
    notation_modifiers mods;
    mods.parse(p);
    flet<bool> set_allow_local(g_allow_local, !persistent);
    auto nt = parse_mixfix_notation(p, k, overload, grp, mods.m_parse_only, mods.m_priority);
    environment env = p.env();
    if (nt.second)
        env = add_user_token(env, *nt.second, persistent);
    env = add_notation(env, nt.first, persistent);
    return env;
}
Example #24
0
static name parse_class(parser & p) {
    if (p.curr_is_token(g_lbracket)) {
        p.next();
        name n;
        if (p.curr_is_identifier())
            n = p.get_name_val();
        else if (p.curr_is_keyword() || p.curr_is_command())
            n = p.get_token_info().value();
        else
            throw parser_error("invalid 'using' command, identifier or symbol expected", p.pos());
        p.next();
        p.check_token_next(g_rbracket, "invalid 'using' command, ']' expected");
        return n;
    } else {
        return name();
    }
}
Example #25
0
static environment notation_cmd_core(parser & p, bool overload, notation_entry_group grp, bool persistent) {
    notation_modifiers mods;
    mods.parse(p);
    flet<bool> set_allow_local(g_allow_local, !persistent);
    environment env = p.env();
    buffer<token_entry> new_tokens;
    auto ne = parse_notation_core(p, overload, grp, new_tokens, mods.m_parse_only, mods.m_priority);
    for (auto const & te : new_tokens)
        env = add_user_token(env, te, persistent);
    env = add_notation(env, ne, persistent);
    return env;
}
Example #26
0
environment set_line_cmd(parser & p) {
    if (!p.curr_is_numeral())
        throw parser_error("invalid #setline command, numeral expected", p.pos());
    unsigned r = p.get_small_nat();
    p.set_line(r);
    p.next();
    return p.env();
}
Example #27
0
std::size_t message::read(std::istream& in,
                          boost::system::error_code& ec,
                          parser& http_parser)
{
    // make sure that we start out with an empty message & clear error_code
    clear();
    ec.clear();
    
    // parse data from file one byte at a time
    boost::tribool parse_result;
    char c;
    while (in) {
        in.read(&c, 1);
        if ( ! in ) {
            ec = make_error_code(boost::system::errc::io_error);
            break;
        }
        http_parser.set_read_buffer(&c, 1);
        parse_result = http_parser.parse(*this, ec);
        if (! boost::indeterminate(parse_result)) break;
    }

    if (boost::indeterminate(parse_result)) {
        if (http_parser.check_premature_eof(*this)) {
            // premature EOF encountered
            if (! ec)
                ec = make_error_code(boost::system::errc::io_error);
        } else {
            // EOF reached when content length unknown
            // assume it is the correct end of content
            // and everything is OK
            parse_result = true;
            ec.clear();
        }
    }
    
    return (http_parser.get_total_bytes_read());
}
Example #28
0
cpp_ptr<cpp_type_alias> cpp_type_alias::parse(const parser &p, const cpp_name &scope, cpp_cursor cur)
{
    assert(clang_getCursorKind(cur) == CXCursor_TypedefDecl
           || clang_getCursorKind(cur) == CXCursor_TypeAliasDecl);

    auto name = detail::parse_name(cur);
    auto target = parse_alias_target(cur, name);
    auto result = detail::make_ptr<cpp_type_alias>(scope, std::move(name), detail::parse_comment(cur),
                                                   clang_getCursorType(cur), target);

    p.register_type(*result);

    return result;
}
static unsigned int
heap_analysis ()
{
	// Run this analysis only in LTO mode
	if (!in_lto_p)
		return 0;

    fprintf(dump_file, "\ncs618heap: STARTED.\n");
    std::cerr<<"\ncs618heap: STARTED.\n"; //AN NEWADD

	program.initialization ();
    std::cerr << "Part 1 Done \n" ;
    program.preprocess_control_flow_graph ();
    std::cerr << "Part 2 Done \n" ;
	program.print_parsed_data ();
	program.print_original_cfg();
	program.delete_block_aux ();

	RESULT ("\n\n");
    fprintf(dump_file, "\ncs618heap: ENDED.\n"); //AN NEWADD
    std::cerr<<"\ncs618heap: ENDED.\n"; //AN NEWADD

	return 0;
}
Example #30
0
environment add_alias(parser & p, environment env, bool composite,
                      name const & full_id, levels const & ctx_levels, buffer<expr> const & ctx_params) {
    name id;
    if (composite)
        id = name(name(full_id.get_prefix().get_string()), full_id.get_string());
    else
        id = name(full_id.get_string());
    if (!empty(ctx_levels) || !ctx_params.empty()) {
        expr r = mk_local_ref(full_id, ctx_levels, ctx_params);
        env = p.add_local_ref(env, id, r);
    }
    if (full_id != id)
        env = add_expr_alias_rec(env, id, full_id);
    return env;
}