Exemple #1
0
std::vector<node> &
_parser::move_next_statement(void)
{
	LOCK_OBJECT(std::recursive_mutex, _parser_lock);

	std::vector<node> statement;

	if(!has_next_statement()) {
		THROW_PARSER_EXCEPTION_WITH_MESSAGE(
			PARSER_EXCEPTION_NO_NEXT_STATEMENT,
			"pos. " << _position
			);
	}

	if(has_next_token()
			&& _position == (_statement.size() - 2)) {

		if(lexer::get_token().get_type() == TOKEN_BEGIN) {
			_advance_token();
		}

		if(has_next_token()) {
			_enumerate_statement(statement);
			_statement.insert(_statement.begin() + (++_position), statement);
		} else {
			++_position;
		}
	} else if(_position < (_statement.size() - 1)) {
		++_position;
	}

	return get_statement();
}
Exemple #2
0
Fichier : main.c Projet : Nilera/OS
int main(int argc, char *argv[])
{
    int buffer_size = 4 * 1024;
    if (argc < 2)
    {
        exit(1);
    }
    buffer_size = atoi(argv[1]);
    if (buffer_size == 0)
    {
        return 0;
    }
    
    char *buffer = safe_malloc(buffer_size + 1);
    
    int end;
    while ((end = has_next_token(buffer, buffer_size)) >= 0)
    {
        char *token = next_token(buffer, buffer_size, end);
        print(token, 2);
        free(token);
    }
    
    free(buffer);
    return 0;
}
Exemple #3
0
/*
 * Parse input and produce binary stream
 * @param stmt_lst statement list
 * @param sym_tbl symbol table
 */
void 
_par::_parse(
	std::vector<std::vector<token_t>> &stmt_lst,
	std::map<std::string, size_t> &sym_tbl
	)
{
	trace(
		PAR_TRACE_ENABLE,
		TRACE_ENTRY,
		"par::parse"
		);

	if(next_token())

		while(has_next_token()) {
			std::vector<token_t> stmt;
			_parse_stmt(
				stmt,
				sym_tbl
				);
			stmt_lst.push_back(stmt);
		}
	trace(
		PAR_TRACE_ENABLE,
		TRACE_EXIT,
		"par::parse"
		);
}
bool Dfa::skip_space(){
    while(has_next_token()){
        char path_char = static_cast<char>(_str[_pos]);
        if(isspace(path_char)) skip_next_char();
        else return true;
    }
    return false;
}
Exemple #5
0
void 
_parser::_advance_token(
	bool expect_eos
	)
{
	if(!expect_eos
			&& !has_next_token()) {
		THROW_PARSER_EXCEPTION_WITH_MESSAGE(
			PARSER_EXCEPTION_UNEXPECTED_END_OF_TOKEN_STREAM,
			lexer::to_string(false)
			);
	} else if(expect_eos
			&& has_next_token()) {
		THROW_PARSER_EXCEPTION_WITH_MESSAGE(
			PARSER_EXCEPTION_EXPECTED_END_OF_TOKEN_STREAM,
			lexer::to_string(false)
			);
	}
	move_next_token();
}
Exemple #6
0
/*
 * Advance to next token
 * @return true on success, false otherwise
 */
bool 
_lex::_next_token(void)
{
	token_t tok;

	if(!has_next_token())
		return false;

	if(_cache_pos < _cache.size() - 1) {
		++_cache_pos;
		_typ = _cache.at(_cache_pos).type;
		_txt = _cache.at(_cache_pos).text;
	} else {
		_enum_token();
		tok.type = _typ;
		tok.text = _txt;
		_cache.push_back(
			tok
			);
		++_cache_pos;
	}

	return true;
}