本文整理汇总了C++中SyntaxTree类的典型用法代码示例。如果您正苦于以下问题:C++ SyntaxTree类的具体用法?C++ SyntaxTree怎么用?C++ SyntaxTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SyntaxTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: m_curErrPos
SyntaxTree* Parser::m_parse_orderedChoice(TArray<Parser*>* ps)
{
m_ErrorPos startPos = m_curErrPos();
int i = 0;
for (TArrayIterator<Parser*> itr(ps); itr.hasMore(); ++i) {
Parser* p = itr.next();
SyntaxTree* st = p->parse();
if (st->isError()) {
m_fail(startPos);
return st;
}
if (! st->isFail()) {
SyntaxTree::Childs* childs = new SyntaxTree::Childs(1);
childs->setContentsMemID("pcoc");
p->addSyntaxTreeToParent(childs, st);
SyntaxTree* ordst = createSyntaxTree(startPos.parsePos, childs);
ordst->chooseNum = i;
return ordst;
}
if (itr.hasMore())
m_back(startPos);
}
m_fail(startPos);
return m_PARSE_FAILED;
}
示例2: resolveClosure
ref_t ModuleScope :: resolveClosure(ref_t closureMessage, ref_t outputRef, ident_t ns)
{
ref_t signRef = 0;
module->resolveAction(getAction(closureMessage), signRef);
int paramCount = getParamCount(closureMessage);
IdentifierString closureName(module->resolveReference(closureTemplateReference));
if (signRef == 0) {
if (paramCount > 0) {
closureName.appendInt(paramCount);
}
if (isWeakReference(closureName)) {
return module->mapReference(closureName, true);
}
else return mapFullReference(closureName, true);
}
else {
ref_t signatures[ARG_COUNT];
size_t signLen = module->resolveSignature(signRef, signatures);
List<SNode> parameters;
SyntaxTree dummyTree;
SyntaxWriter dummyWriter(dummyTree);
dummyWriter.newNode(lxRoot);
for (size_t i = 0; i < signLen; i++) {
dummyWriter.appendNode(lxTarget, signatures[i]);
}
if (outputRef) {
dummyWriter.appendNode(lxTarget, outputRef);
}
// if the output signature is not provided - use the super class
else dummyWriter.appendNode(lxTarget, superReference);
dummyWriter.closeNode();
SNode paramNode = dummyTree.readRoot().firstChild();
while (paramNode != lxNone) {
parameters.add(paramNode);
paramNode = paramNode.nextNode();
}
closureName.append('#');
closureName.appendInt(paramCount + 1);
ref_t templateReference = 0;
if (isWeakReference(closureName)) {
templateReference = module->mapReference(closureName, true);
}
else templateReference = mapFullReference(closureName, true);
if (templateReference) {
return generateTemplate(templateReference, parameters, ns, false);
}
else return superReference;
}
}
示例3: removePartial
/**
* @brief Parser::removePartial Destroys all of the nodes to the right of current
* @param S the tree
*/
void Parser::removePartial(SyntaxTree &S){
TNpair* c = S.getCurrent();
S.shiftToRoot();
bool f = false;
S = removePartial(S.getCurrent(),c,f);
S.shiftTo(c);
}
示例4: main
int main(int argc, char** argv) {
bool opTree = false;
string filename = "";
for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 't': // Print the tree
opTree = true;
break;
}
} else
filename = string(argv[i]);
}
try {
SyntaxTree tree;
vector<char> bytecode;
ifstream ifs(filename.c_str());
VirtualMachine vm;
vm.compile(ifs, bytecode, tree);
if (opTree)
tree.dump(std::cout);
vm.run(&bytecode[0]);
} catch (std::exception &e) {
std::cerr << e.what() << "\n";
}
}
示例5: TEST_F
TEST_F(ExpressionTest, parseExpression3) {
static const std::string expression = "0 | (1 | 0 & 1) & 1";
static const std::string result = "|C&()|C&CCC";
auto operation = Expression().makeOperation(expression);
SyntaxTree visitor;
operation->accept(visitor);
EXPECT_STREQ(result.c_str(), visitor.result().c_str());
}
示例6: m_parse_noTree
SyntaxTree* Parser::m_parse_noTree(Parser* p)
{
SyntaxTree* st = p->parse();
if (st->isFail())
return st;
if (! m_bUseMemoize) {
SyntaxTree::deleteRecursively(st);
}
return m_NO_SYNTAX_TREE;
}
示例7: main
int main ()
{
SyntaxTree * treeS = new ( nothrow ) SyntaxTree ();
treeS->parse();
treeS->print();
cout << endl;
delete treeS;
return 0;
}
示例8: tokens
vector<DisambiguatedData> PredictedMorphologyTreeRecoverer::GetMorphology(
const SyntaxTree& realTree)
{
size_t size = static_cast<size_t>(realTree.GetSize());
vector<Token> tokens(size);
for (size_t nodeIndex = 0; nodeIndex < size; ++nodeIndex)
{
tokens[nodeIndex] = static_cast<Token>(realTree.GetNodes()[nodeIndex]);
}
return disambiguator->Disambiguate(tokens);
}
示例9: CleanupOnFailure
void Syntaxer::CleanupOnFailure() {
SyntaxTree tree;
for (int i = 0; i < (int)stack_->symbols.size(); ++i) {
if (stack_->symbols[i].SymbolType() == GrammarSymbolNonterminal) {
tree.SetRoot((SyntaxNode*)stack_->values[i]);
tree.Destroy();
}
}
stack_->clear();
}
示例10: generateTemplateProperty
void ModuleScope :: generateTemplateProperty(SyntaxWriter& output, ref_t reference, List<SNode>& parameters)
{
SyntaxTree templateTree;
TemplateGenerator transformer(templateTree);
SyntaxWriter writer(templateTree);
writer.newNode(lxRoot);
transformer.generateTemplateProperty(writer, *this, reference, parameters);
writer.closeNode();
SyntaxTree::copyNode(output, templateTree.readRoot());
}
示例11: importClassTemplate
void ModuleScope :: importClassTemplate(SyntaxWriter& output, ref_t reference, List<SNode>& parameters)
{
SyntaxTree templateTree;
TemplateGenerator transformer(templateTree);
SyntaxWriter writer(templateTree);
writer.newNode(lxRoot);
transformer.generateTemplate(writer, *this, reference, parameters, false, true);
writer.closeNode();
transformer.importClass(output, templateTree.readRoot());
}
示例12: main
int main()
{
string formula;
while (getline(cin, formula))
{
SyntaxTree F;
F.BuildSyntaxTree(formula);
cout << fixed << setprecision(5);
cout << F.Count() << endl;
}
system("pause");
return 0;
}
示例13: name
SyntaxTree* UserParser::m_parse1(m_ErrorPos startPos)
{
const char* n = name();
SyntaxTree* st;
if (m_bUseMemoize) {
st = m_memo.getAt(startPos.parsePos);
if (st == m_PARSING) {
// left recursion
char pbuf[128];
gpInp->sprintSourceInfo(pbuf, 128, startPos.parsePos);
HMD_PRINTF("LEFT RECURSION DETECTED: %s %s\n", n, pbuf);
return m_FATAL_PARSER_ERROR;
} else if (st != m_NOT_PARSED_YET) {
if (st->isValidTree())
gpInp->setPos(st->str.endPos);
if (m_printIntermediateLevel > 1 ||
(m_printIntermediateLevel > 0 && !st->isFail())) {
char pbuf[128];
gpInp->sprintSourceInfo(pbuf, 128, startPos.parsePos);
HMD_PRINTF("%s %s -> memoized ", n, pbuf);
if (st->isValidTree()) {
char b[44];
gpInp->copySummary(b, 40, st->str);
HMD_PRINTF("pos=%d-%d '%s'\n", st->str.startPos, st->str.endPos, b);
} else {
if (st == m_NO_SYNTAX_TREE)
HMD_PRINTF("no syntax tree\n");
else if (st == m_PARSE_FAILED)
HMD_PRINTF("parse failed\n");
else if (st->isErrorCut())
HMD_PRINTF("ErrorCut(%d)\n",st->errorCutId);
else
HMD_PRINTF("(UNKNOWN BUG?)\n");
}
}
return st;
}
// not parsed yet
m_memo.setAt(startPos.parsePos, m_PARSING);
}
if (m_printIntermediateLevel > 1) {
char pbuf[128];
gpInp->sprintSourceInfo(pbuf, 128, startPos.parsePos);
HMD_PRINTF("try %s %s pos=%d:\n", n, pbuf, startPos.parsePos);
}
return NULL;
}
示例14: prtPatSet
void
prtPatSet(PatSet *p, ostream &os, unsigned indent) {
if (p != NULL) {
PatSet::iterator pi;
for (pi = p->begin(); pi != p->end(); pi++) {
SyntaxTree *st = *pi;
if (st != NULL) {
os << endl;
st->print(os, 0, 1000000, 50, indent+2);
os << endl;
}
}
}
}
示例15: LeftBinarize
void LeftBinarize( SyntaxTree &tree, ParentNodes &parents )
{
for(ParentNodes::const_iterator p = parents.begin(); p != parents.end(); p++) {
const SplitPoints &point = *p;
if (point.size() > 3) {
const vector< SyntaxNode* >& topNodes
= tree.GetNodes( point[0], point[point.size()-1]-1);
string topLabel = topNodes[0]->GetLabel();
for(size_t i=2; i<point.size()-1; i++) {
// cerr << "LeftBin " << point[0] << "-" << (point[point.size()-1]-1) << ": " << point[0] << "-" << point[i]-1 << " ^" << topLabel << endl;
tree.AddNode( point[0], point[i]-1, "^" + topLabel );
}
}
}
}