Ejemplo n.º 1
0
static void Calculate(GtkWidget *Widget, gpointer EvalWindow)
{
	SilikoSyntaxTreeNode *ResultTree =
		SilikoParseInfix(
		SilikoStringSourceNew(
		gtk_entry_get_text(
		GTK_ENTRY(
		gtk_builder_get_object(GTK_BUILDER(EvalWindow), "Input")))));
	SilikoValue Value = SilikoSyntaxTreeEvaluate(ResultTree);
	SilikoSyntaxTreeDelete(ResultTree);

	char *ResultString = SilikoValueToString(Value);
	gtk_label_set_text(
		GTK_LABEL(
			gtk_builder_get_object(
			GTK_BUILDER(EvalWindow), "Output")),
		ResultString);
	free(ResultString);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	SilikoValue value;
	SilikoSyntaxTreeNode *tree;
	const char *prompt;
	const char *response;

	if (ISATTY())
	{
		prompt = "> ";
		response = "= ";
	}
	else
	{
		prompt = "";
		response = "";
	}

	SilikoFunctionCallerSetUp();

	char *expression = NULL;
	char *old_expression = NULL;

	while(-1)
	{
		expression = readline(prompt);

		if(!expression)
		{
			free(old_expression);
			old_expression = NULL;
			break;
		}

		if(*expression && (!old_expression || strcmp(expression, old_expression) != 0))
			add_history(expression);

		free(old_expression);
		old_expression = NULL;

		tree = SilikoParseInfix(
			SilikoStringSourceNew(expression));
		value = SilikoSyntaxTreeEvaluate(tree);
		SilikoSyntaxTreeDelete(tree);

		char *ResultString = SilikoValueToString(value);
		printf("%s\n", ResultString);
		free(ResultString);

		old_expression = expression;
	}

	SilikoFunctionCallerTearDown();

	if (ISATTY())
	{
		fputc('\n', stdout);
		fflush(stdout);
	}
	return 0;
}