#include "src/ast/parser.h"
-#define YYMALLOC malloc
-#define YYFREE free
-
using namespace re2c;
extern "C" {
} // extern "C"
-/* Bison version 1.875 emits a definition that is not working
- * with several g++ version. Hence we disable it here.
- */
-#if defined(__GNUC__)
-#define __attribute__(x)
-#endif
-
static spec_t &find(specs_t &specs, const std::string &name)
{
for (specs_t::iterator i = specs.begin(); i != specs.end(); ++i) {
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 72, 72, 74, 75, 76, 77, 81, 88, 94,
- 97, 101, 101, 104, 108, 112, 116, 123, 130, 137,
- 144, 151, 153, 159, 166, 168, 174, 178, 185, 189,
- 196, 200, 207, 208, 214, 219, 220, 224, 225, 226,
- 230, 231, 242
+ 0, 62, 62, 64, 65, 66, 67, 71, 78, 84,
+ 85, 88, 88, 91, 94, 97, 100, 106, 112, 118,
+ 124, 131, 132, 137, 144, 145, 151, 152, 156, 157,
+ 161, 163, 167, 168, 175, 181, 182, 186, 187, 188,
+ 192, 193, 205
};
#endif
case 7:
{
- if (!context.symtab.insert(std::make_pair(*(yyvsp[-2].str), (yyvsp[-1].regexp))).second) {
- fatal_l(context.input.get_line(), "sym already defined");
- }
- delete (yyvsp[-2].str);
+ if (!context.symtab.insert(std::make_pair(*(yyvsp[-2].str), (yyvsp[-1].regexp))).second) {
+ fatal_l(context.input.get_line(), "sym already defined");
}
+ delete (yyvsp[-2].str);
+}
break;
case 8:
{
- fatal_l(context.input.get_line(),
- "trailing contexts are not allowed in named definitions");
- }
+ fatal_l(context.input.get_line(),
+ "trailing contexts are not allowed in named definitions");
+}
break;
case 9:
- {
- (yyval.str) = (yyvsp[-1].str);
- }
-
- break;
-
- case 10:
-
- {
- (yyval.str) = (yyvsp[0].str);
- }
+ { (yyval.str) = (yyvsp[-1].str); }
break;
case 13:
{
- find(context.specs, "").rules.push_back(ASTRule((yyvsp[-1].regexp), (yyvsp[0].code)));
- }
+ find(context.specs, "").rules.push_back(ASTRule((yyvsp[-1].regexp), (yyvsp[0].code)));
+}
break;
case 14:
{
- find(context.specs, "").defs.push_back((yyvsp[0].code));
- }
+ find(context.specs, "").defs.push_back((yyvsp[0].code));
+}
break;
case 15:
{
- find(context.specs, "").eofs.push_back((yyvsp[0].code));
- }
+ find(context.specs, "").eofs.push_back((yyvsp[0].code));
+}
break;
case 16:
{
- for(CondList::const_iterator i = (yyvsp[-2].clist)->begin(); i != (yyvsp[-2].clist)->end(); ++i) {
- find(context.specs, *i).rules.push_back(ASTRule((yyvsp[-1].regexp), (yyvsp[0].code)));
- }
- delete (yyvsp[-2].clist);
+ for(CondList::const_iterator i = (yyvsp[-2].clist)->begin(); i != (yyvsp[-2].clist)->end(); ++i) {
+ find(context.specs, *i).rules.push_back(ASTRule((yyvsp[-1].regexp), (yyvsp[0].code)));
}
+ delete (yyvsp[-2].clist);
+}
break;
case 17:
{
- for(CondList::const_iterator i = (yyvsp[-2].clist)->begin(); i != (yyvsp[-2].clist)->end(); ++i) {
- find(context.specs, *i).defs.push_back((yyvsp[0].code));
- }
- delete (yyvsp[-2].clist);
+ for(CondList::const_iterator i = (yyvsp[-2].clist)->begin(); i != (yyvsp[-2].clist)->end(); ++i) {
+ find(context.specs, *i).defs.push_back((yyvsp[0].code));
}
+ delete (yyvsp[-2].clist);
+}
break;
case 18:
{
- for(CondList::const_iterator i = (yyvsp[-2].clist)->begin(); i != (yyvsp[-2].clist)->end(); ++i) {
- find(context.specs, *i).eofs.push_back((yyvsp[0].code));
- }
- delete (yyvsp[-2].clist);
+ for(CondList::const_iterator i = (yyvsp[-2].clist)->begin(); i != (yyvsp[-2].clist)->end(); ++i) {
+ find(context.specs, *i).eofs.push_back((yyvsp[0].code));
}
+ delete (yyvsp[-2].clist);
+}
break;
case 19:
{
- for (CondList::const_iterator i = (yyvsp[-1].clist)->begin(); i != (yyvsp[-1].clist)->end(); ++i) {
- find(context.specs, *i).setup.push_back((yyvsp[0].code));
- }
- delete (yyvsp[-1].clist);
+ for (CondList::const_iterator i = (yyvsp[-1].clist)->begin(); i != (yyvsp[-1].clist)->end(); ++i) {
+ find(context.specs, *i).setup.push_back((yyvsp[0].code));
}
+ delete (yyvsp[-1].clist);
+}
break;
case 20:
{
- const AST *r = ast_nil(context.input.get_line(), 0);
- find(context.specs, "0").rules.push_back(ASTRule(r, (yyvsp[0].code)));
- delete (yyvsp[-1].clist);
- }
+ const AST *r = ast_nil(context.input.get_line(), 0);
+ find(context.specs, "0").rules.push_back(ASTRule(r, (yyvsp[0].code)));
+ delete (yyvsp[-1].clist);
+}
break;
case 22:
{
- (yyval.code) = (yyvsp[0].code);
- (yyval.code)->cond = *(yyvsp[-1].str);
- delete (yyvsp[-1].str);
- }
+ (yyval.code) = (yyvsp[0].code);
+ (yyval.code)->cond = *(yyvsp[-1].str);
+ delete (yyvsp[-1].str);
+}
break;
case 23:
{
- (yyval.code) = new Code(context.input.get_fname(), context.input.get_line());
- (yyval.code)->cond = *(yyvsp[0].str);
- delete (yyvsp[0].str);
- }
+ (yyval.code) = new Code(context.input.get_fname(), context.input.get_line());
+ (yyval.code)->cond = *(yyvsp[0].str);
+ delete (yyvsp[0].str);
+}
break;
case 24:
- {
- (yyval.regexp) = ast_cap((yyvsp[0].regexp));
- }
+ { (yyval.regexp) = ast_cap((yyvsp[0].regexp)); }
break;
case 25:
{
- (yyval.regexp) = ast_cat(ast_cap((yyvsp[-2].regexp)),
- ast_cat(ast_tag(context.input.get_line(), 0, NULL, false), (yyvsp[0].regexp)));
- }
-
- break;
-
- case 26:
-
- {
- (yyval.regexp) = (yyvsp[0].regexp);
- }
+ (yyval.regexp) = ast_cat(ast_cap((yyvsp[-2].regexp)),
+ ast_cat(ast_tag(context.input.get_line(), 0, NULL, false), (yyvsp[0].regexp)));
+}
break;
case 27:
- {
- (yyval.regexp) = ast_alt((yyvsp[-2].regexp), (yyvsp[0].regexp));
- }
-
- break;
-
- case 28:
-
- {
- (yyval.regexp) = (yyvsp[0].regexp);
- }
+ { (yyval.regexp) = ast_alt((yyvsp[-2].regexp), (yyvsp[0].regexp)); }
break;
case 29:
- {
- (yyval.regexp) = ast_diff((yyvsp[-2].regexp), (yyvsp[0].regexp));
- }
-
- break;
-
- case 30:
-
- {
- (yyval.regexp) = (yyvsp[0].regexp);
- }
+ { (yyval.regexp) = ast_diff((yyvsp[-2].regexp), (yyvsp[0].regexp)); }
break;
case 31:
- {
- (yyval.regexp) = ast_cat((yyvsp[-1].regexp), (yyvsp[0].regexp));
- }
+ { (yyval.regexp) = ast_cat((yyvsp[-1].regexp), (yyvsp[0].regexp)); }
break;
case 33:
{
- switch((yyvsp[0].op)) {
- case '*': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 0, AST::MANY); break;
- case '+': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 1, AST::MANY); break;
- case '?': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 0, 1); break;
- }
+ switch((yyvsp[0].op)) {
+ case '*': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 0, AST::MANY); break;
+ case '+': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 1, AST::MANY); break;
+ case '?': (yyval.regexp) = ast_iter((yyvsp[-1].regexp), 0, 1); break;
}
+}
break;
case 34:
{
- (yyval.regexp) = ast_iter((yyvsp[-1].regexp), (yyvsp[0].bounds).min, (yyvsp[0].bounds).max);
- }
+ (yyval.regexp) = ast_iter((yyvsp[-1].regexp), (yyvsp[0].bounds).min, (yyvsp[0].bounds).max);
+}
break;
case 41:
{
- symtab_t::iterator i = context.symtab.find(*(yyvsp[0].str));
- if (i == context.symtab.end()) {
- fatal_l(context.input.get_line(),
- "undefined symbol '%s'", (yyvsp[0].str)->c_str());
- }
- (yyval.regexp) = i->second;
- if (ast_need_wrap((yyval.regexp))) {
- (yyval.regexp) = ast_ref((yyval.regexp), *(yyvsp[0].str));
- }
- delete (yyvsp[0].str);
+ symtab_t::iterator i = context.symtab.find(*(yyvsp[0].str));
+ if (i == context.symtab.end()) {
+ fatal_l(context.input.get_line(),
+ "undefined symbol '%s'", (yyvsp[0].str)->c_str());
}
+ (yyval.regexp) = i->second;
+ if (ast_need_wrap((yyval.regexp))) {
+ (yyval.regexp) = ast_ref((yyval.regexp), *(yyvsp[0].str));
+ }
+ delete (yyvsp[0].str);
+}
break;
case 42:
- {
- (yyval.regexp) = ast_cap((yyvsp[-1].regexp));
- }
+ { (yyval.regexp) = ast_cap((yyvsp[-1].regexp)); }
break;
#include "src/ast/parser.h"
-#define YYMALLOC malloc
-#define YYFREE free
-
using namespace re2c;
extern "C" {
} // extern "C"
-/* Bison version 1.875 emits a definition that is not working
- * with several g++ version. Hence we disable it here.
- */
-#if defined(__GNUC__)
-#define __attribute__(x)
-#endif
-
static spec_t &find(specs_t &specs, const std::string &name)
{
for (specs_t::iterator i = specs.begin(); i != specs.end(); ++i) {
%%
spec
- : /* empty */
- | spec TOKEN_CONF { context.input.lex_conf(context.opts); }
- | spec def
- | spec rule
- | spec TOKEN_LINE_INFO
- ;
+: /* empty */
+| spec TOKEN_CONF { context.input.lex_conf(context.opts); }
+| spec def
+| spec rule
+| spec TOKEN_LINE_INFO
+;
def
- : name expr enddef {
- if (!context.symtab.insert(std::make_pair(*$1, $2)).second) {
- fatal_l(context.input.get_line(), "sym already defined");
- }
- delete $1;
+: name expr enddef {
+ if (!context.symtab.insert(std::make_pair(*$1, $2)).second) {
+ fatal_l(context.input.get_line(), "sym already defined");
}
- /* errors */
- | name expr '/' {
- fatal_l(context.input.get_line(),
- "trailing contexts are not allowed in named definitions");
- };
+ delete $1;
+}
+/* errors */
+| name expr '/' {
+ fatal_l(context.input.get_line(),
+ "trailing contexts are not allowed in named definitions");
+};
name
- : TOKEN_ID '=' {
- $$ = $1;
- }
- | TOKEN_FID {
- $$ = $1;
- };
+: TOKEN_ID '=' { $$ = $1; }
+| TOKEN_FID
+;
enddef: ';' | TOKEN_FID_END;
rule
- : trailexpr TOKEN_CODE {
- find(context.specs, "").rules.push_back(ASTRule($1, $2));
- }
-
- | '*' TOKEN_CODE {
- find(context.specs, "").defs.push_back($2);
- }
-
- | '$' TOKEN_CODE {
- find(context.specs, "").eofs.push_back($2);
- }
-
- | TOKEN_CLIST trailexpr ccode {
- for(CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
- find(context.specs, *i).rules.push_back(ASTRule($2, $3));
- }
- delete $1;
+: trailexpr TOKEN_CODE {
+ find(context.specs, "").rules.push_back(ASTRule($1, $2));
+}
+| '*' TOKEN_CODE {
+ find(context.specs, "").defs.push_back($2);
+}
+| '$' TOKEN_CODE {
+ find(context.specs, "").eofs.push_back($2);
+}
+| TOKEN_CLIST trailexpr ccode {
+ for(CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
+ find(context.specs, *i).rules.push_back(ASTRule($2, $3));
}
-
- | TOKEN_CLIST '*' ccode {
- for(CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
- find(context.specs, *i).defs.push_back($3);
- }
- delete $1;
+ delete $1;
+}
+| TOKEN_CLIST '*' ccode {
+ for(CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
+ find(context.specs, *i).defs.push_back($3);
}
-
- | TOKEN_CLIST '$' ccode {
- for(CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
- find(context.specs, *i).eofs.push_back($3);
- }
- delete $1;
+ delete $1;
+}
+| TOKEN_CLIST '$' ccode {
+ for(CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
+ find(context.specs, *i).eofs.push_back($3);
}
-
- | TOKEN_CSETUP TOKEN_CODE {
- for (CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
- find(context.specs, *i).setup.push_back($2);
- }
- delete $1;
+ delete $1;
+}
+| TOKEN_CSETUP TOKEN_CODE {
+ for (CondList::const_iterator i = $1->begin(); i != $1->end(); ++i) {
+ find(context.specs, *i).setup.push_back($2);
}
-
- | TOKEN_CZERO ccode {
- const AST *r = ast_nil(context.input.get_line(), 0);
- find(context.specs, "0").rules.push_back(ASTRule(r, $2));
- delete $1;
- };
+ delete $1;
+}
+| TOKEN_CZERO ccode {
+ const AST *r = ast_nil(context.input.get_line(), 0);
+ find(context.specs, "0").rules.push_back(ASTRule(r, $2));
+ delete $1;
+};
ccode
- : TOKEN_CODE
-
- | TOKEN_CNEXT TOKEN_CODE {
- $$ = $2;
- $$->cond = *$1;
- delete $1;
- }
-
- | TOKEN_CJUMP {
- $$ = new Code(context.input.get_fname(), context.input.get_line());
- $$->cond = *$1;
- delete $1;
- };
+: TOKEN_CODE
+| TOKEN_CNEXT TOKEN_CODE {
+ $$ = $2;
+ $$->cond = *$1;
+ delete $1;
+}
+| TOKEN_CJUMP {
+ $$ = new Code(context.input.get_fname(), context.input.get_line());
+ $$->cond = *$1;
+ delete $1;
+};
trailexpr
- : expr {
- $$ = ast_cap($1);
- } | expr '/' expr {
- $$ = ast_cat(ast_cap($1),
- ast_cat(ast_tag(context.input.get_line(), 0, NULL, false), $3));
- };
-
-expr:
- diff
- {
- $$ = $1;
- }
- | expr '|' diff
- {
- $$ = ast_alt($1, $3);
- }
+: expr { $$ = ast_cap($1); }
+| expr '/' expr {
+ $$ = ast_cat(ast_cap($1),
+ ast_cat(ast_tag(context.input.get_line(), 0, NULL, false), $3));
+};
+
+expr
+: diff
+| expr '|' diff { $$ = ast_alt($1, $3); }
;
-diff:
- term
- {
- $$ = $1;
- }
- | diff '\\' term
- {
- $$ = ast_diff($1, $3);
- }
+diff
+: term
+| diff '\\' term { $$ = ast_diff($1, $3); }
;
-term:
- factor
- {
- $$ = $1;
- }
- | factor term // in POSIX concatenation is right-associative
- {
- $$ = ast_cat($1, $2);
- }
+term
+: factor
+// in POSIX concatenation is right-associative
+| factor term { $$ = ast_cat($1, $2); }
;
factor
- : primary
- | primary closes {
- switch($2) {
- case '*': $$ = ast_iter($1, 0, AST::MANY); break;
- case '+': $$ = ast_iter($1, 1, AST::MANY); break;
- case '?': $$ = ast_iter($1, 0, 1); break;
- }
- } | primary TOKEN_CLOSESIZE {
- $$ = ast_iter($1, $2.min, $2.max);
- };
+: primary
+| primary closes {
+ switch($2) {
+ case '*': $$ = ast_iter($1, 0, AST::MANY); break;
+ case '+': $$ = ast_iter($1, 1, AST::MANY); break;
+ case '?': $$ = ast_iter($1, 0, 1); break;
+ }
+}
+| primary TOKEN_CLOSESIZE {
+ $$ = ast_iter($1, $2.min, $2.max);
+}
+;
closes
- : close
- | closes close { $$ = ($1 == $2) ? $1 : '*'; }
- ;
+: close
+| closes close { $$ = ($1 == $2) ? $1 : '*'; }
+;
close
- : '*' { $$ = '*'; }
- | '+' { $$ = '+'; }
- | '?' { $$ = '?'; }
- ;
+: '*' { $$ = '*'; }
+| '+' { $$ = '+'; }
+| '?' { $$ = '?'; }
+;
primary
- : TOKEN_REGEXP
- | TOKEN_ID {
- symtab_t::iterator i = context.symtab.find(*$1);
- if (i == context.symtab.end()) {
- fatal_l(context.input.get_line(),
- "undefined symbol '%s'", $1->c_str());
- }
- $$ = i->second;
- if (ast_need_wrap($$)) {
- $$ = ast_ref($$, *$1);
- }
- delete $1;
- } | '(' expr ')' {
- $$ = ast_cap($2);
- };
+: TOKEN_REGEXP
+| TOKEN_ID {
+ symtab_t::iterator i = context.symtab.find(*$1);
+ if (i == context.symtab.end()) {
+ fatal_l(context.input.get_line(),
+ "undefined symbol '%s'", $1->c_str());
+ }
+ $$ = i->second;
+ if (ast_need_wrap($$)) {
+ $$ = ast_ref($$, *$1);
+ }
+ delete $1;
+}
+| '(' expr ')' { $$ = ast_cap($2); }
+;
%%