本文整理汇总了C++中pANTLR3_BASE_TREE类的典型用法代码示例。如果您正苦于以下问题:C++ pANTLR3_BASE_TREE类的具体用法?C++ pANTLR3_BASE_TREE怎么用?C++ pANTLR3_BASE_TREE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了pANTLR3_BASE_TREE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LiteralValueDef
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;
}
示例2: assert
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);
}
}
示例3: label
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);
}
}
示例4:
pANTLR3_BASE_TREE
dupTreeTT (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_BASE_TREE parent)
{
pANTLR3_BASE_TREE newTree;
pANTLR3_BASE_TREE child;
pANTLR3_BASE_TREE newSubTree;
ANTLR3_UINT32 n;
ANTLR3_UINT32 i;
if (t == NULL)
{
return NULL;
}
newTree = (pANTLR3_BASE_TREE)t->dupNode(t);
// Ensure new subtree root has parent/child index set
//
adaptor->setChildIndex (adaptor, newTree, t->getChildIndex(t));
adaptor->setParent (adaptor, newTree, parent);
n = adaptor->getChildCount (adaptor, t);
for (i=0; i < n; i++)
{
child = (pANTLR3_BASE_TREE)adaptor->getChild (adaptor, t, i);
newSubTree = (pANTLR3_BASE_TREE)adaptor->dupTreeTT (adaptor, child, t);
adaptor->addChild (adaptor, newTree, newSubTree);
}
return newTree;
}
示例5: 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);
}
}
示例6: 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);
}
}
}
示例7:
/** 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;
}
示例8: emerson_printAST
pANTLR3_STRING emerson_printAST(pANTLR3_BASE_TREE tree, pANTLR3_UINT8* parserTokenNames)
{
pANTLR3_STRING string;
ANTLR3_UINT32 i;
ANTLR3_UINT32 n;
pANTLR3_BASE_TREE t;
if(tree->children == NULL || tree->children->size(tree->children) == 0)
{
return tree->toString(tree);
}
// THis is how you get a new string. The string is blank
string = tree->strFactory->newRaw(tree->strFactory);
if(tree->isNilNode(tree) == ANTLR3_FALSE)
{
string->append8 (string, "(");
pANTLR3_COMMON_TOKEN token = tree->getToken(tree);
ANTLR3_UINT32 type = token->type;
string->append(string, (const char*)parserTokenNames[type]);
string->append8(string, " ");
}
if(tree->children != NULL)
{
n = tree->children->size(tree->children);
for (i = 0; i < n; i++)
{
t = (pANTLR3_BASE_TREE) tree->children->get(tree->children, i);
if (i > 0)
{
string->append8(string, " ");
}
string->appendS(string, emerson_printAST(t,parserTokenNames));
}
}
if(tree->isNilNode(tree) == ANTLR3_FALSE)
{
string->append8(string,")");
}
return string;
}
示例9:
/** 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;
}
示例10: addChild
/** Add a child to the tree t. If child is a flat tree (a list), make all
* in list children of t. Warning: if t has no children, but child does
* and child isNilNode then it is ok to move children to t via
* t.children = child.children; i.e., without copying the array. This
* is for construction and I'm not sure it's completely general for
* a tree's addChild method to work this way. Make sure you differentiate
* between your tree's addChild and this parser tree construction addChild
* if it's not ok to move children to t with a simple assignment.
*/
static void
addChild (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_BASE_TREE child)
{
if (t != NULL && child != NULL)
{
t->addChild(t, child);
}
}
示例11:
static pANTLR3_STRING
toStringTree (pANTLR3_BASE_TREE tree)
{
pANTLR3_STRING string;
ANTLR3_UINT32 i;
ANTLR3_UINT32 n;
pANTLR3_BASE_TREE t;
if (tree->children == NULL || tree->children->size(tree->children) == 0)
{
return tree->toString(tree);
}
/* Need a new string with nothing at all in it.
*/
string = tree->strFactory->newRaw(tree->strFactory);
if (tree->isNilNode(tree) == ANTLR3_FALSE)
{
string->append8 (string, "(");
string->appendS (string, tree->toString(tree));
string->append8 (string, " ");
}
if (tree->children != NULL)
{
n = tree->children->size(tree->children);
for (i = 0; i < n; i++)
{
t = (pANTLR3_BASE_TREE) tree->children->get(tree->children, i);
if (i > 0)
{
string->append8(string, " ");
}
string->appendS(string, t->toStringTree(t));
}
}
if (tree->isNilNode(tree) == ANTLR3_FALSE)
{
string->append8(string,")");
}
return string;
}
示例12: dbgAddChild
static void
dbgAddChild (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, pANTLR3_BASE_TREE child)
{
if (t != NULL && child != NULL)
{
t->addChild(t, child);
adaptor->debugger->addChild(adaptor->debugger, t, child);
}
}
示例13:
static void
replaceChildren
(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, pANTLR3_BASE_TREE t)
{
if (parent != NULL)
{
parent->replaceChildren(parent, startChildIndex, stopChildIndex, t);
}
}
示例14: if
static ANTLR3_UINT32 getCharPositionInLine (pANTLR3_BASE_TREE tree)
{
pANTLR3_COMMON_TOKEN token;
token = ((pANTLR3_COMMON_TREE)(tree->super))->token;
if (token == NULL || token->getCharPositionInLine(token) == -1)
{
if (tree->getChildCount(tree) > 0)
{
pANTLR3_BASE_TREE child;
child = (pANTLR3_BASE_TREE)tree->getChild(tree, 0);
return child->getCharPositionInLine(child);
}
return 0;
}
return token->getCharPositionInLine(token);
}
示例15:
ASTNode::ASTNode(const pANTLR3_BASE_TREE node)
{
m_LineNumber = node->getLine(node);
m_CharPosition = node->getCharPositionInLine(node);
pANTLR3_BASE_TREE n = node;
while ((n != NULL) && (n->u == NULL))
{
if (n->u != NULL)
{
m_FileName = (wchar_t*) n->u;
node->u = n->u;
break;
}
else
{
n = n->getParent(n);
}
}
}