summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parse.y56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/parse.y b/src/parse.y
index 33bcb55..e8d26d3 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -15,6 +15,9 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
}
+%extra_arg {__attribute__((unused)) grammar_t *} grammar
+
+
%type SYMBOL {std::string *} str
%destructor SYMBOL delete
@@ -33,33 +36,6 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
%type CHAR {unsigned char} c
-%type namespace {std::vector<std::string> *}
-%destructor namespace delete
-
-%type rhs {rhs_t *}
-%destructor rhs delete
-
-%type variable {var_t *}
-%destructor variable delete
-
-%type action {std::string *}
-%destructor action delete
-
-%type symbol {symbol_t *}
-%destructor symbol delete
-
-%type term {symbol_t *}
-%destructor term delete
-
-%type csymbol {std::string *}
-%destructor csymbol delete
-
-%type consume {bool}
-
-
-%extra_arg {__attribute__((unused)) grammar_t *} grammar
-
-
grammar |=;
grammar |= grammar directive;
@@ -104,6 +80,9 @@ directive |= SYMBOL(lhs) "|=" '(' CHAR(c1) "..." CHAR(c2) ')' ';' {
}
+%type rhs {rhs_t *}
+%destructor rhs delete
+
rhs |= [new rhs_t]
rhs |= rhs(=rhs) symbol(sym) variable(var) {
@@ -123,19 +102,31 @@ rhs |= rhs(=rhs) STRING(str) {
}
+%type variable {var_t *}
+%destructor variable delete
+
variable |= [new var_t]
variable |= '(' consume(consume) csymbol(var) ')'
[new var_t(*var, consume)]
+
+%type consume {bool}
+
consume |= [false]
consume |= '=' [true]
+%type action {std::string *}
+%destructor action delete
+
action |= ';' [new std::string]
action |= BLOCK(=v) [v]
action |= SQBLOCK(v) [new std::string("return " + *v + ";")]
+%type namespace {std::vector<std::string> *}
+%destructor namespace delete
+
namespace |= csymbol(v) [new std::vector<std::string> {*v}]
namespace |= namespace(=ns) "::" csymbol(v) {
ns->push_back(*v);
@@ -143,11 +134,22 @@ namespace |= namespace(=ns) "::" csymbol(v) {
}
+%type symbol {symbol_t *}
+%destructor symbol delete
+
symbol |= SYMBOL(v) [new symbol_t(symbol_t::make_nonterm(*v))]
symbol |= term(=v) [v]
+
+%type term {symbol_t *}
+%destructor term delete
+
term |= SYMBOL_UC(v) [new symbol_t(symbol_t::make_term(*v))]
term |= CHAR(v) [new symbol_t(symbol_t::make_char(v))]
+
+%type csymbol {std::string *}
+%destructor csymbol delete
+
csymbol |= SYMBOL_UC(=v) [v]
csymbol |= SYMBOL(=v) [v]