2015-12-08 04:51:55 +08:00
|
|
|
#pragma once
|
2015-10-19 01:44:00 +08:00
|
|
|
|
|
|
|
#include "cypher.h"
|
|
|
|
#include "token.hpp"
|
|
|
|
#include "ast/tree.hpp"
|
2016-02-03 07:18:20 +08:00
|
|
|
#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();
|
2016-01-18 07:41:54 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|