本文整理汇总了C++中Symbol_table::get方法的典型用法代码示例。如果您正苦于以下问题:C++ Symbol_table::get方法的具体用法?C++ Symbol_table::get怎么用?C++ Symbol_table::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symbol_table
的用法示例。
在下文中一共展示了Symbol_table::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: primary
double primary()
{
Token t = ts.get();
switch (t.kind) {
case '(':
{
double d = expression();
t = ts.get();
if (t.kind != ')') error("expected ')'");
return d;
}
case '{':
{
double d = expression();
t = ts.get();
if (t.kind != '}') error("expected '}'");
return d;
}
case number:
return t.value;
case '-':
return - primary();
case '+':
return primary();
case name:
{
Token next = ts.get();
if (next.kind == '=') {
double d = expression();
sym_table.set(t.name,d);
return d;
}
else {
ts.putback(next);
return sym_table.get(t.name);
}
}
default:
error("primary expected");
}
}
示例2: primary
double primary()
// deal with numbers, square roots, exponents, parentheses, and brackets
{
Token t = ts.get();
switch (t.kind) {
case root:
{
t = ts.get();
if (t.kind != '(')
error("'(' expected");
double d = expression();
if (d < 0)
error ("negative argument for sqrt()");
t = ts.get();
if (t.kind != ')')
error ("')' expected");
return sqrt(d);
}
case exponent:
{
t = ts.get();
if (t.kind != '(')
error("'(' expected");
double d = expression();
t = ts.get();
if (t.kind != ',')
error("expected two arguments for pow()");
int exp = narrow_cast<int>(expression());
t = ts.get();
if (t.kind != ')')
error("')'expected");
return power(d, exp);
}
case '{': // handle '{' expression '}'
{
double d = expression();
t = ts.get();
if (t.kind != '}')
error("'}' expected");
return d;
}
case '(': // handle '(' expression ')'
{
double d = expression();
t = ts.get();
if (t.kind != ')')
error("')' expected");
return d;
}
case number: // we use '8' to represent a number
return t.value; // return the number's value
case name:
return symtable.get(t.name);
case '-':
return -primary();
case '+':
return primary();
default:
error("primary expected");
}
}
示例3: Token
Token
Lexer::on_symbol()
{
Symbol const* sym = symbols.get(str_.take());
return Token(loc_, sym);
}