• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Token_stream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Token_stream的典型用法代码示例。如果您正苦于以下问题:C++ Token_stream类的具体用法?C++ Token_stream怎么用?C++ Token_stream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Token_stream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1:

// Put the next token into the token stream. Returns
// true if scanning succeeded.
inline bool
Lexer::scan(Token_stream& ts)
{
  if (Token tok = scan()) {
    ts.put(tok);
    return true;
  }
  return false;
}
开发者ID:quantum0813,项目名称:beaker,代码行数:11,代码来源:lexer.hpp


示例2: calculate

void calculate(Token_stream& ts)
{
	const string prompt = "> ";
	const string result = "= ";
	while (cin) {
		try {
			cout << prompt;
			Token t = ts.get();
			while (t.kind == print) t = ts.get();
			if (t.kind == quit) return;
			ts.putback(t);
			cout << result << statement(ts) << endl;
		}
		catch (exception& e) {
			cerr << e.what() << endl;
			clean_up_mess(ts);
		}
	}
}
开发者ID:JayDz,项目名称:PPP-answers,代码行数:19,代码来源:8-1.cpp


示例3: statement

double statement()
{
    Token t = ts.get();
    switch(t.kind) {
        case sqrt_kind:
            return func(sqrt_kind);
        case power_kind:
            return func(power_kind);
        case let:
            return declaration();
        case name:
            return assign(t.name);
        default:
            ts.unget(t);
            return expression();
    }
}
开发者ID:Tigrolik,项目名称:git_workspace,代码行数:17,代码来源:calculator08buggy.cpp


示例4: primary

// deal with numbers and parentheses
double primary()
{
    Token t = ts.get();
    switch (t.kind) {
    case '(': case '{':    // handle '(' expression ')'
        {    
            double d = expression();
            t = ts.get();
            if (t.kind != ')' && t.kind !='}') error("')' or '}' expected");
            return d;
        }
    case '8':            // we use '8' to represent a number
        return t.value;  // return the number's value
    default:
        error("primary expected");
    }
}
开发者ID:thelastpolaris,项目名称:Programming-Principles-and-Practice-Using-C-,代码行数:18,代码来源:ex2-3.cpp


示例5: declaration

double declaration()
{
	Token t = ts.get();
	if (t.kind != VAR) {
		ts.end();
		error ("Valid name expected in declaration");
	}
	string name = t.name;
	Token t2 = ts.get();
	if (t2.kind != '=') {
		ts.end();
		error("'=' missing in declaration of " ,name);
	}
	double d = expression();
	variables.set_value(name, d);
	return d;
}
开发者ID:dreamaddict,项目名称:Stroustrup-book-exercises,代码行数:17,代码来源:ch7calcexercises1-9.cpp


示例6: prim

double prim(bool get) {
	if (get) ts.get();
	switch (ts.current().kind) {
	case Kind::number:
	{
						 double v = ts.current().number_value;
						 ts.get();
						 return v;
	}
	case Kind::name:
	{
					   double &v = table[ts.current().string_value];
					   if (ts.get().kind == Kind::assign) v = expr(true);
					   return v;
	}
	case Kind::minus:
	{
						return -prim(true);
	}
	case Kind::lp:
	{
					 auto e = expr(true);
					 if (ts.current().kind != Kind::rp)
						 return error("'(' expected");
	}
	default:
		return error("primary expected");
	}
}
开发者ID:jkunlin,项目名称:dest_calculator,代码行数:29,代码来源:Calculator.cpp


示例7: calculate

//------------------------------------------------------------------------------
void calculate()
{	
	double val = 0;
	
	while (cin) 
	try {
		cout << prompt;
		Token t = ts.get();
		while (t.kind == print) t=ts.get(); // first discard all “prints”
		if (t.kind == quit) return;
		ts.putback(t);
		cout << result << statement() << '\n';
	}
	catch (exception& e) {
		cerr << e.what() << '\n'; // write error message
		clean_up_mess();
	}
}
开发者ID:AlexNazarov88,项目名称:My-study-materials,代码行数:19,代码来源:Calculator_6.7(v2).cpp


示例8: expression

double expression()
{  // deal we A+B and A-B
  double left = term();
  while(true) {
    Token t = ts.get(); // get the next Token from the stream
    switch(t.kind) {
    case '+':
      left += term();
      break;
    case '-':
      left -= term();
      break;
    default:
      ts.unget(t); // put the Token back onto the stream (we did not do any action here)
      return left;
    }
  }
}
开发者ID:tol60,项目名称:STROUSTRUP_C11,代码行数:18,代码来源:ch7.e.2.calculator08buggy_fixed.C


示例9: suffix

// check for a suffix after an expression (so far, only factorial) and evaluate.
double suffix(double expression)
{
	Token t=ts.get();
	switch(t.kind) {
		case '!':			// factorial (non-recursive algorithm)
		{
			int intexpr=(int)expression;
			if(intexpr<0) error("cannot take the factorial of a negative number");
			if(intexpr<2) return 1;
			int fact=intexpr;
			for(int i=intexpr;i>1;fact*=--i);		// FORE
			return fact;
		}
		default:
			ts.putback(t);
			return expression;
	}
}
开发者ID:dreamaddict,项目名称:Stroustrup-book-exercises,代码行数:19,代码来源:ch6-ex3.cpp


示例10: calculate

void calculate()
{
    while(cin) {
        try {
            cout << prompt;
            Token t = ts.get();
            while (t.kind == print)
                t = ts.get();
            if (t.kind == quit)
                return;
            ts.unget(t);
            cout << result << statement() << endl;
        } catch(exception &e) {
            cerr << e.what() << endl;
            clean_up_mess();
        }
    }
}
开发者ID:Tigrolik,项目名称:git_workspace,代码行数:18,代码来源:calculator08buggy.cpp


示例11: pow

double pow(){ // Multiplies n by n m times
	Token t = ts.get();
	if (t.kind == '(') {
		double lval = expression();
		int rval = 0;
		t = ts.get();
		if(t.kind == ',') rval = narrow_cast<int>(primary());
		else error("Second argument is not provided");
		double result = 1;
		for(double i = 0; i < rval; i++) {
			result*=lval;
		}
		t = ts.get();
		if (t.kind != ')') error("')' expected"); // If there wasn't any ')' return an error
			return result;
	}
	else error("'(' expected"); // If there wasn't any ')' return an error	
}
开发者ID:thelastpolaris,项目名称:Programming-Principles-and-Practice-Using-C-,代码行数:18,代码来源:ex10.cpp


示例12: expression

double expression() // Performs '+' and '-' operations
{
	double left = term(); // Get the number or the result of calculations in term
	while(true) {
		Token t = ts.get();
		switch(t.kind) {
		case '+':
			left += term(); // Addition
			break;
		case '-':
			left -= term(); // Subtraction
			break;
		default:
			ts.unget(t); // If nothing was done return character to the stream
			return left; // Return the new or unchanged value of 'left'
		}
	}
}
开发者ID:thelastpolaris,项目名称:Programming-Principles-and-Practice-Using-C-,代码行数:18,代码来源:ex10.cpp


示例13: expression

double expression()
{
	double left = term();
	while(true) {
		Token t = ts.get();
		switch(t.kind) {
			case '+':
				left += term();
				break;
			case '-':
				left -= term();
				break;
			default:
				ts.unget(t);
				return left;
		}
	}
}
开发者ID:k-mi,项目名称:Stroustrup_PPP,代码行数:18,代码来源:drill7_11.cpp


示例14: 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;
}
开发者ID:JayDz,项目名称:PPP-answers,代码行数:18,代码来源:7-4.cpp


示例15: primary1

// deal with numbers and parentheses
double primary1()
{
    Token t = ts.get();
    switch (t.kind) {
    case '(':    // handle '(' expression ')'
        {
            double d = expression();
            t = ts.get();
            if (t.kind != ')')
                error("')' expected");
            else    {
                t = ts.get();
                if (t.kind == '!')
                    d = factorial(d);
                else
                    ts.putback(t);
                }
            return d;
        }
    case '{':    // handle '(' expression ')'
        {
            double d = expression();
            t = ts.get();
            if (t.kind != '}')
                error("'}' expected");
            else {    
                t = ts.get();
                if (t.kind == '!')
                    d = factorial(d);
                else
                    ts.putback(t);
                }
            return d;
        }
    case '8':            // we use '8' to represent a number
        {
            double d = t.value;
            t = ts.get();
            if (t.kind == '!')
                d = factorial(d);
            else
                ts.putback(t);
            return d;  // return the number's value
        }
    default:
        error("primary expexted");
    }
    
}
开发者ID:konstest,项目名称:cpp_learning,代码行数:50,代码来源:code.cpp


示例16: define_name

double Symbol_table::define_name(char type) // Defines a variable
{
	Token t = ts.get(); // Get a character from the stream
	if (t.kind != 'a') error ("name expected in declaration"); // If there is no name return an error
	string name = t.name; // Read the name in 'name'
	if (is_declared(name)) error(name, " declared twice"); // Check if the variable had been already declared
	Token t2 = ts.get(); // Get a character from the stream
	if (t2.kind != '=') error("= missing in definition of " ,name); /* If there is no '=' symbol used to assign a value
																		to the variable return an error */
	double d = expression(); // Process the provided value
	switch(type) {
	case let:
		names.push_back(Variable(name,d)); // Add new variable to a vector
		return d; // Return the value of new variable
	case constant:
		names.push_back(Variable(name,d,constant)); // Add new constant to a vector
		return d; // Return the value of new constant
	}
}
开发者ID:thelastpolaris,项目名称:Programming-Principles-and-Practice-Using-C-,代码行数:19,代码来源:ex10.cpp


示例17: primary

double primary() {
    Token t = ts.get();
    switch(t.kind) {
    case '(':				// '(' Expression ')'を処理する
    {
        double d = expression();
        t = ts.get();
        if(t.kind != ')') error("')' expected");
        return d;
    }
    case '8':				// '8'を使って数字を表す
        return t.value;		// 数字の値を返す
    case 'q':				// 追加
        keep_window_open("~0");
        exit(EXIT_SUCCESS);
    default:
        error("primary expected");
    }
}
开发者ID:k-mi,项目名称:Stroustrup_PPP,代码行数:19,代码来源:6_8_1+.cpp


示例18: assign

double assign(string var_name) {
	const Token t {ts.get()};
	if (t.kind != '=')
        error("= missing in the assignment of " + var_name);

	double d {expression()};
    set_value(var_name, d);

	return d;
}
开发者ID:Tigrolik,项目名称:git_workspace,代码行数:10,代码来源:calculator08buggy.cpp


示例19: primary

double primary()
{
	Token t = ts.get();
	switch (t.kind) {
	case '(':
		{	double d = expression();
		t = ts.get();
		if (t.kind != ')') error("'(' expected");
			}
	case '-':
		return -primary();
	case number:
		return t.value;
	case name:
		return get_value(t.name);
	default:
		error("primary expected");
	}
}
开发者ID:kordax,项目名称:Stroustrup,代码行数:19,代码来源:CalculatorWin2.cpp


示例20: primary

// deal with numbers and parentheses
double primary()
{
    Token t = ts.get();
    switch (t.kind) {
    case '(':    // handle '(' expression ')'
        {    
            double d = expression();
            t = ts.get();
            if (t.kind != ')') error("')' expected");
            return d;
        }
	case '-':  // so can use negative numbers
		return -primary();
    case '8':            // we use '8' to represent a number
        return t.value;  // return the number's value
    default:
        error("primary expected");
		return 0; //compile warning without wont get here
    }
}
开发者ID:Jtaim,项目名称:Programming-Principles-and-Practice-Using-Cpp,代码行数:21,代码来源:sect6_drill1.cpp



注:本文中的Token_stream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Tokeniser类代码示例发布时间:2022-05-31
下一篇:
C++ TokenT类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap