本文整理汇总了C++中SymbolList::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolList::push_back方法的具体用法?C++ SymbolList::push_back怎么用?C++ SymbolList::push_back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolList
的用法示例。
在下文中一共展示了SymbolList::push_back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: kill_chains
void Grammar::kill_chains() {
std::vector<SymbolList> temp;
for( auto &nT : non_terminals ) {
SymbolList set;
set.push_back(nT);
for( auto rule : production_rules[get_nt_index(nT)] ) {
if( rule.size() == 1 ) {
if( contains_char(set, rule[0]) ) {
continue;
} else {
set.push_back(rule[0]);
}
}
}
for( auto &ch : set ) {
for( auto rule : production_rules[get_nt_index(ch)] ) {
if( rule.size() == 1 && subset_of(rule, non_terminals) ) {
continue;
} else {
temp.push_back(rule);
}
}
}
production_rules[get_nt_index(nT)] = temp;
temp.clear();
}
}
示例2: trial
void trial( SymbolList & testSet,
SymbolList & notCirc,
SymbolMap & symbolMap
)
{
bool bDone = false;
while (!bDone)
{
bDone = true;
SymbolList::iterator item = testSet.begin();
SymbolList::iterator last = testSet.end();
while (item != last)
{
SymbolList::iterator thisItem = item++;
const Symbol sym = *thisItem;
bool bIsReferedTo = symbolMap.isReferredTo( sym );
bool bRefersTo = symbolMap.refersTo ( sym );
if (!( bIsReferedTo && bRefersTo) )
{
bDone = false;
symbolMap.remove( sym );
testSet.remove( sym );
notCirc.push_back( sym );
}
}
}
}
示例3: cyk
bool Grammar::cyk(const std::string& input) {
unsigned int n = input.size();
SymbolList in_sl;
for( auto ch : input ) {
in_sl.push_back(ch);
}
in_sl = to_pseudo_non_terminals(in_sl);
std::vector<SymbolList> pairs;
for( auto it = in_sl.begin(); it != in_sl.end() - 1; ++it ) {
SymbolList temp_sl;
temp_sl.push_back(*it);
temp_sl.push_back(*( it + 1 ));
pairs.push_back(temp_sl);
}
std::vector<SymbolList> sl_vect;
for( auto t : pairs ) {
SymbolList temp = find_as_list(t);
if( temp.size() == 0 ) {
Symbol temp_sym("empty");
temp.push_back(temp_sym);
}
sl_vect.push_back(temp);
}
for( auto x : sl_vect ) {
for( auto t : x ) {
std::cout << t << '|';
}
std::cout << '\n';
}
return true;
}
示例4: get_reachables
SymbolList Grammar::get_reachables() {
SymbolList reachables;
reachables.push_back(starting_symbol);
SymbolList prev_reachables;
do {
prev_reachables = reachables;
for( auto &ch : prev_reachables ) {
for( auto rule : production_rules[get_nt_index(ch)] ) {
for( auto &symbol : rule ) {
if( contains_char(reachables, symbol) || contains_char(terminals, symbol) ) { continue; }
reachables.push_back(symbol);
}
}
}
} while( prev_reachables != reachables );
return reachables;
}
示例5: intersection
SymbolList intersection(const SymbolList& str1, const SymbolList& str2) {
SymbolList ret;
for( auto &ch : str1 ) {
if( contains_char(str2, ch) ) {
ret.push_back(ch);
}
}
return ret;
}
示例6: createBook
void BookPublisher::createBook (const char* symbol, const char* partId)
{
mBook = new MamdaOrderBook();
// This turns on the generation of deltas at the order book
mBook->generateDeltaMsgs (true);
if (symbol) mBook->setSymbol (symbol);
if (partId) mBook->setPartId (partId);
mBookTime.setToNow();
mBook->setBookTime (mBookTime);
mSymbolList.push_back (symbol);
}
示例7: string_to_symbols
SymbolList string_to_symbols(const std::string& str) {
SymbolList ret;
//std::cout << str << '\n';
std::istringstream iss(str);
std::string tmp;
while( std::getline(iss,tmp, ',') ) {
//std::cout << tmp << '\n';
ret.push_back(Symbol(tmp));
}
return ret;
}
示例8: find_as_list
SymbolList Grammar::find_as_list(const SymbolList& sl) {
SymbolList ret;
for( auto nT : non_terminals ) {
for( auto rule : production_rules[get_nt_index(nT)] ) {
if( rule.size() != 2 ) continue;
if( rule[0] == sl[0] && rule[1] == sl[1] ) {
ret.push_back(nT);
}
}
}
return ret;
}
示例9: evalInitStruct
Type* BaseSemanticWalker::evalInitStruct(const InitStructList& stc) {
SymbolList flist;
InitStructList::const_iterator it;
for (it = stc.begin(); it != stc.end(); ++it) {
flist.push_back(Symbol(it->first->getText(),
it->second,
_symtable->globalScope(),
_symtable->unit(),
it->first->getLine(),
it->first->getColumn()));
}
return _typeBuilder->structType(flist);
}
示例10: pseudo_non_terminals
void Grammar::pseudo_non_terminals() {
auto current = get_first(unite(non_terminals, terminals), 'Q');
SymbolList temp_non_terms = non_terminals;
SymbolList pseudo_non_terms;
unsigned int c = 0;
for( auto T : terminals ) {
SymbolList temp;
temp.push_back(T);
non_terminals.push_back(current);
pseudo_non_terms.push_back(current);
production_rules[get_nt_index(current)].push_back(temp);
//std::cout << current << " " << production_rules[get_nt_index(current)].back() << " " << production_rules[get_nt_index(current)].size() << '\n';
get_next(current, ++c);
}
for( auto nT : temp_non_terms ) {
std::vector<SymbolList> temp_rules;
for( auto rule : production_rules[get_nt_index(nT)] ) {
//std::cout << "rule: " << rule << " => ";
if( rule.size() == 1 ) {
//std::cout << "unchanged\n";
temp_rules.push_back(rule);
continue;
}
for( auto ch : rule ) {
//std::cout << "ch: " << ch << '\n';
if( contains_char(terminals, ch) ) {
unsigned int i = pseudo_non_terms.size();
while( i --> 0 ) {
//std::cout << "while( "<<i<<" --> 0)\n";
auto x = production_rules[get_nt_index(pseudo_non_terms[i])];
//std::cout << production_rules[get_nt_index(pseudo_non_terms[i])][0];
//std::cout << x[0][0] << " =?= " << ch << '\n';
if( ch == x[0][0] ) {
//std::cout << " :: TRUE\n";
break;
}
}
auto t = pseudo_non_terms[i];
replace_first_of(rule, ch, t);
}
}
//std::cout << rule << '\n';
temp_rules.push_back(rule);
}
production_rules[get_nt_index(nT)] = temp_rules;
}
}
示例11: allLookaheadsOf
SymbolSet allLookaheadsOf(const Item & item, const Grammar & grammar)
{
SymbolList followingSymbols = item.rule.remainingSymbolsAfter(item.dottedSymbol);
followingSymbols.push_back({ Symbol::Type::TERMINAL, "" });
SymbolSet allLookaheads;
for(auto & lookahead : item.lookaheads)
{
followingSymbols.back() = lookahead;
auto first = grammar.first(followingSymbols);
allLookaheads.insert(first.begin(), first.end());
}
return allLookaheads;
}
示例12: readSymbolsFromFile
void MamaEntitle::readSymbolsFromFile (void)
{
/* get subjects from file or interactively */
FILE* fp = NULL;
char charbuf[1024];
if (mFilename && mFilename[0] )
{
if ((fp = fopen (mFilename, "r")) == (FILE *)NULL)
{
perror (mFilename);
exit (1);
}
}
else
{
fp = stdin;
}
if (isatty(fileno (fp)))
{
printf ("Enter one symbol per line and terminate with a .\n");
printf ("Symbol> ");
}
while (fgets (charbuf, 1023, fp))
{
/* replace newlines with NULLs */
char *c = charbuf;
/* Input terminate case */
if (*c == '.')
break;
while ((*c != '\0') && (*c != '\n'))
{
c++;
}
*c = '\0';
/* copy the string and subscribe */
mSymbolList.push_back (strdup (charbuf));
if (isatty(fileno (fp)))
{
printf ("Symbol> ");
}
}
}
示例13: those_that_product
SymbolList Grammar::those_that_product(SymbolList& sl) {
SymbolList ret;
for( auto CV : sl ) {
for( auto nT : non_terminals ) {
for( auto rule : production_rules[get_nt_index(nT)] ) {
if( sl.size() != rule.size() ) { continue; }
for( unsigned int i = 0; i < rule.size(); ++i ) {
if( !(sl[i] == rule[i]) ) { break; }
if( i == rule.size() - 1 ) {
ret.push_back(nT);
}
}
}
}
}
return ret;
}
示例14: nominal_test
void LexerTests::nominal_test()
{
cout << "-------------------------------------- Lexer ------------------------------------" << endl;
ifstream ifs("../../tests/files/correct.lt");
//Vérification du fichier
if (!ifs.good())
{
ifs.close();
FAILED(0);
PRINT("Failed to open file...");
return;
}
Lexer lexer(ifs);
SymbolList symbols;
Symbol symbol;
lexer.MoveForward(); // commence à lire en placant la tete de lecture au debut du flux
symbol = lexer.GetNext();
while(symbol.code != S_EOF)
{ if(symbol.code == S_LEXER_ERROR)
{ PRINT("Lexer error encountered...");
break;
}
// on récupère les valeurs
symbols.push_back(symbol);
// on déplace la tête de lecture
lexer.MoveForward();
// on lit le prochain symbole
symbol = lexer.GetNext();
}
symbols.push_back(symbol);
/*
* Programme testé : correct.lt
*
* 1. var a,b;
* 2. const c = 4;
* 3. const d = 6;
* 4. var e;
* 5. a := (c+d)*3-5;
* 6. lire b;
* 7. ecrire a*b;
* 8. e := b+d;
* 9. ecrire e;
*/
SymbolList expectedSymbols;
#define PUSH_SYM(symbolcode, value) expectedSymbols.push_back(Symbol(symbolcode, value));
// ligne 1
PUSH_SYM(S_VAR,"var");PUSH_SYM(S_ID,"a");PUSH_SYM(S_V,",");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PV,";");
// ligne 2
PUSH_SYM(S_CONST,"const");PUSH_SYM(S_ID,"c");PUSH_SYM(S_EQ,"=");PUSH_SYM(S_NUM,"4");PUSH_SYM(S_PV,";");
// ligne 3
PUSH_SYM(S_CONST,"const");PUSH_SYM(S_ID,"d");PUSH_SYM(S_EQ,"=");PUSH_SYM(S_NUM,"6");PUSH_SYM(S_PV,";");
// ligne 4
PUSH_SYM(S_VAR,"var");PUSH_SYM(S_ID,"e");PUSH_SYM(S_PV,";");
// ligne 5
PUSH_SYM(S_ID,"a");PUSH_SYM(S_AFFECT,":=");PUSH_SYM(S_PO,"(");PUSH_SYM(S_ID,"c");PUSH_SYM(S_PLUS,"+");PUSH_SYM(S_ID,"d");PUSH_SYM(S_PF,")");PUSH_SYM(S_MULT,"*");PUSH_SYM(S_NUM,"3");PUSH_SYM(S_MINUS,"-");PUSH_SYM(S_NUM,"5");PUSH_SYM(S_PV,";");
// ligne 6
PUSH_SYM(S_READ,"lire");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PV,";");
// ligne 7
PUSH_SYM(S_WRITE,"ecrire");PUSH_SYM(S_ID,"a");PUSH_SYM(S_MULT,"*");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PV,";");
// ligne 8
PUSH_SYM(S_ID,"e");PUSH_SYM(S_AFFECT,":=");PUSH_SYM(S_ID,"b");PUSH_SYM(S_PLUS,"+");PUSH_SYM(S_ID,"d");PUSH_SYM(S_PV,";");
// ligne 9
PUSH_SYM(S_WRITE,"ecrire");PUSH_SYM(S_ID,"e");PUSH_SYM(S_PV,";");
// eof
PUSH_SYM(S_EOF,"");
// verification de l'adequation des quatres tableaux
// -- on vérifie d'abord la taille
if(symbols.size() != expectedSymbols.size())
{ FAILED(0);
PRINT("Les tailles des tableaux ne correspondent pas !");
PRINT("symbols.size() = " << symbols.size());
PRINT("expectedSymbols.size() = " << expectedSymbols.size());
}
else
{ list<Symbol>::iterator realSymbol = symbols.begin(), expectedSymbol = expectedSymbols.begin();
// ici on peut tester que sur un itérateur car on sait que tous les tableaux font la meme taille
int iter(1);
bool failed(false);
while(realSymbol != symbols.end())
{ // tests de correspondance
if(realSymbol->code != expectedSymbol->code)
{ FAILED(iter);
PRINT("real code = '" << realSymbol->code << "'");
PRINT("expected code = '" << expectedSymbol->code << "'");
failed = true;
break; // sortie du while
}
else if(realSymbol->buf != expectedSymbol->buf)
{ FAILED(iter);
PRINT("real buf = '" << realSymbol->buf << "'");
PRINT("expected buf = '" << expectedSymbol->buf << "'");
failed = true;
break; // sortie du while
}
// incrément des itérateurs
realSymbol++; expectedSymbol++;
iter++;
}
//.........这里部分代码省略.........
示例15: parseCommandLine
void MamaEntitle::parseCommandLine (int argc, const char* argv[])
{
int i = 0;
for (i = 1; i < argc; )
{
if ((strcmp (argv[i], "-S") == 0) ||
(strcmp (argv[i], "-source") == 0))
{
mSource = argv[i + 1];
i += 2;
}
else if (strcmp (argv[i], "-d") == 0)
{
mDictSourceName = argv[i + 1];
i += 2;
}
else if (strcmp (argv[i], "-dict_tport") == 0)
{
mDictTport = argv[i+1];
i += 2;
}
else if (strcmp (argv[i], "-I") == 0)
{
mRequireInitial = 0;
i++;
}
else if ((strcmp (argv[i], "-h") == 0) ||
(strcmp (argv[i], "-?") == 0))
{
usage (0);
i++;
}
else if (strcmp (argv[i], "-s") == 0)
{
mSymbolList.push_back (argv[i + 1]);
i += 2;
}
else if (strcmp (argv[i], "-f") == 0)
{
mFilename = argv[i + 1];
i += 2;
}
else if (strcmp (argv[i], "-1") == 0)
{
mSnapshot = 1;
i++;
}
else if (strcmp (argv[i], "-g") == 0)
{
mGroupSubscription = 1;
i++;
}
else if (strcmp (argv[i], "-q") == 0)
{
mQuietness++;
i++;
}
else if (strcmp (argv[i], "-threads") == 0)
{
mThreads = atoi (argv[i + 1]);
i += 2;
}
else if (strcmp (argv[i], "-tport") == 0)
{
mTport = argv[i+1];
i += 2;
}
else if (strcmp (argv[i], "-v") == 0)
{
if (mMamaLogLevel == MAMA_LOG_LEVEL_WARN)
{
mMamaLogLevel = MAMA_LOG_LEVEL_NORMAL;
mama_enableLogging (stderr, MAMA_LOG_LEVEL_NORMAL);
}
else if (mMamaLogLevel == MAMA_LOG_LEVEL_NORMAL)
{
mMamaLogLevel = MAMA_LOG_LEVEL_FINE;
mama_enableLogging (stderr, MAMA_LOG_LEVEL_FINE);
}
else if (mMamaLogLevel == MAMA_LOG_LEVEL_FINE)
{
mMamaLogLevel = MAMA_LOG_LEVEL_FINER;
mama_enableLogging (stderr, MAMA_LOG_LEVEL_FINER);
}
else
{
mMamaLogLevel = MAMA_LOG_LEVEL_FINEST;
mama_enableLogging (stderr, MAMA_LOG_LEVEL_FINEST);
}
i++;
}
else if (strcmp ("-m", argv[i]) == 0)
{
mMiddleware = argv[i+1];
i += 2;
}
else if (strcmp (argv[i], "-V") == 0)
{
if (mSubscLogLevel == MAMA_LOG_LEVEL_NORMAL)
//.........这里部分代码省略.........