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


C++ pANTLR3_BASE_TREE::getChild方法代码示例

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


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

示例1: processSentenceAssign

void SCsTranslator::processSentenceAssign(pANTLR3_BASE_TREE node)
{
    unsigned int nodesCount = node->getChildCount(node);
    assert(nodesCount == 2);

    pANTLR3_BASE_TREE node_left = (pANTLR3_BASE_TREE)node->getChild(node, 0);
    pANTLR3_BASE_TREE node_right = (pANTLR3_BASE_TREE)node->getChild(node, 1);

    pANTLR3_COMMON_TOKEN tok_left = node_left->getToken(node_left);
    pANTLR3_COMMON_TOKEN tok_right = node_left->getToken(node_right);

    assert(tok_left && tok_right);

    if (tok_left->type != ID_SYSTEM)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     "Unsupported type of tokens at the left side of assignment sentence",
                     mParams.fileName,
                     tok_left->getLine(tok_left));
    }

    if (tok_right->type == ID_SYSTEM)
    {
        mAssignments[GET_NODE_TEXT(node_left)] = GET_NODE_TEXT(node_right);
    }
    else
    {
        String left_idtf = (GET_NODE_TEXT(node_left));
        sElement *el = parseElementTree(node_right, &left_idtf);
    }
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:31,代码来源:scs_translator.cpp

示例2: assert

void SCsTranslator::processSentenceLevel1(pANTLR3_BASE_TREE node)
{
    unsigned int nodesCount = node->getChildCount(node);
    assert(nodesCount == 3);

    pANTLR3_BASE_TREE node_obj = (pANTLR3_BASE_TREE)node->getChild(node, 0);
    pANTLR3_BASE_TREE node_pred = (pANTLR3_BASE_TREE)node->getChild(node, 1);
    pANTLR3_BASE_TREE node_subj = (pANTLR3_BASE_TREE)node->getChild(node, 2);

    pANTLR3_COMMON_TOKEN tok_pred = node_pred->getToken(node_pred);

    if (tok_pred->type != ID_SYSTEM)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     String("Invalid predicate '") + ((const char*) node_pred->getText(node_pred)->chars) + "' in simple sentence",
                     mParams.fileName,
                     tok_pred->getLine(tok_pred));
    }

    sElement *el_obj = parseElementTree(node_obj);
    sElement *el_subj = parseElementTree(node_subj);

    // determine arc type
    sc_type type = sc_type_edge_common;
    String pred = GET_NODE_TEXT(node_pred);
    size_t n = pred.find_first_of("#");
    if (n != pred.npos)
        type = _getArcPreffixType(pred.substr(0, n));

    _addEdge(el_obj, el_subj, type, false, pred);
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:31,代码来源:scs_translator.cpp

示例3: ASTNode

ActualParamDef::ActualParamDef(const pANTLR3_BASE_TREE node)
    : ASTNode(node)
{
    assert(node->getType(node) == N_ACTUAL_PARAM);
    assert(node->getChildCount(node) == 2);

    pANTLR3_BASE_TREE n;

    {
        // param name
        n = (pANTLR3_BASE_TREE) node->getChild(node, 0);
        assert(n->getType(n) == N_PARAM_NAME);
        assert(n->getChildCount(n) == 1);

        n = (pANTLR3_BASE_TREE) n->getChild(n, 0);

        m_ParamName = (wchar_t*) n->getText(n)->chars;
    }

    {
        // value
        n = (pANTLR3_BASE_TREE) node->getChild(node, 1);
        assert(n->getType(n) == N_VALUE);

        createValueDef(n, m_pValue);
    }
}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:27,代码来源:ActualParamDef.cpp

示例4: ValueDef

	ArrayInitValueDef::ArrayInitValueDef(const pANTLR3_BASE_TREE node)
		: ValueDef(ARRAY_INIT, node)
	{
		assert(node->getType(node) == N_ARRAY_INIT_VAL);
		assert(node->getChildCount(node) == 2);

		pANTLR3_BASE_TREE n, c;

		{
			// type
			n = (pANTLR3_BASE_TREE) node->getChild(node, 0);
			assert(n->getType(n) == N_ARRAY_TYPE);
			
			m_pDeclaredType = boost::shared_ptr<Type>(static_cast<Type*>(new ArrayType(n)));
		}

		{
			// array values
			n = (pANTLR3_BASE_TREE) node->getChild(node, 1);
			assert(n->getType(n) == N_ARRAY_VALUES);

			m_Values.clear();

			int childCount = n->getChildCount(n);
			for (int i = 0; i < childCount; i++)
			{
				c = (pANTLR3_BASE_TREE) n->getChild(n, i);

				boost::shared_ptr<ValueDef> pValueDef;
				createValueDef(c, pValueDef);

				m_Values.push_back(pValueDef);
			}
		}
	}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:35,代码来源:ArrayInitValueDef.cpp

示例5: f

	IntegerLiteralValueDef::IntegerLiteralValueDef(const pANTLR3_BASE_TREE node)
		: LiteralValueDef(INTEGER_LITERAL, node)
	{
		assert(node->getType(node) == N_INT_LITERAL);
		assert(node->getChildCount(node) == 1);

		pANTLR3_BASE_TREE n = (pANTLR3_BASE_TREE) node->getChild(node, 0);

		assert(n->getType(n) == INTL);

		wchar_t* szStr = (wchar_t*) n->getText(n)->chars;
		
		int value;

		try
		{
			value = boost::lexical_cast<int, wchar_t*>(szStr);
		}
		catch (const std::exception&)
		{
			boost::wformat f(L"Invalid integer value: %1% at line %2%");
			f % szStr % node->getLine(node);
			ParserException e(f.str());
			throw e;
		}

		m_IntValue = value;
	}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:28,代码来源:IntegerLiteralValueDef.cpp

示例6: dumpNode

void SCsTranslator::dumpNode(pANTLR3_BASE_TREE node, std::ofstream &stream)
{
    StringStream ss;
    ss << node;

    String s_root = ss.str().substr(3);
    pANTLR3_COMMON_TOKEN tok = node->getToken(node);
    if (tok)
    {
        stream << s_root << " [shape=box];" << std::endl;
        String label((const char*) node->getText(node)->chars);
        std::replace(label.begin(), label.end(), '"', '\'');
        stream << s_root << " [label=\"" << label << "\"];" << std::endl;
    }
    else
        stream << s_root << " [shape=circle];" << std::endl;

    uint32 n = node->getChildCount(node);
    for (uint32 i = 0; i < n; ++i)
    {
        pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE) node->getChild(node, i);
        StringStream s1;
        s1 << child;

        stream << s_root << " -> " << s1.str().substr(3) << ";" << std::endl;
        dumpNode(child, stream);
    }
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:28,代码来源:scs_translator.cpp

示例7:

/** Transform ^(nil x) to x 
 */
static	pANTLR3_BASE_TREE	
   rulePostProcessing	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE root)
{
    pANTLR3_BASE_TREE saveRoot;

    // Keep track of the root we are given. If it is a nilNode, then we
    // can reuse it rather than orphaning it!
    //
    saveRoot = root;

	if (root != NULL && root->isNilNode(root))
	{
		if	(root->getChildCount(root) == 0)
		{
			root = NULL;
		}
		else if	(root->getChildCount(root) == 1)
		{
			root = (pANTLR3_BASE_TREE)root->getChild(root, 0);
			root->setParent(root, NULL);
			root->setChildIndex(root, -1);

            // The root we were given was a nil node, wiht one child, which means it has
            // been abandoned and would be lost in the node factory. However
            // nodes can be flagged as resuable to prevent this terrible waste
            //
            saveRoot->reuse(saveRoot);
		}
	}

	return root;
}
开发者ID:Daniel1892,项目名称:tora,代码行数:34,代码来源:antlr3basetreeadaptor.c

示例8:

/** Transform ^(nil x) to x 
 */
static	pANTLR3_BASE_TREE	
   rulePostProcessing	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE root)
{

	if (root != NULL && root->isNil(root) && root->getChildCount(root) == 1)
	{
		root = root->getChild(root, 0);
	}

	return root;
}
开发者ID:UIKit0,项目名称:mclab,代码行数:13,代码来源:antlr3basetreeadaptor.c

示例9: processAttrsIdtfList

void SCsTranslator::processSentenceLevel2_7(pANTLR3_BASE_TREE node)
{
    String connector = GET_NODE_TEXT(node);


    // determine object
    pANTLR3_BASE_TREE node_obj = (pANTLR3_BASE_TREE)node->getChild(node, 0);
    sElement *el_obj = _createElement(GET_NODE_TEXT(node_obj), 0);

    // no we need to parse attributes and predicates
    processAttrsIdtfList(true, node, el_obj, connector, false);
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:12,代码来源:scs_translator.cpp

示例10: emerson_createTreeMirrorImage

void emerson_createTreeMirrorImage(pANTLR3_BASE_TREE ptr)
{

    if(ptr!= NULL && ptr->children != NULL)
    {

        ANTLR3_UINT32 n = ptr->getChildCount(ptr);
        if(n == 1)
        {
            emerson_createTreeMirrorImage((pANTLR3_BASE_TREE)(ptr->getChild(ptr, 0)));
        }
        if(n == 2)  // should it be checked
        {
            pANTLR3_BASE_TREE right = (pANTLR3_BASE_TREE)(ptr->getChild(ptr, 1));
            emerson_createTreeMirrorImage( (pANTLR3_BASE_TREE)(ptr->getChild(ptr, 0)));
            emerson_createTreeMirrorImage( (pANTLR3_BASE_TREE)(ptr->getChild(ptr, 1)) );
            ptr->setChild(ptr, 1, ptr->getChild(ptr, 0));
            ptr->setChild(ptr, 0, right);
        }
    }
}
开发者ID:LittleForker,项目名称:sirikata,代码行数:21,代码来源:Util.cpp

示例11: pActualParamDef

	ObjectInitValueDef::ObjectInitValueDef(const pANTLR3_BASE_TREE node)
		: ValueDef(OBJECT_INIT, node)
	{
		assert(node->getType(node) == N_OBJECT_INIT_VAL);
		assert(node->getChildCount(node) == 2);

		pANTLR3_BASE_TREE n, c;

		{
			// class name
			n = (pANTLR3_BASE_TREE) node->getChild(node, 0);
			assert(n->getType(n) == N_CLASS_NAME);
			assert(n->getChildCount(n) == 1);

			n = (pANTLR3_BASE_TREE) n->getChild(n, 0);
			assert(n->getType(n) == ID);

			wchar_t* szClassName = (wchar_t*) n->getText(n)->chars;
			m_ClassName = szClassName;
		}

		{
			m_ActualParamsMap.clear();

			// actual params
			n = (pANTLR3_BASE_TREE) node->getChild(node, 1);
			assert(n->getType(n) == N_ACTUAL_PARAMS);

			int childCount = n->getChildCount(n);
			for (int i = 0; i < childCount; i++)
			{
				c = (pANTLR3_BASE_TREE) n->getChild(n, i);
				assert(c->getType(c) == N_ACTUAL_PARAM);

				ActualParamDefPtr pActualParamDef(new ActualParamDef(c));
				m_ActualParamsMap[pActualParamDef->getParamName()] = pActualParamDef;
			}
		}
	}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:39,代码来源:ObjectInitValueDef.cpp

示例12: if

static  void
toStringWork    (pANTLR3_TREE_NODE_STREAM tns, pANTLR3_BASE_TREE p, pANTLR3_BASE_TREE stop, pANTLR3_STRING buf)
{

        ANTLR3_UINT32   n;
        ANTLR3_UINT32   c;

        if      (!p->isNilNode(p) )
        {
                pANTLR3_STRING  text;

                text    = p->toString(p);

                if  (text == NULL)
                {
                        text = tns->ctns->stringFactory->newRaw(tns->ctns->stringFactory);

                        text->addc      (text, ' ');
                        text->addi      (text, p->getType(p));
                }

                buf->appendS(buf, text);
        }

        if      (p == stop)
        {
                return;         /* Finished */
        }

        n = p->getChildCount(p);

        if      (n > 0 && ! p->isNilNode(p) )
        {
                buf->addc   (buf, ' ');
                buf->addi   (buf, ANTLR3_TOKEN_DOWN);
        }

        for     (c = 0; c<n ; c++)
        {
                pANTLR3_BASE_TREE   child;

                child = p->getChild(p, c);
                tns->toStringWork(tns, child, stop, buf);
        }

        if      (n > 0 && ! p->isNilNode(p) )
        {
                buf->addc   (buf, ' ');
                buf->addi   (buf, ANTLR3_TOKEN_UP);
        }
}
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:51,代码来源:antlr3commontreenodestream.c

示例13:

/** If oldRoot is a nil root, just copy or move the children to newRoot.
 *  If not a nil root, make oldRoot a child of newRoot.
 *
 * \code
 *    old=^(nil a b c), new=r yields ^(r a b c)
 *    old=^(a b c), new=r yields ^(r ^(a b c))
 * \endcode
 *
 *  If newRoot is a nil-rooted single child tree, use the single
 *  child as the new root node.
 *
 * \code
 *    old=^(nil a b c), new=^(nil r) yields ^(r a b c)
 *    old=^(a b c), new=^(nil r) yields ^(r ^(a b c))
 * \endcode
 *
 *  If oldRoot was null, it's ok, just return newRoot (even if isNilNode).
 *
 * \code
 *    old=null, new=r yields r
 *    old=null, new=^(nil r) yields ^(nil r)
 * \endcode
 *
 *  Return newRoot.  Throw an exception if newRoot is not a
 *  simple node or nil root with a single child node--it must be a root
 *  node.  If newRoot is <code>^(nil x)</endcode> return x as newRoot.
 *
 *  Be advised that it's ok for newRoot to point at oldRoot's
 *  children; i.e., you don't have to copy the list.  We are
 *  constructing these nodes so we should have this control for
 *  efficiency.
 */
static	pANTLR3_BASE_TREE	
becomeRoot	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE newRootTree, pANTLR3_BASE_TREE oldRootTree)
{
	/* Protect against tree rewrites if we are in some sort of error
	 * state, but have tried to recover. In C we can end up with a null pointer
	 * for a tree that was not produced.
	 */
	if	(newRootTree == NULL)
	{
		return	oldRootTree;
	}

	/* root is just the new tree as is if there is no
	 * current root tree.
	 */
	if	(oldRootTree == NULL)
	{
		return	newRootTree;
	}

	/* Produce ^(nil real-node)
	 */
	if	(newRootTree->isNilNode(newRootTree))
	{
		if	(newRootTree->getChildCount(newRootTree) > 1)
		{
			/* TODO: Handle tree exceptions 
			 */
			ANTLR3_FPRINTF(stderr, "More than one node as root! TODO: Create tree exception hndling\n");
			return newRootTree;
		}

		/* The new root is the first child
		 */
		newRootTree = newRootTree->getChild(newRootTree, 0);
	}

	/* Add old root into new root. addChild takes care of the case where oldRoot
	 * is a flat list (nill rooted tree). All children of oldroot are added to
	 * new root.
	 */
	newRootTree->addChild(newRootTree, oldRootTree);

	/* Always returns new root structure
	 */
	return	newRootTree;

}
开发者ID:aslakhellesoy,项目名称:antlr-3,代码行数:80,代码来源:antlr3basetreeadaptor.c

示例14: dumpTree

std::string MySQLRecognitionBase::dumpTree(pANTLR3_UINT8 *tokenNames, pANTLR3_BASE_TREE tree, const std::string &indentation)
{
  std::string result;

  ANTLR3_UINT32 char_pos = tree->getCharPositionInLine(tree);
  ANTLR3_UINT32 line = tree->getLine(tree);
  pANTLR3_STRING token_text = tree->getText(tree);

  pANTLR3_COMMON_TOKEN token = tree->getToken(tree);
  const char* utf8 = (const char*)token_text->chars;
  if (token != NULL)
  {
    ANTLR3_UINT32 token_type = token->getType(token);

    pANTLR3_UINT8 token_name;
    if (token_type == EOF)
      token_name = (pANTLR3_UINT8)"EOF";
    else
      token_name = tokenNames[token_type];

#ifdef ANTLR3_USE_64BIT
    result = base::strfmt("%s(line: %i, offset: %i, length: %" PRId64 ", index: %" PRId64 ", %s[%i])    %s\n",
                          indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name,
                          token_type, utf8);
#else
    result = base::strfmt("%s(line: %i, offset: %i, length: %i, index: %i, %s[%i])    %s\n",
                          indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name,
                          token_type, utf8);
#endif

  }
  else
  {
    result = base::strfmt("%s(line: %i, offset: %i, nil)    %s\n", indentation.c_str(), line, char_pos, utf8);
  }

  for (ANTLR3_UINT32 index = 0; index < tree->getChildCount(tree); index++)
  {
    pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE)tree->getChild(tree, index);
    std::string child_text = dumpTree(tokenNames, child, indentation + "\t");
    result += child_text;
  }
  return result;
}
开发者ID:ThiagoGarciaAlves,项目名称:mysql-workbench,代码行数:44,代码来源:mysql-parser-common.cpp

示例15:

/// Set the parent and child indexes for some of the children of the
/// supplied tree, starting with the child at the supplied index.
///
static	void
freshenPACIndexes	(pANTLR3_BASE_TREE tree, ANTLR3_UINT32 offset)
{
	ANTLR3_UINT32	count;
	ANTLR3_UINT32	c;

	count	= tree->getChildCount(tree);		// How many children do we have 

	// Loop from the supplied index and set the indexes and parent
	//
	for	(c = offset; c < count; c++)
	{
		pANTLR3_BASE_TREE	child;

		child = tree->getChild(tree, c);

		child->setChildIndex(child, c);
		child->setParent(child, tree);
	}
}
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:23,代码来源:antlr3basetree.c


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