tree-sitter/examples/grammars/arithmetic.cc
Max Brunsfeld 48baf056b4 Store grammars' rules in vectors, not maps
This way, we can keep of the order in which the rules
were given, for resolving reduce/reduce conflicts.
2014-03-24 13:17:38 -07:00

35 lines
1.1 KiB
C++

#include "tree_sitter/compiler.h"
namespace tree_sitter {
namespace examples {
using namespace tree_sitter::rules;
Grammar arithmetic() {
return Grammar({
{ "expression", choice({
seq({
sym("term"),
sym("plus"),
sym("term") }),
sym("term") }) },
{ "term", choice({
seq({
sym("factor"),
sym("times"),
sym("factor") }),
sym("factor") }) },
{ "factor", choice({
sym("variable"),
sym("number"),
seq({
str("("),
err(sym("expression")),
str(")") }) }) },
{ "plus", str("+") },
{ "times", str("*") },
{ "number", pattern("\\d+") },
{ "variable", pattern("[a-zA-Z]+") },
});
}
}
}