Beispiel #1
0
void Eliza::preProcessResponse() {
	if(is_template(m_sResponse)) {
		findSymbol(m_sResponse);
		if(m_sKeyWord == m_sInput) {
			m_sSuffix = m_sInput;
		} else if(!m_bMemoryRecall){
			extract_suffix();
		} else {
			m_bMemoryRecall = 0;
		}
		if(m_sSuffix.length() == 0) {
			while(is_template(m_sResponse) && response_list.size() > 1) {
				response_list.erase(response_list.begin());
				m_sResponse = response_list[0];
			}
			if(is_template(m_sResponse)) {
				response_list = topicChanger;
				select_response();
			}
		}
		if(m_sSuffix.length() > 0 && m_sSymbol != "%") {
			transpose_sentence(m_sSuffix);
			correct_sentence(m_sSuffix);
			trimRight(m_sSuffix, ' ');
			m_sSuffix.insert(0, " ");
		}
		replace(m_sResponse, m_sSymbol, m_sSuffix);
	}
	if(m_sUserName != "USER") {
		replace(m_sResponse, "USER", m_sUserName);
	}
}
Beispiel #2
0
void cpp_declarationt::output(std::ostream &out) const
{
  out << "is_template: " << is_template() << "\n";
  out << "storage: " << storage_spec().pretty() << "\n";
  out << "template_type: " << template_type().pretty() << "\n";
  out << "type: " << type().pretty() << "\n";

  out << "Declarators:" << "\n";

  for(const auto &it : declarators())
  {
    it.output(out);
    out << "\n";
  }
}
Beispiel #3
0
// handle the context of the conversation
// (the previous replies of the chatterbot)
void Eliza::verify_context(vstring vContext) { 

	m_bGoodContext = 0;
	
	size_t nNum = vContext.size();

	if(nNum == 0) {
		m_bGoodContext = 1;
		return;
	}
	
	for(int i = 0; i < nNum; ++i) {
		if(is_template(vContext[i])) {
			findSymbol(vContext[i]);
			replace(vContext[i], m_sSymbol, m_sSuffix);
		}

		if(m_sPrevResponse == vContext[i]) {
			m_bGoodContext = 1;
			break;
		}
	}
}
Beispiel #4
0
const char *ident(const char *text, CLanguageProxy& proxy, char *&scope)
{
	const char *start = text, *id = start;
	char nameBuf[kMaxNameSize], *name = nameBuf;
	int size = 0, offset = start - proxy.Text();
	bool destructor = false;
	
	while (isident(*text))
		name_append(text, name, size);
	
	*name = 0;

	text = comment(text);
	
	if (strcmp(nameBuf, "extern") == 0)
		return i_extern(text);
	else if (strcmp(nameBuf, "header") == 0) {
		// first add "header"
		while (!isspace(*text)) {
			name_append(text, name, size);
		}
		// then a space
		*name++ = ' ';
		// skip past the double quote
		text = skip(text, '"');
		// save the identifier location
		start = text;
		// put in the identifier [up to next quote]
		while (*text != '"')
			name_append(text, name, size);
		// terminate
		*name = 0;
		// add it
		char match[256];
		long l = std::min((long)255, text - start);
		
		strncpy(match, start, l);
		match[l] = 0;
		
		if (proxy.Types())
			proxy.AddFunction(nameBuf, match, offset, false);

		// walk past the double quote
		text++;
		// eat the code
		text = parens(text + 1, '{');
		return text;
	}
	else if (strcmp(nameBuf, "options") == 0) {
		// first add the scope label
		for (char * c = scope ; (size < kMaxNameSize) ; size++) {
			if (*c == '\0') break;
			*name++ = *c++;
		}
		// then a space
		*name++ = ' ';
		// save the "options" location
		start = text;		
		// then add "options"
		while (!isspace(*text)) {
			name_append(text, name, size);
		}
		// terminate
		*name = 0;
		// add it
		char match[256];
		long l = std::min((long)255, text - start);
		
		strncpy(match, start, l);
		match[l] = 0;
		
		if (proxy.Types())
			proxy.AddFunction(nameBuf, match, offset, false);

		// walk past the double quote
		text++;
		// eat the code
		text = parens(text + 1, '{');
		return text;
	}
	else if (strcmp(nameBuf, "class") == 0 ||
			 strcmp(nameBuf, "struct") == 0 ||
			 strcmp(nameBuf, "union") == 0)
	{
		*name++ = ' ';
		
		if (isidentf(*text))
		{
			while (isident(*text))
				name_append(text, name, size);
			*name = 0;
			
			text = comment(text);
			
			if (*text == ':')
			{
				text = comment(text + 1);
				
				while (isident(*text))
					text++;
				
				text = comment(text);
				
				while (isident(*text))
					text++;
				
				text = comment(text);
			}
			
			if (*text == '{' && proxy.Types())
			{
				char match[256];
				long l = std::min((long)255, text - start);
				
				strncpy(match, start, l);
				match[l] = 0;
		
				proxy.AddFunction(nameBuf, match, offset, false);
			}
		}
		
		if (*text == '{')
			text = parens(text + 1, '{');
		
		text = comment(text);
		
		while (isidentf(*text))
		{
			char match[kMaxNameSize];
			
			name = strchr(nameBuf, ' ') + 1;
			
			strncpy(match, nameBuf, name - nameBuf - 1);
			match[name - nameBuf - 1] = 0;

			while (isident(*text))
				name_append(text, name, size);

			*name = 0;
			
			if (proxy.Types())
				proxy.AddFunction(nameBuf, match, offset, false);
			
			text = comment(text);
			while (*text == ',' || *text == '*')
				text = comment(text + 1);
		}
		
		return text;
	}
	
	if (is_template(text))
	{
		name_append(text, name, size);
		
		text = comment(text);
		
		while (isident(*text))
		{
			while (isident(*text))
				name_append(text, name, size);
		
			text = comment(text);
			
			if (*text == ',')
			{
				name_append(text, name, size);
				text = comment(text);
			}
		}

		if (*text == '>')
		{
			name_append(text, name, size);
			
			text = comment(text);
		}
	}
	
	while (*text == ':' && text[1] == ':')
	{
		name_append(text, name, size);
		name_append(text, name, size);
		
		text = comment(text);
		
		id = name;
		
		if (*text == '~')
		{
			name_append(text, name, size);
			text = comment(text);
			destructor = true;
		}
		
		if (isidentf(*text))
			while (isident(*text))
				name_append(text, name, size);
		
		text = comment(text);
		
		if (is_template(text))
		{
			name_append(text, name, size);
			text = comment(text);
			
			while (isident(*text))
			{
				while (isident(*text))
					name_append(text, name, size);
				
				text = comment(text);
				
				if (*text == ',')
				{
					name_append(text, name, size);
					text = comment(text);
				}
			}
			
			if (*text == '>')
			{
				name_append(text, name, size);
				text = comment(text);
			}
		}
	}
	
	if (!destructor && strcmp(id, "operator") == 0)
	{
		if (*text == '(')
			name_append(text, name, size);
		
		text = comment(text);
		
		while (*text != '(' && size < kMaxNameSize)
		{
			if (isidentf(*text))
			{
				while (isident(*text))
					name_append(text, name, size);
			}
			else if (! isspace(*text))
			{
				while (! isspace(*text) && ! isidentf(*text) && *text != '(' &&
							! (*text == '/' && (text[1] == '*' || text[1] == '/')))
					name_append(text, name, size);
			}

			text = comment(text);
		}
	}
	
	*name = 0;
	
	if (*text == '(')
	{
		char match[256];
		long l = std::min((long)255, text - start);
		
		strncpy(match, start, l);
		match[l] = 0;
		
		text = parens(text + 1, '(');
		text = comment(text);
		
		if (*text == ':')
		{
			while (*text != '{' && *text != ';')
				text++;
			if (*text == '{')
			{
				text = parens(text + 1, '{');
				proxy.AddFunction(nameBuf, match, offset, false);
			}
			else
			{
				text++;
				if (proxy.Prototypes())
					proxy.AddFunction(nameBuf, match, offset, true);
			}
			if (*text == '\n')
				text++;
			return text;
		}
		
		if (*text == ';')
		{
			if (proxy.Prototypes())
				proxy.AddFunction(nameBuf, match, offset, true);
			return text + 1;
		}
		
		if (isidentf(*text) || *text == '{')
		{
			proxy.AddFunction(nameBuf, match, offset, false);
			text = skip_ne(text, '{');
			text = parens(text, '{');
			if (*text == '\n')
				text ++;
			return text;
		}
	}
	
	return text;
} /* ident */