bool parse_dasharray(Iterator first, Iterator last, std::vector<double>& dasharray)
{
    using qi::double_;
    using qi::phrase_parse;
    using qi::_1;
    using qi::lit;
    using qi::char_;
#if BOOST_VERSION > 104200
    using qi::no_skip;
#else
    using qi::lexeme;
#endif
    using phoenix::push_back;
    // SVG
    // dasharray ::= (length | percentage) (comma-wsp dasharray)?
    // no support for 'percentage' as viewport is unknown at load_map
    //
    bool r = phrase_parse(first, last,
                          (double_[push_back(phoenix::ref(dasharray), _1)] %
#if BOOST_VERSION > 104200
                          no_skip[char_(", ")]
#else
                          lexeme[char_(", ")]
#endif
                          | lit("none")),
                          qi::ascii::space);
    if (first != last)
    {
        return false;
    }
    return r;
}
int main()
{
    int kase,F,T,d[10009],u,i;
    sieve(10002);
    scanf("%d",&kase);
    while(kase--)
    {
      scanf("%d %d",&F,&T);
      bool vis[10009]={0};
      q.push(F);
      d[F]=0;
      vis[F]=1;
      while(!q.empty())
      {
        u=q.front();
        q.pop();
        for(i=0;i<c;i++)
        {
         if(!vis[a[i]])
          if(check(u,a[i]))
          d[a[i]]=d[u]+1,q.push(a[i]),vis[a[i]]=1;
        }
      }
      if(vis[T])
       printf("%d\n",d[T]);
      else
       printf("Impossible\n");
    }
    return 0;
}
Exemple #3
0
    Event_Bool_No_Param () 
        : Event_Bool_No_Param::base_type(start)
    {
        using qi::lit;

        start =
            lit("STATE_TIMEOUT") | lit("RAMPING_COMPLETED") | lit("PASSIVE_MEAS_COMPLETED")
            ;
    }
Exemple #4
0
bool Compiler::execute() {
  using phoenix::ref;
  using qi::lit;
  using qi::no_skip;

  // iterate over stream input
  typedef std::istreambuf_iterator<char> base_iterator_type;
  base_iterator_type in_begin(m_input);

  // convert input iterator to forward iterator, usable by spirit parser
  typedef spirit::multi_pass<base_iterator_type> forward_iterator_type;
  forward_iterator_type fwd_begin = spirit::make_default_multi_pass(in_begin);
  forward_iterator_type fwd_end;

  // Initialize global scope
  Scope globalScope;
  StdLib::Init(globalScope);

  // Parsers
  ExpParser<forward_iterator_type> exp_;
  CmdParser<forward_iterator_type> cmd_(exp_);
  CodeParser<forward_iterator_type> code_(exp_);

  typedef qi::rule<forward_iterator_type, std::string(), ascii::space_type> StringRule;
  typedef qi::rule<forward_iterator_type, ascii::space_type> VoidRule;
  StringRule cmdline_ =
    lit('[')
    > (cmd_(ref(globalScope)) | code_(ref(globalScope)))
    > lit(']')
  ;
  VoidRule program_ = +(
    cmdline_[ref(m_output) << qi::_1]
    > -no_skip[ lit("\n")[ref(m_output) << endl] ]
  );

  //BOOST_SPIRIT_DEBUG_NODE(cmdline_);
  //BOOST_SPIRIT_DEBUG_NODE(program_);

  bool r = qi::phrase_parse(
    fwd_begin, fwd_end,
    program_,
    ascii::space
  );

  if (!r || fwd_begin != fwd_end) {
    return false;
  }

  // Cleanup the global scope :)
  m_output << globalScope.bytecode() << endl;

  return r;
}
    word_count_grammar(TokenDef const&)
      : word_count_grammar::base_type(start)
      , w(0), c(0), a(0)
    {
        using boost::phoenix::ref;
        using qi::token;

        start =  *(   token(IDWORD) [++ref(w)]
                  |   token(IDCHAR) [++ref(c)]
                  |   token(IDANY)  [++ref(a)]
                  )
              ;
    }
	repeat_remove_cmd_parser< Iterator >::repeat_remove_cmd_parser():
		repeat_remove_cmd_parser::base_type(start)
	{
		using qi::lit;
		using qi::uint_;
		using qi::_val;
		using qi::_1;

		start =
			(lit("remove") | lit("rm") | lit("r")) >>
			uint_
			[
				_val = phx::construct< repeat_remove_cmd >(_1 - phx::val(1u))
			]
		;
	}
Exemple #7
0
int main()
{
    namespace spirit = boost::spirit;
    namespace qi = spirit::qi;
    namespace phoenix = boost::phoenix;
    namespace ascii = spirit::ascii;

    using qi::rule;
    using qi::int_;
    using qi::_1;
    using qi::_val;
    using qi::phrase_parse;
    using boost::shared_ptr;
    using boost::make_shared;

    shared_ptr<int> x = make_shared<int>(123);

    std::cout << *x << std::endl;

    rule<
    std::string::const_iterator
    , shared_ptr<int>()
    , ascii::space_type
    > int_rule_ = int_[_val = new int(_1)];

    shared_ptr<int> subject_;

    std::string text_ = "12345";

    auto result_ = phrase_parse(text_.cbegin(), text_.cend(), int_rule_, ascii::space, subject_);

    std::cout << (result_ ? "passed" : "failed") << *subject_ << std::endl;
}
int parse_int_number_main()
{
	namespace qi = boost::spirit::qi;
	
	using qi::parse;
	using qi::phrase_parse;
	using qi::int_;
	using qi::double_;
	using qi::ascii::space;
	using qi::_1;
	using boost::phoenix::ref;
	using boost::phoenix::push_back;
	char * a = "(12e2,12223)";
	char * a_end = a+strlen(a) ;
	char * b = "(1233)";
	char * b_end = b+strlen(b);
	char * c = "1  , 2,3,4,5,6,7,8,10,13";
	char * c_end = b+strlen(b) ;
	int n = 0;

	std::vector<int> iv;

	phrase_parse(c,c_end, int_%',', space, iv);
	std::ostream_iterator <int> oi(std::cout, ",");
	boost::copy(iv,oi);
	std::cout<<"\n";
	return 0;
}
Exemple #9
0
	best_cmd_parser< Iterator >::best_cmd_parser():
		best_cmd_parser::base_type(start)
	{
		using qi::lit;

		start =
			lit("best")[phx::nothing]
			;
	}
Exemple #10
0
	chart_cmd_parser< Iterator >::chart_cmd_parser():
		chart_cmd_parser::base_type(start)
	{
		using qi::lit;

		start =
			lit("chart")
			[phx::nothing]
//			>> enum_vals
			;
	}
void bfs(long start)
{
	long i,next,u;
	d[start]=0;
	vis[start]=1;
	q.push(start);
	while(!q.empty())
	{
		u=q.front();
		q.pop();
		for(i=0;i<gr[u].size();i++)
		{
			next=gr[u][i];
			if(!vis[next])
			{
				q.push(next);
				vis[next]=1;
				d[next]=d[u]+1;
			}
		}
	}
}
Exemple #12
0
	vista_header_grammer() : vista_header_grammer::base_type ( vista_header ) {
	using qi::lit;
	using qi::lexeme;
	using ascii::char_;
	using ascii::string;
	using namespace qi::labels;

	using phoenix::at_c;
	using phoenix::push_back;

	start_tag = lit ( "V-data 2 {" );

}
	repeat_add_cmd_parser< Iterator >::repeat_add_cmd_parser():
		repeat_add_cmd_parser::base_type(start)
	{
		using qi::lit;
		using qi::_val;

		start =
			lit("add")
			[
				_val = phx::val(repeat_add_cmd{})
			]
		;
	}
Exemple #14
0
	debug_cmd_parser< Iterator >::debug_cmd_parser():
		debug_cmd_parser::base_type(start)
	{
		using qi::lit;
		using qi::_val;

		start =
			lit("dbg")
			[
				_val = phx::val(debug_cmd{})
			]
		;
	}
Exemple #15
0
    bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
    {
        using qi::char_;
        using qi::double_;
        using qi::phrase_parse;
        using qi::_1;
        using ascii::space;
        const char c = ';';
        bool r = phrase_parse(first, last,

            //  Begin grammar
            (
                double_ % char_(',')
            )
            ,
            //  End grammar

            space, v);

        if (first != last) // fail if we did not get a full match
            return false;
        return r;
    }
Exemple #16
0
    tagger(F f_ = F()) : tagger::base_type(start), f(f_)
    {
        using qi::omit;
        using qi::raw;
        using qi::eps;
        using qi::lit;
        using qi::_1;
        using qi::_r1;
        using qi::_r2;

        start   = omit[raw[lit(_r2)] [f(_r1, _1)]];

        epsilon = omit[raw[eps]      [f(_r1, _1)]];
    }
long bfs(long start)
{
    long i,u,next,count=0;
    vis[start]=true;
    q.push(start);
    while(!q.empty())
    {
		count++;
		u=q.front();
        q.pop();
        for(i=0; i<gr[u].size(); i++)
        {
            next=gr[u][i];
            if(vis[next]==false)
            {
				
                q.push(next);
                vis[next]=true;
            }    
        }
    }
	
    return count;
}
Exemple #18
0
    bool parse_numbers( Iterator first, Iterator last, vector<double> &v )
    {
      using qi::double_;
      using qi::phrase_parse;
      using qi::_1;
      using ascii::space;
      using phoenix::push_back;

      bool r( phrase_parse( first, last,
              (
               double_[ push_back( phoenix::ref( v ), _1 ) ] % ','
              ),
                            space ) );
      return ( first == last ? r : false );
    }
Exemple #19
0
    function<Iterator, Lexer>::function(
            error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler
          , Lexer const& l)
      : function::base_type(start), body(error_handler, l)
    {
        qi::_1_type _1;
        qi::_2_type _2;
        qi::_3_type _3;
        qi::_4_type _4;

        qi::_val_type _val;

        using qi::on_error;
        using qi::on_success;
        using qi::fail;
        using boost::phoenix::function;

        typedef client::error_handler<typename Lexer::base_iterator_type, Iterator>
            error_handler_type;
        typedef function<error_handler_type> error_handler_function;
        typedef function<client::annotation<Iterator> > annotation_function;

        identifier = body.expr.identifier;
        argument_list = -(identifier % ',');

        start = (l.token("void") | l.token("int"))
            >   identifier
            >   '(' > argument_list > ')'
            >   (';' | '{' > body > '}')
            ;

        // Debugging and error handling and reporting support.
        BOOST_SPIRIT_DEBUG_NODES(
            (identifier)
            (argument_list)
            (start)
        );

        // Error handling: on error in start, call error_handler.
        on_error<fail>(start,
            error_handler_function(error_handler)(
                "Error! Expecting ", _4, _3));

        // Annotation: on success in start, call annotation.
        on_success(identifier,
            annotation_function(error_handler.iters)(_val, _1));
    }
Exemple #20
0
optional< p_value_test_case >
parse_IC_line( Iterator first, Iterator last )
{
    using qi::double_;
    using qi::_1;
    using qi::uint_;
    using qi::phrase_parse;
    using ascii::space;
    using boost::phoenix::ref;

    optional< p_value_test_case > result;

    /// Will look like "N=2; IC=1.57184,1.57184,1.57184,1.22985,1.22985,1.57184,1.57184,1.22985"
    size_t N;
    if( phrase_parse( first, last, "N=" >> uint_ >> "; IC=", space, N ) ) {
    	result.reset( p_value_test_case( N ) );
        if( ! phrase_parse( first, last, double_ % ",", space, result->ICs ) ) {
        	result = optional< p_value_test_case >(); // reset
        }
    }

    return result;
}
Exemple #21
0
int
main()
{
    using spirit_test::test_attr;
    namespace qi = boost::spirit::qi;

    using qi::attr;
    using qi::double_;

    {
        double d = 0.0;
        BOOST_TEST(test_attr("", attr(1.0), d) && d == 1.0);

        double d1 = 1.0;
        BOOST_TEST(test_attr("", attr(d1), d) && d == 1.0);

        std::pair<double, double> p;
        BOOST_TEST(test_attr("1.0", double_ >> attr(1.0), p) && 
            p.first == 1.0 && p.second == 1.0);

        char c = '\0';
        BOOST_TEST(test_attr("", attr('a'), c) && c == 'a');
        std::string str;
        BOOST_TEST(test_attr("", attr("test"), str) && str == "test");
    }

    {   // testing lazy constructs
        using boost::phoenix::val;
        using boost::phoenix::ref;

        double d = 0.0;
        BOOST_TEST(test_attr("", attr(val(1.0)), d) && d == 1.0);

        double d1 = 2.0;
        BOOST_TEST(test_attr("", attr(ref(d1)), d) && d == 2.0);
    }

    {
        std::string s;
        BOOST_TEST(test_attr("s", "s" >> qi::attr(std::string("123")), s) && 
            s == "123");
    }

    return boost::report_errors();
}
Exemple #22
0
    bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
    {
        using qi::double_;
        using qi::phrase_parse;
        using qi::_1;
        using ascii::space;
        using phoenix::push_back;
        using phoenix::ref;

        bool r = phrase_parse(first, last,

            //  Begin grammar
            (
                double_[push_back(ref(v), _1)] % ','
            )
            ,
            //  End grammar

            space);

        if (first != last) // fail if we did not get a full match
            return false;
        return r;
    }
Exemple #23
0
    statement<Iterator, Lexer>::statement(
            error_handler<typename Lexer::base_iterator_type, Iterator>& error_handler
          , Lexer const& l)
      : statement::base_type(statement_list), expr(error_handler, l)
    {
        qi::_1_type _1;
        qi::_2_type _2;
        qi::_3_type _3;
        qi::_4_type _4;

        qi::_val_type _val;
        qi::tokenid_mask_type tokenid_mask;

        using qi::on_error;
        using qi::on_success;
        using qi::fail;
        using boost::phoenix::function;

        typedef client::error_handler<typename Lexer::base_iterator_type, Iterator>
            error_handler_type;
        typedef function<error_handler_type> error_handler_function;
        typedef function<client::annotation<Iterator> > annotation_function;

        statement_list =
            +statement_
            ;

        statement_ =
                variable_declaration
            |   assignment
            |   compound_statement
            |   if_statement
            |   while_statement
            |   return_statement
            |   expr
            |   ';'
            ;

        variable_declaration =
                l("int")
            >   expr.identifier
            >  -(l("=") > expr)
            >   ';'
            ;

        assignment =
                expr.identifier
            >   tokenid_mask(token_ids::op_assign)
            >   expr
            >   ';'
            ;

        if_statement =
                l("if")
            >   '('
            >   expr
            >   ')'
            >   statement_
            >
               -(
                    l("else")
                >   statement_
                )
            ;

        while_statement =
                l("while")
            >   '('
            >   expr
            >   ')'
            >   statement_
            ;

        compound_statement =
            '{' >> -statement_list >> '}'
            ;

        return_statement =
                l("return")
            >  -expr
            >   ';'
            ;

        // Debugging and error handling and reporting support.
        BOOST_SPIRIT_DEBUG_NODES(
            (statement_list)
            (statement_)
            (variable_declaration)
            (assignment)
            (if_statement)
            (while_statement)
            (compound_statement)
            (return_statement)
        );

        // Error handling: on error in statement_list, call error_handler.
        on_error<fail>(statement_list,
            error_handler_function(error_handler)(
                "Error! Expecting ", _4, _3));

        // Annotation: on success in variable_declaration,
        // assignment and return_statement, call annotation.
        on_success(variable_declaration,
            annotation_function(error_handler.iters)(_val, _1));
        on_success(assignment,
            annotation_function(error_handler.iters)(_val, _1));
        on_success(return_statement,
            annotation_function(error_handler.iters)(_val, _1));
    }
Exemple #24
0
bool solve(qi &l)
{
   int t;
   si r;

   int i=1;
   bool found=false;
   while(!l.empty())
   {
      t=l.front();
      if(t==i) { found=true; break; }
      r.push(t);
      l.pop();
   }
   if(!found) return false;
   l.pop();
   i+=1;

   while(!l.empty() && !r.empty())
   {
      if(l.front()==i)
	 l.pop();
      else if(r.top()==i)
	 r.pop();
      else
      {  
         found=false;
	 while(!l.empty())
	 {
	    t=l.front();
	    if(t==i) { found=true; break; }
	    r.push(t);
	    l.pop();
	 }
         if(!found) return false;
	 l.pop();
      }
      i+=1;
   }
   return true;
}