memgraph/cypher/parser.hpp

50 lines
920 B
C++
Raw Normal View History

#pragma once
2015-10-19 01:44:00 +08:00
#include "cypher.h"
#include "token.hpp"
#include "ast/tree.hpp"
#include "tokenizer/cypher_lexer.hpp"
2015-10-19 01:44:00 +08:00
void* cypher_parserAlloc(void* (*allocProc)(size_t));
void cypher_parser(void*, int, Token*, ast::Ast* ast);
void cypher_parserFree(void*, void(*freeProc)(void*));
namespace cypher
{
class Parser
{
public:
Parser()
{
parser = cypher_parserAlloc(malloc);
}
~Parser()
{
cypher_parserFree(parser, free);
}
ast::Ast parse(Lexer::Tokenizer tokenizer)
{
auto tree = ast::Ast();
std::list<Token> tokens;
do
{
tokens.emplace_back(tokenizer.lookup());
auto& token = tokens.back();
std::cout << token << std::endl;
2015-10-19 01:44:00 +08:00
cypher_parser(parser, token.id, &token, &tree);
} while(tokens.back().id != 0);
return std::move(tree);
}
private:
void* parser;
};
}