本文整理汇总了C++中Symbol_table::declare方法的典型用法代码示例。如果您正苦于以下问题:C++ Symbol_table::declare方法的具体用法?C++ Symbol_table::declare怎么用?C++ Symbol_table::declare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symbol_table
的用法示例。
在下文中一共展示了Symbol_table::declare方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: declaration
double declaration(bool is_const)
//Handle 'name = expression'
//Declare a variable called "name" with initial value "expresion"
{
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();
switch (is_const) {
case true:
symtable.declare(var_name, d, true);
break;
default:
if (symtable.is_declared(var_name))
symtable.set(var_name, d);
else
symtable.declare(var_name, d, false);
}
return d;
}
示例2: main
int main()
{
try {
sym_table.declare("pi", 3.1415926535, false);
sym_table.declare("e", 2.7182818284, false);
calculate();
return 0;
}
catch(exception& e) {
cerr << e.what() << endl;
return 1;
}
catch(...) {
cerr << "exception\n";
return 2;
}
return 0;
}
示例3: main
int main()
{
try
{
//Predefined names
symtable.declare("pi", 3.1415926535, true);
symtable.declare("e", 2.7182818284, true);
calculate();
return 0;
}
catch (exception& e) {
cerr << "error: " << e.what() << '\n';
char c;
while (cin >> c && c != ';') ;
return 1;
}
catch (...) {
cerr << "unknown exception!\n";
char c;
while (cin >> c && c != ';') ;
return 2;
}
}
示例4: declaration
double declaration(Token k)
// Taken from: http://www.stroustrup.com/Programming/Solutions/Ch7/e7-1.cpp
// handle: name = expression
// declare a variable called "name" with the initial value "expression"
// k will be "let" or "con"(stant)
{
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();
sym_table.declare(var_name,d,k.kind==let);
return d;
}