示例#1
0
文件: struct.c 项目: Gwaltrip/CLP
/* install a symbol in (yet unnamed) struct. This just hijacks the install_symbol function
   pointing to our dummy struct table.
 */ 
node* install_struct_symbol(node* n) {
	vlog("[struct] installing symbol(s)\n");
	if (struct_temp == NULL)
		struct_temp = new_symbol_table(NULL);
	
	return install_symbol(struct_temp, n);
}
示例#2
0
文件: symbol_table.c 项目: 8l/eight
symbol_table *closing_to_table(closure *a)
{
    symbol_table *ret = new_symbol_table();
    while(!nilp(a)){
	if(nilp(table_lookup(cheap_car(cheap_car(a)), ret))){
	    table_insert(cheap_car(cheap_car(a)), 
			 second(cheap_car(a)),
			 ret);
	}
	a = cheap_cdr(a);
    }
    return ret;
}
示例#3
0
文件: plpcc-jni.c 项目: Gwaltrip/CLP
JNIEXPORT jstring JNICALL Java_plptool_interfaces_PLPCC_nativeCompile
	(JNIEnv *env, jobject jobj, jint log_level, jstring input) {
	printf("PLPCC JNI: nativeCompile called.\n");
	jboolean iscopy;
	const char *str = (*env)->GetStringUTFChars(env, input, &iscopy);
	printf("%s\n", str);

	LOG_LEVEL = log_level;
	build_jni_lines(str);

	/* create an empty symbol table */
	sym = new_symbol_table(NULL);

	yy_scan_string(str);
	yyparse();
	handle(parse_tree_head);

	return (*env)->NewStringUTF(env, program);
}
示例#4
0
文件: symbol_table.c 项目: 8l/eight
symbol_table *table_union(symbol_table *a, symbol_table *b)
{
    symbol_table *ret = new_symbol_table();
    closure *item;
    int i;
    closure *chain;			            
    start_table_iteration(b, item, i){
	if (!leakedp(cheap_cdr(item)) ||
	    nilp(table_lookup(cheap_car(item), ret)))
	    table_insert(cheap_car(item), second(item), ret);
    } end_table_iteration;

    start_table_iteration(a, item, i){
	if (!leakedp(cheap_cdr(item)) ||
	    nilp(table_lookup(cheap_car(item), ret)))
	table_insert(cheap_car(item), second(item), ret);
    } end_table_iteration;
    
    return ret;
}
示例#5
0
文件: main.c 项目: Gwaltrip/CLP
int main(int argc, char *argv[]) {

	/* process arguments */
	handle_opts(argc, argv);	

	/* open files */
	vlog("[plpcc] opening files\n");
	FILE_INPUT = fopen(S_FILE_INPUT,"r");
	if (FILE_INPUT == NULL) {
		err("[plpcc] cannot open input file: %s\n", S_FILE_INPUT);
	}
	FILE_OUTPUT = fopen(S_FILE_OUTPUT,"w");
	if (FILE_OUTPUT == NULL) {
		err("[plpcc] cannot open output file: %s\n", S_FILE_OUTPUT);
	}
	yyset_in(FILE_INPUT);

	if (S_SYMBOL_OUTPUT != NULL) {
		SYMBOL_OUTPUT = fopen(S_SYMBOL_OUTPUT, "w");
		if (SYMBOL_OUTPUT == NULL) {
			err("[plpcc] cannot open symbol table output file: %s\n", S_SYMBOL_OUTPUT);
		}
	}

	if (S_PARSE_OUTPUT != NULL) {
		PARSE_OUTPUT = fopen(S_PARSE_OUTPUT, "w");
		if (PARSE_OUTPUT == NULL) {
			err("[plpcc] cannot open parse tree output file: %s\n", S_PARSE_OUTPUT);
		}
	}
	
	if (S_GRAPH_OUTPUT != NULL) {
		GRAPH_OUTPUT = fopen(S_GRAPH_OUTPUT, "w");
		if (GRAPH_OUTPUT == NULL) {
			err("[plpcc] cannot open parse tree graph output file: %s\n", S_GRAPH_OUTPUT);
		}
	}

	/* grab the lines from the source for error handling and annotation */
	build_lines(S_FILE_INPUT);

	/* create an empty symbol table */
	sym = new_symbol_table(NULL);

	log("[plpcc] starting frontend\n");
	yyparse();

	/* print the parse tree */
	if (PARSE_OUTPUT != NULL) {
		vlog("[plpcc] printing parse tree\n");
		print_tree(parse_tree_head, PARSE_OUTPUT, 0);
	}

	/* print the parse tree graph formatted for Graphviz*/
	if (GRAPH_OUTPUT != NULL) {
		vlog("[plpcc] printing parse tree graph\n");
		print_tree_graph(parse_tree_head, GRAPH_OUTPUT, S_FILE_INPUT);
		
		/* close output file*/
		fclose(GRAPH_OUTPUT);
		
		/* Run Graphviz command to generate PNG of parse tree */
		S_GRAPH_COMMAND = malloc(sizeof(char) * (strlen(S_FILE_OUTPUT) * 2 + 22));
		sprintf(S_GRAPH_COMMAND, "dot -Tpng %s.dot > %s.png", S_FILE_OUTPUT, S_FILE_OUTPUT);
		system(S_GRAPH_COMMAND);
	}
	
	/* print the symbol table */
	if (SYMBOL_OUTPUT != NULL) {
		vlog("[plpcc] printing symbol table\n");
		print_symbols(sym, SYMBOL_OUTPUT, 0);
		vlog("[plpcc] printing activation records\n");
		print_frames(sym, SYMBOL_OUTPUT);
	}

	/* call the backend to compile the parse tree, starting from the head */
	if (NO_COMPILE == 0) {
		handle(parse_tree_head);
		fprintf(FILE_OUTPUT, "%s", program);
	}

	vlog("[plpcc] closing files\n");
	fclose(FILE_INPUT);
	fclose(FILE_OUTPUT);

	log("[plpcc] done\n");
	return 0;
}