void Highlighter::highlightImport(Scanner &scanner) { FormatToken tk; while ((tk = scanner.read()).format() != Format_EndOfBlock) { Format format = tk.format(); if (tk.format() == Format_IDENTIFIER) format = Format_IMPORTED_MODULE; setFormat(tk.begin(), tk.length(), _formats[format]); } }
Inst parseMnemoGcnAtomic(unsigned opCode, Scanner& scanner, Brigantine& bw, int*) { unsigned const atomicOperation = scanner.eatToken(EMAtomicOp); OptionalU const segment = scanner.tryEatToken(EMSegment); unsigned const memoryOrder = scanner.eatToken(EMMemoryOrder); unsigned const memoryScope = scanner.eatToken(EMMemoryScope); OptionalU const equivClass = tryParseEquiv(scanner); unsigned const type = scanner.eatToken(EMType); scanner.eatToken(EMNone); InstAtomic res = bw.addInst<InstAtomic>(opCode,type); res.atomicOperation() = atomicOperation; res.segment() = BrigSegment(segment.isInitialized() ? segment.value() : BRIG_SEGMENT_AMD_GCN); res.equivClass() = equivClass.isInitialized() ? equivClass.value() : 0; res.memoryOrder() = memoryOrder; res.memoryScope() = memoryScope; return res; }
void take_cloud(Scanner& scanner) { cuda::DeviceArray<Point> cloud = scanner.tsdf().fetchCloud(cloud_buffer); cuda::DeviceArray<Normal> normal; cuda::DeviceArray<RGB> color; scanner.tsdf().fetchNormals(cloud, normal); //scanner.tsdf().fetchTangentColors(cloud, color); scanner.tsdf().fetchVertexColors(cloud, color); cv::Mat cloud_host(1, (int)cloud.size(), CV_32FC4); cv::Mat normal_host(1, (int)normal.size(), CV_32FC4); cv::Mat color_host(1, (int)cloud.size(), CV_8UC4); cloud.download(cloud_host.ptr<Point>()); normal.download(normal_host.ptr<Normal>()); color.download(color_host.ptr<RGB>()); viz.showWidget("Colored Cloud", cv::viz::WCloud(cloud_host, color_host, normal_host)); }
bool LineParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner) { if (mAllowExpression && mState==BeginState) { scanner.putbackInt (value, loc); parseExpression (scanner, loc); return true; } return Parser::parseInt (value, loc, scanner); }
void LuaHighlighter::highlightImport(Scanner& scanner) { FormatToken tk; while((tk = scanner.read()).format() != Format_EndOfBlock) { Format format = tk.format(); if(format == Format_Identifier) format = Format_RequiredModule; setFormat(tk.begin(), tk.length(), formatForCategory(format)); } }
int main( int argc, char* argv[] ) { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); #endif /* freopen("input-nn.txt","w",stdout); cout<<1<<endl; int n=100000; cout<<n<<endl; set<pii> s; rep(i,n){ int x=rand(); int y=rand(); pii p=mp(x,y); if(s.count(p)){i--; continue;} s.insert(p); cout<<x<<" "<<y<<endl; } exit(0); */ Scanner sc; int testCases = sc.nextInt(); for(int testCase=1;testCase<=testCases;testCase++){ int n = sc.nextInt(); vpii p(n); rep(i,n){ p[i].first = sc.nextInt(); p[i].second= sc.nextInt(); } buildTree(0, n, &(vpii(p)[0])); //fprintf(stderr,"time=%.3lfsec\n",0.001*(clock()-start)); rep(i,n){ findNearestNeighbour(n, p[i].first, p[i].second); printf("%lld\n", closestDist); }
int main(int argc, const char* argv[]) { std::string userInput; // Variable to hold user input Scanner *scanner = new Scanner(); const int NUMBER_OF_FILES = 2; string testFiles[NUMBER_OF_FILES] = { "test.txt", "test1.txt" }; fstream sourceFile; PreProcessor *preProcessor = new PreProcessor(); Parser *parser = new Parser(); if (argc > 1) { ProcessCommands(std::string(argv[1])); string temp = argv[1]; if (temp.compare("-h") != 0 && ProcessCommands(temp)) { Load(argv[1], sourceFile); scanner->Load(preProcessor->Process(sourceFile)); parser->Parse(scanner->Tokenize()); parser->PrintReport(); } } else { for (int i = 0; i < NUMBER_OF_FILES; i++) { Load(testFiles[i], sourceFile); scanner->Load(preProcessor->Process(sourceFile)); parser->Parse(scanner->Tokenize()); parser->PrintReport(); } } do { std::cout << ">> "; getline(std::cin, userInput); if (userInput.compare("-h") != 0 && ProcessCommands(userInput)) { scanner->Load(userInput); scanner->Tokenize(); scanner->PrintReport(); } } while (ProcessCommands(userInput)); delete preProcessor, scanner, parser; return 0; }
void save_mesh(Scanner& scanner) { cuda::DeviceArray<Point> cloud = scanner.tsdf().fetchCloud(cloud_buffer); cuda::DeviceArray<RGB> tangent_color; cuda::DeviceArray<RGB> vertex_color; scanner.tsdf().fetchVertexColors(cloud, vertex_color); scanner.tsdf().fetchTangentColors(cloud, tangent_color); cv::Mat cloud_host(1, (int)cloud.size(), CV_32FC4); cv::Mat vertex_color_host(1, (int)vertex_color.size(), CV_8UC4); cv::Mat tangent_color_host(1, (int)tangent_color.size(), CV_8UC4); cloud.download(cloud_host.ptr<Point>()); vertex_color.download(vertex_color_host.ptr<RGB>()); tangent_color.download(tangent_color_host.ptr<RGB>()); cv::viz::writeCloud("model_color.ply", cloud_host, vertex_color_host); cv::viz::writeCloud("model_tangent.ply", cloud_host, tangent_color_host); combine_mesh(); }
int main() { Scanner scanner; if (!scanner.scan()) { std::cout << "scan fail" << std::endl; std::cout << scanner.get_root() << std::endl; return 0; } std::map<std::string, std::string> uri_class_table = scanner.get_uri_class_table(); std::map<std::pair<std::string, std::string>, std::string> uri_method_table = scanner.get_uri_method_table(); std::map<std::string, std::string>::iterator iter = uri_class_table.begin(); std::map<std::pair<std::string, std::string>, std::string>::iterator it = uri_method_table.begin(); for (; iter != uri_class_table.end(); iter++) std::cout << "URI:" << iter->first << "\tCLASS:" << iter->second << std::endl; for (; it != uri_method_table.end(); it++) std::cout << "PATH: " << it->first.first << " METHOD: " << it->first.second << " FUNCTION:" << it->second << std::endl; }
void hornclause(Scanner & s) { if (s.Peek().token_type == TOKENS::LABEL) { head(s); x_1(s); } else { oops("hornclause", s, "LABEL"); } }
int CodeFormatter::tokenizeBlock(const QTextBlock &block) { int startState = loadLexerState(block.previous()); if (block.blockNumber() == 0) startState = 0; Q_ASSERT(startState != -1); Scanner tokenize; tokenize.setScanComments(true); m_currentLine = block.text(); // to determine whether a line was joined, Tokenizer needs a // newline character at the end m_currentLine.append(QLatin1Char('\n')); m_tokens = tokenize(m_currentLine, startState); const int lexerState = tokenize.state(); QTextBlock saveableBlock(block); saveLexerState(&saveableBlock, lexerState); return lexerState; }
void body(Scanner & s) { if (s.Peek().token_type == TOKENS::LABEL) { predicate(s); x_2(s); } else { oops("body", s, "LABEL"); } }
void predicate(Scanner & s) { if (s.Peek().token_type == TOKENS::LABEL) { name(s); x_3(s); } else { oops("predicate", s, "LABEL"); } }
void head(Scanner & s) { if (s.Peek().token_type == TOKENS::LABEL) { predicate(s); x_6(s); } else { oops("head", s, "LABEL"); } }
string CompiledModelGenerator::substituteTerms(const string& reactionName, const string& inputEquation, bool bFixAmounts) { string equation = cleanEquation(inputEquation); if (equation.size() < 1) { return string("0"); } Scanner s; stringstream ss; ss<<equation; s.AssignStream(ss); s.startScanner(); s.nextToken(); CodeBuilder sb; try { while (s.token() != CodeTypes::tEndOfStreamToken) { substituteToken(reactionName, bFixAmounts, s, sb); s.nextToken(); } } catch (const Exception& e) { throw Exception(e.Message()); } return sb.ToString(); }
string compile() { // tokenize it: cout << "\nListing Source code:\n\n"<< sourceCode << "\n\n"; Scanner scanner; TokenList* list = scanner.scan(sourceCode); cout << "\n\nTokens:\n" << *list; // now parse the tokenlist into a syntax tree ParseTableReader parserTableReader; Parser* p = parserTableReader.createParser(list, serializedParseTable); cout << "\nParsing tokenlist now:\n"; string ret = ""; try{ SyntaxTree* syntaxtree = p->parse(); cout << "\n\nSyntaxTree created:\n" << *syntaxtree; cout << "\n\nGenerating AST:\n"; ASTGenerator astGen(syntaxtree); AST::CodeProgram* p = astGen.generate(); ret = p->code(); cout << "Compiled ASM:\n" << ret << endl; }catch(GrammarException* ex){ cout << "\n\nGrammarException: " << ex->what() << "\n"; } return ret; }
// Term -> ; Statement Term | Epsolon void Parser::Term() { //cout<< tokenToString(scanner.nextToken()) <<endl; switch (scanner.nextToken()) { case T_SEMICOLON: //; { scanner.eatToken(T_SEMICOLON); Statement(); if (scanner.nextToken() == T_SEMICOLON) Term(); //Term(); break; } case T_EOF: break; default: { parseError(scanner.lineNumber(), scanner.nextToken()); break; } } }
int main(int argc,char* argv[]) { std::cout << "\n\n Analyzing from Base Pacakge : " << "Main\n " << std::string(21,'=') << std::endl; Scanner sc; sc.ScanPackageRecurse("Main"); std::vector<std::string> files = sc.GetFiles(); std::cout << "\n\n Scanning from Base Pacakge : " << "Main\n " << std::string(21,'=') << std::endl; std::vector<std::string>::iterator it; for (it=files.begin(); it!=files.end(); it++) std::cout << "\n " << *it; std::cout << "\n "; }
void bingoGetName (Scanner &scanner, Array<char> &result) { QS_DEF(Array<char>, str); bool single_line = Scanner::isSingleLine(scanner); result.clear(); if (single_line) { scanner.readLine(str, true); int idx = str.find('|'); int idx2 = 0; if (idx >= 0) { int tmp = str.find(idx + 1, str.size(), '|'); if (tmp > 0) idx2 = tmp + 1; } BufferScanner scan2(str.ptr() + idx2); while (!scan2.isEOF()) { if (isspace(scan2.readChar())) break; } scan2.skipSpace(); if (!scan2.isEOF()) scan2.readLine(result, false); } else { scanner.readLine(result, false); if (result.size() >= 4 && strncmp(result.ptr(), "$RXN", 4) == 0) scanner.readLine(result, false); } }
int main( int argc, char* argv[] ) { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif Scanner sc; int tc = sc.nextInt(); while(tc--){ int m = sc.nextInt(); int n = sc.nextInt(); int s=n+m; //source node int t=n+m+1;//sink node graphClear(n+m+2);//total nodes are n+m+2 rep(i,m) { int a=sc.nextInt(); addEdge(s, i, a, 0);//addEdge(source,destination,capacity,cost) } rep(j,n) { int b=sc.nextInt(); addEdge(m+j, t, b, 0);//addEdge(source,destination,capacity,cost) }
int main(int argc, char* argv[]) { string inputFile = argv[1]; string outputFile = argv[2]; ofstream myOutputFile; myOutputFile.open(outputFile.data()); if(myOutputFile){ try{ Scanner scanner = Scanner(inputFile.data()); vector<Token> tokenList = scanner.getTokens(); Parser parser(tokenList); DatalogProgram dlp = parser.getData(); Driver driver = Driver(); driver.run(dlp); myOutputFile << driver.toString(); } catch(string &e){ myOutputFile << "Failure!" << endl << "\t" << e << endl; } catch(int &e){ myOutputFile << "Error on line: " << e; } } else myOutputFile << "Cannot open " + outputFile + " for writing" << endl; myOutputFile.close(); }
int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif Scanner sc; int V1 = sc.nextInt(); int V2 = sc.nextInt(); init(V1, V2); int e = sc.nextInt(); while(e--){ int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; addEdge(u, v); } printf("%d\n", maxMatching()); return 0; }
TokenSequence* Parser::composeTable(char* filename) { TokenSequence* sequence = new TokenSequence(10, 10); Token* singulum = nullptr; Symboltable* table = new Symboltable(); Scanner* scanner = new Scanner(filename, table); std::cout << "Initialization works\n"; do { std::cout << "debuging *** Parser::composeTable DO-STRT" << std::endl; singulum = scanner->nextToken(); if (singulum != nullptr) { if (singulum->getType() == Syntax::PROH_Z) { std::cerr << "error line " << singulum->getLine() << " column " << singulum->getColumn() << ": syntax error type 1 (unsupported token)\n"; exit(1); } std::cout << "crashing?\n"; sequence->add(singulum, false); } std::cout << "debuging *** Parser::composeTable DO-END" << std::endl; } while(singulum != nullptr); std::cout << "Scanning works\n"; return sequence; }
bool ControlParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner) { if (mState==StartState) { if (keyword==Scanner::K_if || keyword==Scanner::K_elseif) { if (keyword==Scanner::K_elseif) getErrorHandler().warning ("elseif without matching if", loc); mExprParser.reset(); scanner.scan (mExprParser); mState = IfEndState; return true; } else if (keyword==Scanner::K_while) { mExprParser.reset(); scanner.scan (mExprParser); mState = WhileEndState; return true; } } else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState || mState==IfElseJunkState) { if (parseIfBody (keyword, loc, scanner)) return true; } else if (mState==WhileBodyState) { if ( parseWhileBody (keyword, loc, scanner)) return true; } return Parser::parseKeyword (keyword, loc, scanner); }
int main(int argc, char* argv[]) { string inputfile = argv[1]; string outputfile = argv[2]; ifstream in; in.open(argv[1]); ofstream out; out.open(argv[2]); Scanner scanner; while(!in.eof()) { scanner.scan(in, out); if(scanner.final == true) { break; } } for(unsigned int i = 0; i < scanner.tokens.size(); i++) { Token temp = scanner.tokens[i]; //out << "(" << temp.getKind() << "," << temp.getValue() << "," << temp.getLine() << ")\n"; } if(scanner.final == true) { //out << "Input Error on line " << scanner.number << "\n"; } else { //out << "Total Tokens = " << scanner.tokens.size() << endl; } try {
bool Table::Compact_ColumnWalk(LinkedListEntry *Entry, int id, void *data1, void *data2) { ColumnField *field = static_cast<ColumnField *>(Entry); Table *ctable = (Table *)data1; LinkedList *sublist = (LinkedList *)data2; ColumnField *ccol = ctable->NewColumn(field->GetFieldId(), field->GetFieldName(), field->GetDataType(), field->GetUnique()); if (field->GetUnique()) { Scanner *subscan = ccol->GetUniqueDataScanner(); if (subscan != NULL) { Table *subtable = subscan->GetTable(); if (subtable != NULL) { StringField *f = new StringField(); f->SetString(subtable->Name); sublist->AddEntry(f, 1); f = new StringField(); f->SetString(subtable->IdxName); sublist->AddEntry(f, 1); } } } return true; }
bool SyntaxParserImpl::parse() { vector<YYSTYPE> valueStack; vector<int> stateStack; stateStack.push_back(0); GotoTable *gotoTable = LALRParser::instance()->getGotoTable(); ActionTable* actionTable = LALRParser::instance()->getActionTable(); bool useLastToken = false; Token t; for (;;) { if (!m_scanner->getNext(t)) { if (useLastToken) break; else { useLastToken = true; t.type = ESS_Term_Begin; } } for (;;) { Action act = actionTable->getAction(stateStack.back(), t.type); if (act.type == Action::T_Shift) { if (t.type == ESS_Term_Begin) { stateStack.clear(); break; } stateStack.push_back(act.value); valueStack.push_back(yylval); break; } else if (act.type == Action::T_Reduce) { auto& body = getProductBody(act.value); YYSTYPE head; g_lrproductionHead = &head; g_lrproductionBody = body.empty() ? &head : &valueStack[valueStack.size() - body.size()]; getProductionAction(act.value)(); valueStack.erase(valueStack.end() - body.size(), valueStack.end()); valueStack.push_back(head); stateStack.erase(stateStack.end() - body.size(), stateStack.end()); int nstate = gotoTable->getNextState(stateStack.back(), getProductHead(act.value)); stateStack.push_back(nstate); } else ASSERT(0); } } ASSERT(stateStack.empty()); return true; }
/** * @brief Main Function * @details the quick brown fox jumps over the lazy dog * * @param argc - argument count * @param argv - argument list * @return completion status */ std::string run(std::string in_expression_string) { Scanner scanner; Compiler* compiler; compiler = scanner.execute(in_expression_string); compiler->compile(); std::vector<std::string> variable_names; for(auto a: compiler->literals) { variable_names.push_back(a.name); } QMA algo; std::string result; result = algo.compute_minimum_boolean_expression(compiler->AST_root->TT, variable_names); return result; }
void TypeParser::parseIdentifier(Scanner &scanner, QStack<Info *> &stack, QString &array, bool in_array, bool &colon_prefix) { if (in_array) { array = scanner.identifier(); } else if (colon_prefix || stack.top()->qualified_name.isEmpty()) { stack.top()->qualified_name << scanner.identifier(); colon_prefix = false; } else { //stack.top()->qualified_name.last().append(" " + scanner.identifier()); QString identifier = scanner.identifier(); QString &name = stack.top()->qualified_name.last(); bool set = false; if (identifier != "int") set = true; // TODO: this handles only one case if (name != "short" && !name.endsWith(" short") && name != "long" && !name.endsWith(" long")) { set = true; } if (set) name.append(" " + identifier); } }
void Printer::printLexicalTable(Scanner& scanner, bool withTable) { _cellSeparator = withTable ? '|' : ' '; int t_len = withTable ? TOKEN_TEXT_LEN + TOKEN_TYPE_LEN + TOKEN_VALUE_LEN + TOKEN_LINE_LEN : 0; string tframe(t_len, '-'); if (withTable) { cout << "Table for " << scanner.fname << endl << endl; tframe = '*' + tframe + '*'; cout << tframe << endl; } printLine("Type", "Line", "Text", "Value"); cout << tframe << endl; TokenPtr token; while (scanner.Next()) { token = scanner.Get(); string type = token->getName(), line = to_string(token->line), text = token->text, value = token->getValue(); printLine(type, line, text, value); cout << tframe << endl; } }