Beispiel #1
0
int main()
try
{
    //defining some variables:
    define_name("pi", 3.1415926535);
    define_name("e", 2.7182818284);

    calculate();

    keep_window_open(); //for windows consoles
    return 0;
}

catch(exception& e)
{
    cerr<< e.what() << endl;
    keep_window_open("~");

    /* the above line is the same as:
    cout << "Please enter ~ to close the program";
    char ch;
    while (cin>>ch)
        if (ch == '~') return 1;
    */

    return 1;
}

catch(...)
{
    cerr << "exception \n";
    keep_window_open("~");
    return 2;
}
//-------------------------------------------------------------------------------
int main()
try
{
	define_name("pi",3.1415926535);
	define_name("e",2.7182818284);	
	
	cout << "Welcome to our simple calculator.\n"
			"Please enter expressions using floating-point numbers.\n";
			
    calculate();
    
	keep_window_open();
	return 0;
}
catch (runtime_error& e) {
	cerr << e.what() << '\n';
	keep_window_open("~~");
	return 1;
}

catch (...) {
    cerr << "Oops: unknown exception!\n"; 
	keep_window_open("~~");
    return 2;
}
Beispiel #3
0
int main()
{
  try {
    define_name("pi", 3.1415926535);
    define_name("e", 2.7182818284);
    
    calculate();
    return 0;
  } catch (exception& e) {
    cerr << e.what() << endl;
    // keep_window_open("~~");
    return 1;
  } catch (...) {
    cerr << "exception \n";
    // keep_window_open("~~");
    return 2;
  }
}
int main()
try {
    // predefine names:
    define_name("pi",3.1415926535);
    define_name("e",2.7182818284);

    calculate();

    return 0;
}
catch (exception& e) {
    cerr << e.what() << endl;
    return 1;
}
catch (...) {
    cerr << "exception \n";
    return 2;
}
Beispiel #5
0
int main()
{
	try {

		define_name("pi", 3.1415926535);
		define_name("e", 2.7182818284);
		Token_stream ts;
		calculate(ts);
		return 0;
	}
	catch(exception& e) {
		cerr << e.what() << endl;
		return 1;
	}
	catch(...) {
		cerr << "exception\n";
		return 2;
	}
	return 0;
}
Beispiel #6
0
int main()
try {
    // predefine names:
    define_name("pi",3.1415926535,false);	// these pre-defiend names are constants
    define_name("e",2.7182818284,false);

    calculate();

    keep_window_open();    // cope with Windows console mode
    return 0;
}
catch (exception& e) {
    cerr << e.what() << endl;
    keep_window_open("~~");
    return 1;
}
catch (...) {
    cerr << "exception \n";
    keep_window_open("~~");
    return 2;
}
Beispiel #7
0
// "let"が検出されている前提とする
// name = expression を処理する
// "name"という名前の変数を初期値"expression"で宣言する
double declaration(){
	Token t = ts.get();
	if(t.kind != name) error("name expected in declaration");
	string var_name = t.name;

	Token t2 = ts.get();
	if(t2.kind != '=') error("= missing in declaration of ", var_name);

	double d = expression();
	define_name(var_name, d);
	return d;
}
Beispiel #8
0
double declaration()
{
  Token t = ts.get();
  if(t.kind != NAME)
    error("declaration: expecting variable name.");
  string var = t.name;    // TODO: add name field in token
  t = ts.get();
  if(t.kind != '=')
    error("declaration: expecting = symbol");
  double d = expression();
  return define_name(var, d);
}
double declaration()
    // handle: name = expression
    // declare a variable called "name" with the initial value "expression"
{
    Token t = ts.get();
    if (t.kind != name) error ("name expected in declaration");
    string var_name = t.name;

    Token t2 = ts.get();
    if (t2.kind != '=') error("= missing in declaration of ", var_name);

    double d = expression();
    define_name(var_name,d);
    return d;
}
Beispiel #10
0
//======================================================================
int main(){
try {
cout<<"This is a calulator!\n"
<<"+, -, *, /, !, %(remainder), ^ (to the power) are supported. You can use brackets () and {}.\n" 
<<"You can use let to define new variables. [let 'name' = 'value']\n"
<<"pi and e are pre defined\n "
<<"Use '; and enter' to terminate an input expression and 'q' to quit.\n\n"
<<"---------------------------------------------------------------------\n";

define_name("pi",3.1415926535);//define pi
define_name("e",2.7182818284);//define e

calculate();
}

catch(exception& e){
	cerr<<e.what()<<'\n';
	return 1;
}
catch(...){
	cerr<<"Exception \n";
	return 2;
}
}
Beispiel #11
0
double declaration()
// assume user input let (as checked by statement()
// check the input follows the format name = expression
//declare a variable to be added to variablesTable with that name and value "expression"
{
    Token t = tokenStream.get();
    if (t.kind != name) error("name expected in variable declaration");
    string var_name = t.name;

    Token t2 = tokenStream.get();
    if (t2.kind != '=') error("missing an = in the variable declaration of ", var_name);

    double d = expression();
    define_name(var_name,d);
    return d;
}
void xm_from()
{
unsigned long data_size, rsrc_size;
char text[64];

    if(receive_sync() == ACK) {
	receive_part(info, DATABYTES, 1);
	transname(info + I_NAMEOFF + 1, text, info[I_NAMEOFF]);
	define_name(text);
	data_size = get4(info + I_DLENOFF);
	rsrc_size = get4(info + I_RLENOFF);
	start_info(info, rsrc_size, data_size);
	start_data();
	receive_part(out_buffer, data_size, 1);
	start_rsrc();
	receive_part(out_buffer, rsrc_size, 0);
	end_file();
    }
}
Beispiel #13
0
static void
test_insdel_rowcol_names (void)
{
	Workbook *wb;
	Sheet *sheet1,*sheet2;
	const char *test_name = "test_insdel_rowcol_names";
	GOUndo *undo;
	int i;

	mark_test_start (test_name);

	wb = workbook_new ();
	sheet1 = workbook_sheet_add (wb, -1,
				     GNM_DEFAULT_COLS, GNM_DEFAULT_ROWS);
	sheet2 = workbook_sheet_add (wb, -1,
				     GNM_DEFAULT_COLS, GNM_DEFAULT_ROWS);

	define_name ("Print_Area", "Sheet1!$A$1:$IV$65536", sheet1);
	define_name ("Print_Area", "Sheet2!$A$1:$IV$65536", sheet2);

	define_name ("NAMEGA1", "A1", wb);
	define_name ("NAMEG2", "$A$14+Sheet1!$A$14+Sheet2!$A$14", wb);

	define_name ("NAMEA1", "A1", sheet1);
	define_name ("NAMEA2", "A2", sheet1);
	define_name ("NAMEA1ABS", "$A$1", sheet1);
	define_name ("NAMEA2ABS", "$A$2", sheet1);

	dump_names (wb);

	for (i = 3; i >= 0; i--) {
		g_printerr ("About to insert before column %d on %s\n",
			    i, sheet1->name_unquoted);
		sheet_insert_cols (sheet1, i, 12, &undo, NULL);
		dump_names (wb);
		g_printerr ("Undoing.\n");
		go_undo_undo_with_data (undo, NULL);
		g_object_unref (undo);
		g_printerr ("Done.\n");
	}

	for (i = 3; i >= 0; i--) {
		g_printerr ("About to insert before column %d on %s\n",
			    i, sheet2->name_unquoted);
		sheet_insert_cols (sheet2, i, 12, &undo, NULL);
		dump_names (wb);
		g_printerr ("Undoing.\n");
		go_undo_undo_with_data (undo, NULL);
		g_object_unref (undo);
		g_printerr ("Done.\n");
	}

	for (i = 3; i >= 0; i--) {
		g_printerr ("About to delete column %d on %s\n",
			    i, sheet1->name_unquoted);
		sheet_delete_cols (sheet1, i, 1, &undo, NULL);
		dump_names (wb);
		g_printerr ("Undoing.\n");
		go_undo_undo_with_data (undo, NULL);
		g_object_unref (undo);
		g_printerr ("Done.\n");
	}

	g_object_unref (wb);

	mark_test_end (test_name);
}