2014-02-17 12:53:57 -08:00
|
|
|
#include "tree_sitter/compiler.h"
|
2014-03-09 21:37:21 -07:00
|
|
|
#include "compiler/prepare_grammar/prepare_grammar.h"
|
|
|
|
|
#include "compiler/build_tables/build_tables.h"
|
|
|
|
|
#include "compiler/generate_code/c_code.h"
|
|
|
|
|
#include "compiler/prepared_grammar.h"
|
2014-03-27 12:54:54 -07:00
|
|
|
#include "compiler/name_symbols/name_symbols.h"
|
2014-01-11 15:14:17 -08:00
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
2014-04-08 08:19:55 -07:00
|
|
|
using std::pair;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
|
|
pair<string, vector<Conflict>> compile(const Grammar &grammar, std::string name) {
|
2014-03-02 15:07:43 -08:00
|
|
|
auto grammars = prepare_grammar::prepare_grammar(grammar);
|
2014-03-27 12:54:54 -07:00
|
|
|
PreparedGrammar &syntax_grammar = grammars.first;
|
|
|
|
|
PreparedGrammar &lexical_grammar = grammars.second;
|
|
|
|
|
|
2014-04-08 18:47:42 -07:00
|
|
|
auto symbol_names = name_symbols::name_symbols(syntax_grammar, lexical_grammar);
|
|
|
|
|
|
|
|
|
|
auto table_build_result = build_tables::build_tables(syntax_grammar, lexical_grammar, symbol_names);
|
2014-04-08 08:19:55 -07:00
|
|
|
auto tables = table_build_result.first;
|
|
|
|
|
auto conflicts = table_build_result.second;
|
2014-04-14 08:38:11 -07:00
|
|
|
|
2014-03-27 12:54:54 -07:00
|
|
|
ParseTable &parse_table = tables.first;
|
|
|
|
|
LexTable &lex_table = tables.second;
|
|
|
|
|
|
2014-04-08 08:19:55 -07:00
|
|
|
return { generate_code::c_code(name, parse_table, lex_table, symbol_names), conflicts };
|
2014-01-11 15:14:17 -08:00
|
|
|
}
|
|
|
|
|
}
|