示例#1
0
文件: Reader.hpp 项目: questor/git-ws
					inline Val parseArr()
					{
						Arr arr;

						// Skip '['
						++idx;

						// Empty array
						if(isC(']')) goto end;

						// Reserve some memory
						arr.reserve(10);

						while(true)
						{
							// Get value
							arr.emplace_back(parseVal());

							// Check for another value
							if(isC(',')) { ++idx; continue; }

							// Check for end of the array
							if(isC(']')) break;

							throwError("Invalid array", std::string{"Expected either `,` or `]`, got `"} + getC() + "`");
						}

						end:

						// Skip ']'
						++idx;

						return Val{arr};
					}
示例#2
0
文件: Reader.hpp 项目: questor/git-ws
					inline Val parseObj()
					{
						Obj obj;

						// Skip '{'
						++idx;

						// Empty object
						if(isC('}')) goto end;

						// Reserve some memory
						obj.reserve(10);

						while(true)
						{
							// Read string key
							if(!isC('"')) throwError("Invalid object", std::string{"Expected `\"` , got `"} + getC() + "`");
							auto key(readStr());

							// Read ':'
							if(!isC(':')) throwError("Invalid object", std::string{"Expected `:` , got `"} + getC() + "`");

							// Skip ':'
							++idx;

							// Read value
							obj[std::move(key)] = parseVal();

							// Check for another key-value pair
							if(isC(',')) { ++idx; continue; }

							// Check for end of the object
							if(isC('}')) break;

							throwError("Invalid object", std::string{"Expected either `,` or `}`, got `"} + getC() + "`");
						}

						end:

						// Skip '}'
						++idx;

						return Val{obj};
					}
void sieve() {
    unsigned i, j, k;
    for(i = 3; i < LMT; i += 2)
        if( !ifC(i) )
            for(j = i*i, k = (i<<1); j < MAX; j += k)
                isC(j);
    for(i = 3, j = 0; i<MAX; i += 2)
        if( !ifC(i) )
            primes[j++] = i;
    primelen = j;
}
示例#4
0
文件: lex.c 项目: Pendrokar/ilmentufa
token *
lex()
	{
	static char *word = NULL;
	token *result;
	char *p;

	result = newtoken();

	if (!word || *word == 0) {
		word = getword();
		if (!word) {
			result->type = 0;
			if (D_valsi)
				printf("valsi: end of text\n");
			return result;
			}
		}

	if (iscmene(word)) {
		result->type = CMENE_518;
		result->text = newstring(strlen(word) + 1);
		memcheck(result->text, "text");
		strcpy(result->text, word);
		word = NULL;
		}
	else if (isbrivla(word)) {
		result->type = BRIVLA_509;
		result->text = newstring(strlen(word) + 1);
		memcheck(result->text, "text");
		strcpy(result->text, word);
		word = NULL;
		}
	else {
		for (p = word + 1; *p; p++)
			if (isC(*p)) break;
		result->text = newstring(p - word + 1);
		memcheck(result->text, "text");
		strncpy(result->text, word, p - word);
		result->text[p-word] = 0;
		word = p;
		}
	if (D_valsi) {
		printf("valsi: ");
		print(result);
		}
	return result;
	}
示例#5
0
文件: Reader.hpp 项目: questor/git-ws
					inline Str readStr()
					{
						// Skip opening '"'
						++idx;

						// Find end index of the string
						auto end(idx);
						auto sz(0u);
						for(; true; ++end, ++sz)
						{
							// End of the string
							if(getC(end) == '"') break;

							// Skip non-escape sequences
							if(getC(end) != '\\') continue;

							// Skip escape sequences
							++end;
							SSVU_ASSERT(isValidEscapeSequenceChar(getC(end)));
						}

						// Reserve memory for the string (BOTTLENECK)
						Str result;
						result.reserve(sz);

						for(; idx < end; ++idx)
						{
							// Not an escape sequence
							if(!isC('\\')) { result += getC(); continue; }

							// Escape sequence: skip '\'
							++idx;

							// Convert escape sequence
							result += getEscapeSequence(getC());
						}

						// Skip closing '"'
						++idx;

						return result;
					}