Example #1
0
double Calculator::parseExprMul(std::string_view &ref)
{
	double value = parseSymbol(ref);
	while (true)
	{
		skipSpaces(ref);
		if (!ref.empty() && ref[0] == '*')
		{
			ref.remove_prefix(1);
			value *= parseSymbol(ref);
			m_printStrategy->printMultiplication();
		}
		else if (!ref.empty() && ref[0] == '/')
		{
			ref.remove_prefix(1);
			value /= parseSymbol(ref);
			m_printStrategy->printDivision();
		}
		else
		{
			break;
		}
	}

	return value;
}
Example #2
0
    Token Lexer::parseNext() {
        //skip whitespace of the current character
        skipWhitespace();

        //return eof if we are at the end
        if (curChar() == '\0') {
            return Token::Eof;
        }

        Token ret;

        //first check if it is a keyword and return it
        ret = parseKeyword();
        if (ret != Token::None)
            return ret;
        ret = parseSymbol();
        if (ret != Token::None)
            return ret;
        ret = parseIdentifier();
        if (ret != Token::None)
            return ret;
        ret = parseNumeric();
        if (ret != Token::None)
            return ret;

        //if nothing was able to parse it, it must be a character and we return it
        value.character = eatChar();
        return Token::Character;
    }
Example #3
0
static void cmd_symbol(Stream *chp, int argc, char* argv[])
{
   if (argc > 0)
     chprintf(chp, "%s\r\n", parseSymbol(argv[0], buf));
   else {
     char tab = GET_BYTE_PARAM(SYMBOL_TAB);
     char sym = GET_BYTE_PARAM(SYMBOL);
     chprintf(chp, "SYMBOL %c%c\r\n", tab,sym);
   }
}
 SExpression* parse(TokenStream& Tokens) {
     if (!Tokens.hasNext()) { return NULL; }
     IToken* Token = Tokens.next();
     if (dynamic_cast<OpenParen*>(Token)) {
         return parseList(Tokens);
     } else if (dynamic_cast<Symbol*>(Token)) {
         return parseSymbol(dynamic_cast<Symbol*>(Token));
     } else if (dynamic_cast<CloseParen*>(Token)) {
         throw invalid_syntax();
     } else if (dynamic_cast<String*>(Token)) {
         return parseString(dynamic_cast<String*>(Token));
     } else {
         return NULL;
     }
 }
Example #5
0
// =============================================================================
//
Expression::Expression (BotscriptParser* parser, Lexer* lx, DataType reqtype) :
	m_parser (parser),
	m_lexer (lx),
	m_type (reqtype)
{
	ExpressionSymbol* sym;

	while ((sym = parseSymbol()) != null)
		m_symbols << sym;

	// If we were unable to get any expression symbols, something's wonky with
	// the script. Report an error. mBadTokenText is set to the token that
	// ParseSymbol ends at when it returns false.
	if (m_symbols.isEmpty())
		error ("unknown identifier '%1'", m_badTokenText);

	adjustOperators();
	verify();
	evaluate();
}
Example #6
0
  RTCORE_API void rtcInit(const char* cfg) 
  {
      cout << "in rtcInit " << endl;
    Lock<MutexSys> lock(g_mutex);
    TRACE(rtcInit);
    CATCH_BEGIN;

    if (g_initialized) {
      g_mutex.unlock();
      process_error(RTC_INVALID_OPERATION,"already initialized");
      g_mutex.lock();
      return;
    }
    g_initialized = true;

    /* reset global state */
    initSettings();
    
    if (cfg != NULL) 
    {
      size_t pos = 0;
      do {
        std::string tok = parseIdentifier (cfg,pos);

        if (tok == "threads" && parseSymbol(cfg,'=',pos)) 
	{
	  g_numThreads = parseInt(cfg,pos);
#if defined(__MIC__)
	  if (!(g_numThreads == 1 || (g_numThreads % 4) == 0)) {
	    g_mutex.unlock();
	    process_error(RTC_INVALID_OPERATION,"Xeon Phi supports only number of threads % 4 == 0, or threads == 1");
	    g_mutex.lock();
            return;
          }
#endif
        }
        else if (tok == "isa" && parseSymbol (cfg,'=',pos)) 
	{
	  std::string isa = parseIdentifier (cfg,pos);
	  if      (isa == "sse" ) cpu_features = SSE;
	  else if (isa == "sse2") cpu_features = SSE2;
	  else if (isa == "sse3") cpu_features = SSE3;
	  else if (isa == "ssse3") cpu_features = SSSE3;
	  else if (isa == "sse41") cpu_features = SSE41;
	  else if (isa == "sse42") cpu_features = SSE42;
	  else if (isa == "avx") cpu_features = AVX;
	  else if (isa == "avxi") cpu_features = AVXI;
	  else if (isa == "avx2") cpu_features = AVX2;
	}
        else if ((tok == "tri_accel" || tok == "accel") && parseSymbol (cfg,'=',pos))
            g_tri_accel = parseIdentifier (cfg,pos);
	else if ((tok == "tri_builder" || tok == "builder") && parseSymbol (cfg,'=',pos))
	    g_tri_builder = parseIdentifier (cfg,pos);
	else if ((tok == "tri_traverser" || tok == "traverser") && parseSymbol (cfg,'=',pos))
            g_tri_traverser = parseIdentifier (cfg,pos);
      	else if ((tok == "tri_accel_mb" || tok == "accel_mb") && parseSymbol (cfg,'=',pos))
            g_tri_accel = parseIdentifier (cfg,pos);
	else if ((tok == "tri_builder_mb" || tok == "builder_mb") && parseSymbol (cfg,'=',pos))
	    g_tri_builder = parseIdentifier (cfg,pos);
        else if ((tok == "tri_traverser_mb" || tok == "traverser_mb") && parseSymbol (cfg,'=',pos))
            g_tri_traverser = parseIdentifier (cfg,pos);
        else if (tok == "hair_accel" && parseSymbol (cfg,'=',pos))
            g_hair_accel = parseIdentifier (cfg,pos);
	else if (tok == "hair_builder" && parseSymbol (cfg,'=',pos))
            g_hair_builder = parseIdentifier (cfg,pos);
	else if (tok == "hair_traverser" && parseSymbol (cfg,'=',pos))
            g_hair_traverser = parseIdentifier (cfg,pos);
	else if (tok == "hair_builder_replication_factor" && parseSymbol (cfg,'=',pos))
            g_hair_builder_replication_factor = parseInt (cfg,pos);
	
        else if (tok == "verbose" && parseSymbol (cfg,'=',pos))
            g_verbose = parseInt (cfg,pos);
	else if (tok == "benchmark" && parseSymbol (cfg,'=',pos))
            g_benchmark = parseInt (cfg,pos);
        else if (tok == "flags") {
          g_scene_flags = 0;
          if (parseSymbol (cfg,'=',pos)) {
            do {
              std::string flag = parseIdentifier (cfg,pos);
              if      (flag == "static" ) g_scene_flags |= RTC_SCENE_STATIC;
              else if (flag == "dynamic") g_scene_flags |= RTC_SCENE_DYNAMIC;
              else if (flag == "compact") g_scene_flags |= RTC_SCENE_COMPACT;
              else if (flag == "coherent") g_scene_flags |= RTC_SCENE_COHERENT;
              else if (flag == "incoherent") g_scene_flags |= RTC_SCENE_INCOHERENT;
              else if (flag == "high_quality") g_scene_flags |= RTC_SCENE_HIGH_QUALITY;
              else if (flag == "robust") g_scene_flags |= RTC_SCENE_ROBUST;
            } while (parseSymbol (cfg,',',pos));
          }
        }
        
      } while (findNext (cfg,',',pos));
    }

    if (g_verbose >= 1)
    {
      std::cout << "Embree Ray Tracing Kernels " << __EMBREE_VERSION__ << " (" << __DATE__ << ")" << std::endl;
      std::cout << "  Compiler : " << getCompilerName() << std::endl;
      std::cout << "  Platform : " << getPlatformName() << std::endl;
      std::cout << "  CPU      : " << stringOfCPUFeatures(getCPUFeatures()) << std::endl;
      std::cout << "  Features : ";
#if defined(__USE_RAY_MASK__)
      std::cout << "raymasks ";
#endif
#if defined (__BACKFACE_CULLING__)
      std::cout << "backfaceculling ";
#endif
#if defined(__INTERSECTION_FILTER__)
      std::cout << "intersection_filter ";
#endif
#if defined(__BUFFER_STRIDE__)
      std::cout << "bufferstride ";
#endif
      std::cout << std::endl;

#if defined (__MIC__)
#if defined(__BUFFER_STRIDE__)
      std::cout << "  WARNING: enabled 'bufferstride' support will lower BVH build performance" << std::endl;
#endif
#endif
    }

    /* CPU has to support at least SSE2 */
#if !defined (__MIC__)
    if (!has_feature(SSE2)) {
      g_mutex.unlock();
      process_error(RTC_UNSUPPORTED_CPU,"CPU does not support SSE2");
      g_mutex.lock();
      return;
    }
#endif

    g_error = createTls();
    g_error_function = NULL;

    init_globals();
    cout << "in rtcInit(), BVH4Register() " << endl;
#if !defined(__MIC__)
    cout << "BVH4Register()" << endl;
    BVH4Register();
#else
    cout << "BVH4iRegister() " << endl;
    BVH4iRegister();
#endif 
    cout << "BVH4MBRegister() " << endl;
    BVH4MBRegister();
    BVH4HairRegister();    
#if defined(__TARGET_AVX__)
    cout << "BVH8Register() " << endl;
    if (has_feature(AVX)) {
      BVH8Register();
    }
#endif
    
    InstanceIntersectorsRegister();

//if (g_verbose >= 2) 
    printSettings();
    
    TaskScheduler::create(g_numThreads);

    cout << " end rtcInit " << endl;
    CATCH_END;
  }