void TreeViewer::setNode( SyntaxNode *node ) { clearTreeStack(); TreeIterator iterator(node); while( ! iterator.isDone() ){ SyntaxNode *syntaxNode = dynamic_cast<SyntaxNode *>(iterator.current()); if( syntaxNode ) syntaxNode->accept( this ); iterator.next(); } update(); }
SyntaxNode* ActionMake::Invoke(const std::vector<void*>& container) { SyntaxNode* ans = new SyntaxNode(SyntaxNodeOperation, argument_.text); SyntaxNode** nodes = new SyntaxNode*[argument_.parameters.size()]; for (int i = 0; i < (int)argument_.parameters.size(); ++i) { if (argument_.parameters[i] == 0) { nodes[i] = nullptr; } else { nodes[i] = (SyntaxNode*)container[container.size() - argument_.parameters[i]]; } } ans->AddChildren(nodes, argument_.parameters.size()); delete[] nodes; return ans; }
// Converts a SyntaxNode tree to a Moses::GHKM::ParseTree. std::auto_ptr<ParseTree> XmlTreeParser::ConvertTree( const SyntaxNode &tree, const std::vector<std::string> &words) { std::auto_ptr<ParseTree> root(new ParseTree(tree.GetLabel())); const std::vector<SyntaxNode*> &children = tree.GetChildren(); if (children.empty()) { if (tree.GetStart() != tree.GetEnd()) { std::ostringstream msg; msg << "leaf node covers multiple words (" << tree.GetStart() << "-" << tree.GetEnd() << "): this is currently unsupported"; throw Exception(msg.str()); } std::auto_ptr<ParseTree> leaf(new ParseTree(words[tree.GetStart()])); leaf->SetParent(root.get()); root->AddChild(leaf.release()); } else { for (std::vector<SyntaxNode*>::const_iterator p = children.begin(); p != children.end(); ++p) { assert(*p); std::auto_ptr<ParseTree> child = ConvertTree(**p, words); child->SetParent(root.get()); root->AddChild(child.release()); } } return root; }
void BlockSyntaxNode::printAST(SyntaxNode *root, std::ostream &os) { os << std::setw(4) << std::dec << nodenum << " "; os << "[label=\""; if (pbb) { switch (pbb->getType()) { case ONEWAY: os << "Oneway"; if (notGoto) os << " (ignored)"; break; case TWOWAY: os << "Twoway"; break; case NWAY: os << "Nway"; break; case CALL: os << "Call"; break; case RET: os << "Ret"; break; case FALL: os << "Fall"; break; case COMPJUMP: os << "Computed jump"; break; case COMPCALL: os << "Computed call"; break; case INVALID: os << "Invalid"; break; } os << " " << std::hex << pbb->getLowAddr(); } else os << "block"; os << "\"];" << std::endl; if (pbb) { for (int i = 0; i < pbb->getNumOutEdges(); i++) { PBB out = pbb->getOutEdge(i); os << std::setw(4) << std::dec << nodenum << " "; SyntaxNode *to = root->findNodeFor(out); assert(to); os << " -> " << to->getNumber() << " [style=dotted"; if (pbb->getNumOutEdges() > 1) os << ",label=" << i; os << "];" << std::endl; } } else { for (unsigned i = 0; i < statements.size(); i++) statements[i]->printAST(root, os); for (unsigned i = 0; i < statements.size(); i++) { os << std::setw(4) << std::dec << nodenum << " "; os << " -> " << statements[i]->getNumber() << " [label=\"" << i << "\"];" << std::endl; } } }
SyntaxNode *SyntaxNode::findChild(int searchtoken) const { switch(m_token) { case NAME : case PARAM : case HOSTVAR : case STRING : case NUMBER : case DATECONST : case TIMECONST : case TIMESTAMPCONST: throwSqlError(SQL_FATAL_ERROR,_T("No children in findChild(%d) in SyntaxNode (line %d, token %d)") ,searchtoken,m_pos.getLineNumber(),m_token); break; } for(int i = 0; i < m_attributes.m_children.m_count; i++) { SyntaxNode *p = m_attributes.m_children.m_child[i]; if(p->token() == searchtoken) return p; } return NULL; }
void SqlCompiler::genInsert(SyntaxNode *n) { // n == <insert_stmt> const TCHAR *tableName = n->child(0)->name(); StatementTable table(*this,n->child(0)); if(!ok()) return; if(table.getTableType() != TABLETYPE_USER) { syntaxError(n->child(0),SQL_INVALID_TABLETYPE,_T("Cannot insert into systemtable <%s>"),tableName); return; } SyntaxNode *insertwhat = n->child(2); switch(insertwhat->token()) { case VALUES: genInsertValues(n,table); break; case SELECT: genInsertSelect(n); break; default: stopcomp(insertwhat); } m_code.appendIns0(CODERETURN); }
void SyntaxTree::ConnectNodes() { typedef SyntaxTreeIndex2::const_reverse_iterator InnerIterator; SyntaxNode *prev = 0; // Iterate over all start indices from lowest to highest. for (SyntaxTreeIndexIterator p = m_index.begin(); p != m_index.end(); ++p) { const SyntaxTreeIndex2 &inner = p->second; // Iterate over all end indices from highest to lowest. for (InnerIterator q = inner.rbegin(); q != inner.rend(); ++q) { const std::vector<SyntaxNode*> &nodes = q->second; // Iterate over all nodes that cover the same span in order of tree // depth, top-most first. for (std::vector<SyntaxNode*>::const_reverse_iterator r = nodes.rbegin(); r != nodes.rend(); ++r) { SyntaxNode *node = *r; if (!prev) { // node is the root. m_top = node; node->SetParent(0); } else if (prev->GetStart() == node->GetStart()) { // prev is the parent of node. assert(prev->GetEnd() >= node->GetEnd()); node->SetParent(prev); prev->AddChild(node); } else { // prev is a descendant of node's parent. The lowest common // ancestor of prev and node will be node's parent. SyntaxNode *ancestor = prev->GetParent(); while (ancestor->GetEnd() < node->GetEnd()) { ancestor = ancestor->GetParent(); } assert(ancestor); node->SetParent(ancestor); ancestor->AddChild(node); } prev = node; } } } }
/*TODO: we'd only have to return a vector of XML options if we dropped linking. 2-d vector is so we can link things up afterwards. We can't create TranslationOptions as we parse because we don't have the completed source parsed until after this function removes all the markup from it (CreateFromString in Sentence::Read). */ bool ProcessAndStripXMLTags(string &line, SyntaxTree &tree, set< string > &labelCollection, map< string, int > &topLabelCollection ) { //parse XML markup in translation line // no xml tag? we're done. if (line.find_first_of('<') == string::npos) { return true; } // break up input into a vector of xml tags and text // example: (this), (<b>), (is a), (</b>), (test .) vector<string> xmlTokens = TokenizeXml(line); // we need to store opened tags, until they are closed // tags are stored as tripled (tagname, startpos, contents) typedef pair< string, pair< size_t, string > > OpenedTag; vector< OpenedTag > tagStack; // stack that contains active opened tags string cleanLine; // return string (text without xml) size_t wordPos = 0; // position in sentence (in terms of number of words) bool isLinked = false; // loop through the tokens for (size_t xmlTokenPos = 0 ; xmlTokenPos < xmlTokens.size() ; xmlTokenPos++) { // not a xml tag, but regular text (may contain many words) if(!isXmlTag(xmlTokens[xmlTokenPos])) { // add a space at boundary, if necessary if (cleanLine.size()>0 && cleanLine[cleanLine.size() - 1] != ' ' && xmlTokens[xmlTokenPos][0] != ' ') { cleanLine += " "; } cleanLine += unescape(xmlTokens[xmlTokenPos]); // add to output wordPos = Tokenize(cleanLine).size(); // count all the words } // process xml tag else { // *** get essential information about tag *** // strip extra boundary spaces and "<" and ">" string tag = Trim(TrimXml(xmlTokens[xmlTokenPos])); // cerr << "XML TAG IS: " << tag << std::endl; if (tag.size() == 0) { cerr << "ERROR: empty tag name: " << line << endl; return false; } // check if unary (e.g., "<wall/>") bool isUnary = ( tag[tag.size() - 1] == '/' ); // check if opening tag (e.g. "<a>", not "</a>")g bool isClosed = ( tag[0] == '/' ); bool isOpen = !isClosed; if (isClosed && isUnary) { cerr << "ERROR: can't have both closed and unary tag <" << tag << ">: " << line << endl; return false; } if (isClosed) tag = tag.substr(1); // remove "/" at the beginning if (isUnary) tag = tag.substr(0,tag.size()-1); // remove "/" at the end // find the tag name and contents string::size_type endOfName = tag.find_first_of(' '); string tagName = tag; string tagContent = ""; if (endOfName != string::npos) { tagName = tag.substr(0,endOfName); tagContent = tag.substr(endOfName+1); } // *** process new tag *** if (isOpen || isUnary) { // put the tag on the tag stack OpenedTag openedTag = make_pair( tagName, make_pair( wordPos, tagContent ) ); tagStack.push_back( openedTag ); // cerr << "XML TAG " << tagName << " (" << tagContent << ") added to stack, now size " << tagStack.size() << endl; } // *** process completed tag *** if (isClosed || isUnary) { // pop last opened tag from stack; if (tagStack.size() == 0) { cerr << "ERROR: tag " << tagName << " closed, but not opened" << ":" << line << endl; return false; } OpenedTag openedTag = tagStack.back(); tagStack.pop_back(); // tag names have to match if (openedTag.first != tagName) { cerr << "ERROR: tag " << openedTag.first << " closed by tag " << tagName << ": " << line << endl; return false; } // assemble remaining information about tag size_t startPos = openedTag.second.first; string tagContent = openedTag.second.second; size_t endPos = wordPos; // span attribute overwrites position string span = ParseXmlTagAttribute(tagContent,"span"); if (! span.empty()) { vector<string> ij = Tokenize(span, "-"); if (ij.size() != 1 && ij.size() != 2) { cerr << "ERROR: span attribute must be of the form \"i-j\" or \"i\": " << line << endl; return false; } startPos = atoi(ij[0].c_str()); if (ij.size() == 1) endPos = startPos + 1; else endPos = atoi(ij[1].c_str()) + 1; } // cerr << "XML TAG " << tagName << " (" << tagContent << ") spanning " << startPos << " to " << (endPos-1) << " complete, commence processing" << endl; if (startPos >= endPos) { cerr << "ERROR: tag " << tagName << " must span at least one word (" << startPos << "-" << endPos << "): " << line << endl; return false; } string label = ParseXmlTagAttribute(tagContent,"label"); labelCollection.insert( label ); string scoreString = ParseXmlTagAttribute(tagContent,"score"); float score = scoreString == "" ? 0.0f : std::atof(scoreString.c_str()); // report what we have processed so far if (0) { cerr << "XML TAG NAME IS: '" << tagName << "'" << endl; cerr << "XML TAG LABEL IS: '" << label << "'" << endl; cerr << "XML SPAN IS: " << startPos << "-" << (endPos-1) << endl; } SyntaxNode *node = tree.AddNode( startPos, endPos-1, label ); node->SetScore(score); } } } // we are done. check if there are tags that are still open if (tagStack.size() > 0) { cerr << "ERROR: some opened tags were never closed: " << line << endl; return false; } // collect top labels const vector< SyntaxNode* >& topNodes = tree.GetNodes( 0, wordPos-1 ); for( vector< SyntaxNode* >::const_iterator node = topNodes.begin(); node != topNodes.end(); node++ ) { SyntaxNode *n = *node; const string &label = n->GetLabel(); if (topLabelCollection.find( label ) == topLabelCollection.end()) topLabelCollection[ label ] = 0; topLabelCollection[ label ]++; } // return de-xml'ed sentence in line line = cleanLine; return true; }
void SqlCompiler::genInsertValues(const SyntaxNode *n, // n == insert_stmt StatementTable &table) { NodeList columnlist((n->child(1)->childCount() == 0) ? NULL : n->child(1)->child(0)); SyntaxNode *insertwhat = n->child(2); // == VALUES NodeList exprlist(insertwhat->child(0)); Array<InsertColumnExpression> icemap; if(columnlist.size() == 0) { // no columnnames specified. use all columns of tabledefinition if(exprlist.size() != table.getColumnCount()) { syntaxError(insertwhat,SQL_INVALID_EXPRLIST,_T("Invalid number of expressions specified")); return; } for(UINT i = 0; i < table.getColumnCount(); i++) icemap.add(InsertColumnExpression(table,i,exprlist[i])); } else { // columnnames specified if(columnlist.size() != exprlist.size()) { syntaxError(insertwhat,SQL_INVALID_EXPRLIST,_T("Invalid number of expressions specified")); return; } for(UINT i = 0; i < columnlist.size(); i++) { const TCHAR *name = columnlist[i]->name(); int colindex = table.findColumnIndex(name); if(colindex < 0) syntaxError(columnlist[i],SQL_INVALID_COLUMNNAME,_T("Invalid columnname:<%s>"),name); else { bool found = false; for(UINT j = 0; j < icemap.size(); j++) { // check not already spec if(icemap[j].m_colIndex == colindex) { syntaxError(columnlist[i],SQL_COLUMN_ALREADY_DEFINED,_T("Column <%s> already specified"),name); found = true; break; } } if(!found) icemap.add(InsertColumnExpression(table,colindex,exprlist[i])); } } if(columnlist.size() > table.getColumnCount()) syntaxError(insertwhat,SQL_TOO_MANY_COLUMNS,_T("Too many columns specified")); else { if(columnlist.size() < table.getColumnCount()) // check, that unspecified columns have nulls-allowed or defaultvalue for(UINT i = 0; i < table.getColumnCount(); i++) { bool found = false; for(UINT j = 0; j < icemap.size(); j++) { if(icemap[j].m_colIndex == i) { found = true; break; } } if(!found) { // unspecified column SyntaxNode *defaultvalue = fetchDefaultValueNode(table.getColumn(i)); if(defaultvalue == NULL) syntaxError(n->child(0),SQL_NODEFAULT_OR_NULLALLOWED,_T("Column <%s> has no default-value or null-allowed"),table.getColumn(i).m_name.cstr()); else icemap.add(InsertColumnExpression(table,i,defaultvalue)); } } } } if(ok()) { // icemap.size == tableDef.colcount. i.e all columns has an expression int hostvarcounter = 0; for(UINT i = 0; i < icemap.size(); i++) { findHostVarIndex(icemap[i].m_expr,hostvarcounter); } } if(ok()) { for(UINT i = 0; i < icemap.size(); i++) checkExpressionType(icemap[i]); } if(ok()) { m_code.appendIns2(CODETUPINIT,0,table.getColumnCount()); for(UINT i = 0; i < icemap.size(); i++) { bool dummy; genExpression(reduceExpression(icemap[i].m_expr,dummy)); m_code.appendIns2(CODEPOPTUP,0,icemap[i].m_colIndex); } m_code.appendIns0(CODETRBEGIN); m_code.appendIns1(CODEPUSHCONST,m_code.appendConst(table.getSequenceNo())); m_code.appendIns1(CODETUPINSERT,0); m_code.appendIns0(CODETRCOMMIT); } #ifdef TRACECOMP m_code.dump(); #endif // if(ok()) { // FILE *dmp = FOPEN(_T("fisk"),_T("w")); // for(int i = 0; i < icemap.size(); i++) // icemap[i].dump(dmp); // m_code.dump(dmp); // fclose(dmp); // } }
void BlockSyntaxNode::addSuccessors(SyntaxNode *root, std::vector<SyntaxNode *> &successors) { for (unsigned i = 0; i < statements.size(); i++) { if (statements[i]->isBlock()) { //BlockSyntaxNode *b = (BlockSyntaxNode*)statements[i]; // can move previous statements into this block if (i > 0) { std::cerr << "successor: move previous statement into block" << std::endl; SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); BlockSyntaxNode *b1 = (BlockSyntaxNode *)this->clone(); BlockSyntaxNode *nb = (BlockSyntaxNode *)b1->getStatement(i); b1 = (BlockSyntaxNode *)b1->replace(statements[i - 1], NULL); nb->prependStatement(statements[i - 1]->clone()); n = n->replace(this, b1); successors.push_back(n); //PRINT_BEFORE_AFTER } } else { if (statements.size() != 1) { // can replace statement with a block containing that statement std::cerr << "successor: replace statement with a block containing the statement" << std::endl; BlockSyntaxNode *b = new BlockSyntaxNode(); b->addStatement(statements[i]->clone()); SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); n = n->replace(statements[i], b); successors.push_back(n); //PRINT_BEFORE_AFTER } } // "jump over" style of if-then if (i < statements.size() - 2 && statements[i]->isBranch()) { SyntaxNode *b = statements[i]; if (b->getOutEdge(root, 0) == statements[i + 2] && (statements[i + 1]->getOutEdge(root, 0) == statements[i + 2] || statements[i + 1]->endsWithGoto())) { std::cerr << "successor: jump over style if then" << std::endl; BlockSyntaxNode *b1 = (BlockSyntaxNode *)this->clone(); b1 = (BlockSyntaxNode *)b1->replace(statements[i + 1], NULL); IfThenSyntaxNode *nif = new IfThenSyntaxNode(); Exp *cond = b->getBB()->getCond(); cond = new Unary(opLNot, cond->clone()); cond = cond->simplify(); nif->setCond(cond); nif->setThen(statements[i + 1]->clone()); nif->setBB(b->getBB()); b1->setStatement(i, nif); SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); n = n->replace(this, b1); successors.push_back(n); //PRINT_BEFORE_AFTER } } // if then else if (i < statements.size() - 2 && statements[i]->isBranch()) { SyntaxNode *tThen = statements[i]->getOutEdge(root, 0); SyntaxNode *tElse = statements[i]->getOutEdge(root, 1); assert(tThen && tElse); if (((tThen == statements[i + 2] && tElse == statements[i + 1]) || (tThen == statements[i + 1] && tElse == statements[i + 2])) && tThen->getNumOutEdges() == 1 && tElse->getNumOutEdges() == 1) { SyntaxNode *else_out = tElse->getOutEdge(root, 0); SyntaxNode *then_out = tThen->getOutEdge(root, 0); if (else_out == then_out) { std::cerr << "successor: if then else" << std::endl; SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); n = n->replace(tThen, NULL); n = n->replace(tElse, NULL); IfThenElseSyntaxNode *nif = new IfThenElseSyntaxNode(); nif->setCond(statements[i]->getBB()->getCond()->clone()); nif->setBB(statements[i]->getBB()); nif->setThen(tThen->clone()); nif->setElse(tElse->clone()); n = n->replace(statements[i], nif); successors.push_back(n); //PRINT_BEFORE_AFTER } } } // pretested loop if (i < statements.size() - 2 && statements[i]->isBranch()) { SyntaxNode *tBody = statements[i]->getOutEdge(root, 0); SyntaxNode *tFollow = statements[i]->getOutEdge(root, 1); assert(tBody && tFollow); if (tBody == statements[i + 1] && tFollow == statements[i + 2] && tBody->getNumOutEdges() == 1 && tBody->getOutEdge(root, 0) == statements[i]) { std::cerr << "successor: pretested loop" << std::endl; SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); n = n->replace(tBody, NULL); PretestedLoopSyntaxNode *nloop = new PretestedLoopSyntaxNode(); nloop->setCond(statements[i]->getBB()->getCond()->clone()); nloop->setBB(statements[i]->getBB()); nloop->setBody(tBody->clone()); n = n->replace(statements[i], nloop); successors.push_back(n); //PRINT_BEFORE_AFTER } } // posttested loop if (i > 0 && i < statements.size() - 1 && statements[i]->isBranch()) { SyntaxNode *tBody = statements[i]->getOutEdge(root, 0); SyntaxNode *tFollow = statements[i]->getOutEdge(root, 1); assert(tBody && tFollow); if (tBody == statements[i - 1] && tFollow == statements[i + 1] && tBody->getNumOutEdges() == 1 && tBody->getOutEdge(root, 0) == statements[i]) { std::cerr << "successor: posttested loop" << std::endl; SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); n = n->replace(tBody, NULL); PostTestedLoopSyntaxNode *nloop = new PostTestedLoopSyntaxNode(); nloop->setCond(statements[i]->getBB()->getCond()->clone()); nloop->setBB(statements[i]->getBB()); nloop->setBody(tBody->clone()); n = n->replace(statements[i], nloop); successors.push_back(n); //PRINT_BEFORE_AFTER } } // infinite loop if (statements[i]->getNumOutEdges() == 1 && statements[i]->getOutEdge(root, 0) == statements[i]) { std::cerr << "successor: infinite loop" << std::endl; SyntaxNode *n = root->clone(); n->setDepth(root->getDepth() + 1); InfiniteLoopSyntaxNode *nloop = new InfiniteLoopSyntaxNode(); nloop->setBody(statements[i]->clone()); n = n->replace(statements[i], nloop); successors.push_back(n); PRINT_BEFORE_AFTER } statements[i]->addSuccessors(root, successors); }
int BlockSyntaxNode::evaluate(SyntaxNode *root) { #if DEBUG_EVAL if (this == root) std::cerr << "begin eval =============" << std::endl; #endif if (pbb) return 1; int n = 1; if (statements.size() == 1) { SyntaxNode *out = statements[0]->getOutEdge(root, 0); if (out->getBB() != NULL && out->getBB()->getNumInEdges() > 1) { #if DEBUG_EVAL std::cerr << "add 15" << std::endl; #endif n += 15; } else { #if DEBUG_EVAL std::cerr << "add 30" << std::endl; #endif n += 30; } } for (unsigned i = 0; i < statements.size(); i++) { n += statements[i]->evaluate(root); if (statements[i]->isGoto()) { if (i != statements.size() - 1) { #if DEBUG_EVAL std::cerr << "add 100" << std::endl; #endif n += 100; } else { #if DEBUG_EVAL std::cerr << "add 50" << std::endl; #endif n += 50; } } else if (statements[i]->isBranch()) { SyntaxNode *loop = root->getEnclosingLoop(this); std::cerr << "branch " << statements[i]->getNumber() << " not in loop" << std::endl; if (loop) { std::cerr << "branch " << statements[i]->getNumber() << " in loop " << loop->getNumber() << std::endl; // this is a bit C specific SyntaxNode *out = loop->getOutEdge(root, 0); if (out && statements[i]->getOutEdge(root, 0) == out) { std::cerr << "found break" << std::endl; n += 10; } if (statements[i]->getOutEdge(root, 0) == loop) { std::cerr << "found continue" << std::endl; n += 10; } } else { #if DEBUG_EVAL std::cerr << "add 50" << std::endl; #endif n += 50; } } else if (i < statements.size() - 1 && statements[i]->getOutEdge(root, 0) != statements[i + 1]) { #if DEBUG_EVAL std::cerr << "add 25" << std::endl; std::cerr << statements[i]->getNumber() << " -> " << statements[i]->getOutEdge(root, 0)->getNumber() << " not " << statements[i + 1]->getNumber() << std::endl; #endif n += 25; } } #if DEBUG_EVAL if (this == root) std::cerr << "end eval = " << n << " =============" << std::endl; #endif return n; }
SymVar* Parser::ParseDeclarator(SymType* type, bool parseParams) { SymVar* result = NULL; //pointer while (*lexer.Peek() == MULTIPLICATION) { type = new SymTypePointer(type); lexer.Get(); } //direct-declarator if (*lexer.Peek() == ROUND_LEFT_BRACKET) { lexer.Get(); result = ParseDeclarator(type); Expected(lexer.Get()->GetSubType(), ROUND_RIGHT_BRACKET); return result; } Expected(parseParams || *lexer.Peek() == IDENTIFIER, "exepcted an identifier"); if (parseParams && *lexer.Peek() != IDENTIFIER) { string n = to_string((long double)counter++); BaseToken* dummy = new BaseToken("abstract-"+n, 0, 0, IDENTIFIER, IDENTIFIER); result = new SymVar(dummy, type); } else { string msg = "redefinition: " + lexer.Peek()->GetText(); Expected(!symStack.Top()->Find(lexer.Peek()->GetText()), &msg[0]); result = new SymVar(lexer.Get(), type); } BaseToken* token = lexer.Peek(); if (*token == SQUARE_LEFT_BRACKET) { lexer.Get(); Expected(*lexer.Peek() != SQUARE_RIGHT_BRACKET, "unknown size"); SyntaxNode* index = ParseExpression(); Expected(*index->token != IDENTIFIER, "expression must have a constant value"); SymType* indexType = index->GetType(); Expected(indexType == intType && indexType->CanConvertTo(intType), "expression must be an integral constant expression"); Expected(lexer.Get()->GetSubType(), SQUARE_RIGHT_BRACKET); int size = dynamic_cast<TokenVal <int> *>(index->token)->GetValue(); result->SetType(new SymTypeArray(size, type)); } else if (*token == ROUND_LEFT_BRACKET) { lexer.Get(); SymTypeFunc* t = new SymTypeFunc(type); t->params->offset = 4; symStack.Push(t->params); ParseParameterList(); symStack.Pop(); if (*lexer.Peek() == FIGURE_LEFT_BRACKET) { parseFunc.push_back(t); t->body = ParseBlock(); parseFunc.pop_back(); } result->SetType(t); } return result; }
SyntaxNode* ActionSymbol::Invoke(const std::vector<void*>& container) { Sym* sym = (Sym*)container[container.size() - argument_.parameters.front()]; SyntaxNode* ans = new SyntaxNode(SyntaxNodeSymbol, sym->ToString()); ans->SetSymbolAddress(sym); return ans; }
SyntaxNode* ActionLiteral::Invoke(const std::vector<void*>& container) { Literal* literal = (Literal*)container[container.size() - argument_.parameters.front()]; SyntaxNode* ans = new SyntaxNode(SyntaxNodeLiteral, literal->ToString()); ans->SetLiteralAddress(literal); return ans; }
SyntaxNode* ActionConstant::Invoke(const std::vector<void*>& container) { Constant* constant = (Constant*)container[container.size() - argument_.parameters.front()]; SyntaxNode* ans = new SyntaxNode(SyntaxNodeConstant, constant->ToString()); ans->SetConstantAddress(constant); return ans; }