当前位置: 首页>>代码示例>>C++>>正文


C++ Scanner::next方法代码示例

本文整理汇总了C++中Scanner::next方法的典型用法代码示例。如果您正苦于以下问题:C++ Scanner::next方法的具体用法?C++ Scanner::next怎么用?C++ Scanner::next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner::next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse

void Parser::parse()
{
	int id_ctr = 0;
	scan->next();
	while(scan->type != -1)
	{
		Symbol s;
		s.scope = std::string("scope");
		s.symid = std::to_string(id_ctr);
		s.value = std::string(scan->val);
		s.kind = std::to_string(scan->type);
		s.data["key1"] = std::string("val1");
		s.data["key2"] = std::string("val2");
		symbols[s.symid] = s;

		scan->next();
		id_ctr++;
	}

	for(std::pair<std::string,Symbol> pair : symbols)
	{
		std::cout << "scope " << pair.second.scope << std::endl;
		std::cout << "symid " << pair.second.symid << std::endl;
		std::cout << "value " << pair.second.value << std::endl;
		std::cout << "kind " << pair.second.kind << std::endl;
		for(std::pair<std::string,std::string> datum : pair.second.data)
			std::cout << datum.first << " : " << datum.second << std::endl;
		std::cout << std::endl;
	}
}
开发者ID:apamburn,项目名称:CS4490,代码行数:30,代码来源:Parser.cpp

示例2: initializeTable

/**
 * Initialize Table
 * ================================
 *
 * The following reads in the PEG in the passed filename and converts the
 * grammar specification into a set of tokens for traversal when parsing other files
 * according to said grammar.
 */
void Parser::initializeTable(Scanner& input)
{
    // These regexes are used to read in a custom PEG grammar.
    // Refer to /grammars/arithmetic.peg for a more thorough explanation
    // on the grammar. Note all other terms can be manipulated just
    // by reading in the remainder of a line or reading in words.
    Regex arrowOperator = Regex::fromPool("pparser-arrow", "\\->");
    Regex markedWord = Regex::fromPool("pparser-marked-word", "\\A+'?");

    // On any given line, the first two terminals should be the nonterminal
    // being defined and the arrow operator or we've encountered a comment.
    while(input.peek() != EOF) {

        if(input.peek() == PPARSER_COMMENT) {
            input.readLine();
        } else {

            // First read in nonterminal and find start if possible
            std::string nonterminal = input.next(markedWord);
            if(nonterminal.back() == PPARSER_START) {
                nonterminal.pop_back();
                if(start.empty()) {
                    start = nonterminal;
                } else {
                    throw InvalidGrammar("Multiple starting nonterminals", input.getCurrentState());
                }
            }

            // Can now read in the arrow operator
            input.next(arrowOperator);

            // Rest of line is dedicated to definition
            table[nonterminal] = std::make_shared<Choices>(input);
        }
    }

    // Must have at least one starting nonterminal
    if(start.empty()) {
        throw InvalidGrammar("No starting nonterminal specified");
    }

}
开发者ID:jrpotter,项目名称:sage,代码行数:50,代码来源:Parser.cpp

示例3: s

//  Created by Clayton Minicus on 3/2/16.
//  Copyright © 2016 Clayton Minicus. All rights reserved.
//

#include <stdio.h>

#include "catch.hpp"
#include "scanner.h"

TEST_CASE("scanner scans correctly", "[scanner]") {
    Token t;
    
    // ------------------------------- Empty -----------------------------------
    SECTION("scanner scans empty file correctly") {
        Scanner s("");
        t = s.next();
        REQUIRE(t.to_string() == "[email protected](1:1)");
    }
    
    // ----------------------------- Integers ----------------------------------
    SECTION("scanner scans single digit integers correctly") {
        Scanner s("1");
        t = s.next();
        REQUIRE(t.to_string() == "integer<1>@(1:1)");
    }
    
    SECTION("scanner scans multiple digit integers correctly") {
        Scanner s("12345");
        t = s.next();
        REQUIRE(t.to_string() == "integer<12345>@(1:1)");
    }
开发者ID:cminicus,项目名称:RX-Compiler,代码行数:31,代码来源:scanner_test.cpp


注:本文中的Scanner::next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。