示例#1
0
文件: csg.c 项目: hyphaltip/parsnp
void INS_EDGE(CSG *csg, CSG_Node *source, CSG_Node *target) 
{ 
	CSG_Node **bucket;

	if (*(LABEL(target)) == LAST_SYMBOL) 
		SET_FINAL(source); 
	else {
		if (OUT(source) == 0) {
			source->arc = (CSG_Node **)target;
		} else  {
			if (OUT(source) == 1) {
				bucket = (CSG_Node **)malloc(sizeof(CSG_Node *)
				* 2);
				bucket[0] = (CSG_Node *)source->arc;
				source->arc = bucket;
			} else if (OUT(source) == 2) {
				source->arc = (CSG_Node **)realloc(source->arc 
				, sizeof(CSG_Node *) * 5);
			} 
			source->arc[OUT(source)] = target; 
		}
		OUT(source)++; 
		LG(target) = MAX(LG(target), (IS_INITIAL(source) 
		? 0 :  LG(source) + LEN_L(source))); 
	}
}; 
/* Everything starts here. :) */
int main ()
{
	int c, set = 1;
	bool is_immediate_decodable = true;

	while ((c = getc(stdin)) > 0)
	{
		// End of a group.
		if (c == '9')
		{
			fprintf(stdout, output[is_immediate_decodable], set);
			NEW_GROUP();
			is_immediate_decodable = true;
			++set;
		}
		else if (is_immediate_decodable)
		{
			switch (c)
			{
				// End of a code.
				case '\n':
				case ' ':
				case '\t':
				{
					// Checking if is immediate decodable.
					if (PATH_CONTINUES()) {
						is_immediate_decodable = false;
						continue;
					}
					// This is a final node for a code.
					SET_FINAL();
					// A new group takes place.
					NEW_CODE();
					break;
				}

				// 0 or 1.
				default:
				{
					c -= '0';
					GO(c);
					if (IS_FINAL())
						is_immediate_decodable = false;
				}
			}
		}
	}

	return 0;
}