当前位置: 首页>>代码示例>>C++>>正文


C++ ExprNode::SetIndex方法代码示例

本文整理汇总了C++中ExprNode::SetIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ ExprNode::SetIndex方法的具体用法?C++ ExprNode::SetIndex怎么用?C++ ExprNode::SetIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ExprNode的用法示例。


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

示例1: if

ExprNode* Parser :: ParseFactor(){
    ExprNode *root = nullptr;
    Token *token = scan.Get();
    if(isEq(token, _SEPARATION, ";"))
        return 0;
    switch (token->Type){
        case _INTEGER:
            root = new IntNode(token);
            break;

        case _FLOAT:
            root = new FloatNode(token);
            break;

        case _IDENTIFIER:
        {
            Symbol *sym = symStack->find_symbol(token->Value);
            if(!sym && parsingFunc)
                sym = parsingFunc->params->find_symbol(token->Value);
            string exc = "Identifier \"" + token->Value + "\" not defined";
            errorIf(!sym, exc.c_str(), token);
            errorIf(!dynamic_cast<VarSymbol*>(sym) && !dynamic_cast<FuncSymbol*>(sym), "Unknown symbol", token);
            errorIf(!sym, "Identifier is undefined", token);
		
             root = new IdentifierNode(token, dynamic_cast<VarSymbol*>(sym));
			if (dynamic_cast<PointerSymbol*>(sym->getType()))
				root = new PointerNode(root);
			

            if(isEq(scan.GetNext() ,_SEPARATION ,"("))
                root = ParseFuncCall(root);
            
            //scan.Next();
            return root;
        }

        case _CHAR:
            root = new CharNode(token);
            break;

        case _STRING:

            root = new StringNode(token);
			root->SetIndex(++index);
            stringConsts.push_back(dynamic_cast<StringNode*>(root));
            break;

        case _KEYWORD:
        {

            string kw = token->Value;
            if(kw == "printf" || kw == "scanf"){
                errorIf( scan.GetNext()->Value != "(", "Open bracket expected", token);
                scan.Next();
                StringNode *format = dynamic_cast<StringNode*>(ParseExpr(priorityTable[","] + 1));
                errorIf(!format, "Expected string format", token);
                IONode *node = new IONode(dynamic_cast<Token*>(token), format);
                if(scan.Get()->Value == ","){
                    scan.Next();
                    while(true){
                        ExprNode *arg = ParseExpr(priorityTable[","] + 1);
                        errorIf (!arg, "Argument expected", token);
                        node->addArg(arg);
                        if(scan.Get()->Value == ")")
                            break;
                        if(scan.Get()->Value == ",")
                            scan.Next();
                    }
                }
                scan.Next();
                root = node;
            }
            else if(kw == "char" || kw == "int" || kw == "float"){
               // scan.Next();
                SymbolType* type = ParseType();
                errorIf(isEq(scan.Get(), _SEPARATION, "("), "Expected open bracket '('", token);
                scan.Next();
                root = new CastNode(token, ParseExpr(), type);
                // errorIf((isEq(scan.GetNext(), _SEPARATION, ")") && !scan.isEnd()), "Expected closing bracket", token);
            }
            else
                throw MyException("You can use keywords just such as char, int and float in expressions");
        }
            break;




        case _OPERATION:
			if (token->Value == "*"){
				scan.Next();
				auto temp = ParseExpr(priorityTable["--"]);
			//	if (dynamic_cast<PointerNode*>(temp))
//				root = dynamic_cast<PointerNode*>(temp)->name;
	//				root = temp;
		//		else
					root = new PointerNode(temp);
				
			}else
				
//.........这里部分代码省略.........
开发者ID:Deniallugo,项目名称:compiler,代码行数:101,代码来源:Parser.cpp


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