diff options
Diffstat (limited to 'src/parse/parser.ypp')
-rw-r--r-- | src/parse/parser.ypp | 127 |
1 files changed, 71 insertions, 56 deletions
diff --git a/src/parse/parser.ypp b/src/parse/parser.ypp index 1c476953..bf746b3b 100644 --- a/src/parse/parser.ypp +++ b/src/parse/parser.ypp @@ -1,25 +1,40 @@ %{ +#include "src/util/c99_stdint.h" #include <assert.h> -#include <time.h> -#include <string.h> +#include <stddef.h> #include <stdlib.h> -#include <iostream> +#include <limits> +#include <list> +#include <map> #include <set> +#include <string> +#include <utility> +#include <vector> -#include "config.h" +#include "src/codegen/output.h" #include "src/codegen/skeleton/skeleton.h" +#include "src/conf/opt.h" +#include "src/globals.h" #include "src/ir/bytecode/bytecode.h" +#include "src/ir/dfa/dfa.h" #include "src/ir/regexp/encoding/enc.h" #include "src/ir/regexp/encoding/range_suffix.h" +#include "src/ir/regexp/regexp.h" #include "src/ir/regexp/regexp_cat.h" #include "src/ir/regexp/regexp_close.h" #include "src/ir/regexp/regexp_null.h" -#include "src/globals.h" +#include "src/ir/regexp/regexp_rule.h" +#include "src/ir/rule_rank.h" #include "src/parse/code.h" #include "src/parse/extop.h" +#include "src/parse/loc.h" #include "src/parse/parser.h" -#include "src/util/c99_stdint.h" +#include "src/parse/scanner.h" +#include "src/parse/spec.h" +#include "src/util/counter.h" +#include "src/util/free_list.h" +#include "src/util/range.h" #include "src/util/smart_ptr.h" #define YYMALLOC malloc @@ -157,23 +172,23 @@ void default_rule(CondList *clist, const Code * code) re2c::CondList * clist; }; -%token CLOSE -%token CLOSESIZE -%token CODE -%token CONF -%token ID -%token FID -%token FID_END -%token NOCOND -%token REGEXP -%token SETUP -%token STAR - -%type <op> CLOSE STAR SETUP close -%type <extop> CLOSESIZE -%type <code> CODE -%type <regexp> REGEXP rule look expr diff term factor primary -%type <str> ID FID newcond +%token TOKEN_CLOSE +%token TOKEN_CLOSESIZE +%token TOKEN_CODE +%token TOKEN_CONF +%token TOKEN_ID +%token TOKEN_FID +%token TOKEN_FID_END +%token TOKEN_NOCOND +%token TOKEN_REGEXP +%token TOKEN_SETUP +%token TOKEN_STAR + +%type <op> TOKEN_CLOSE TOKEN_STAR TOKEN_SETUP close +%type <extop> TOKEN_CLOSESIZE +%type <code> TOKEN_CODE +%type <regexp> TOKEN_REGEXP rule look expr diff term factor primary +%type <str> TOKEN_ID TOKEN_FID newcond %type <clist> cond clist %% @@ -190,7 +205,7 @@ spec: ; decl: - ID '=' expr ';' + TOKEN_ID '=' expr ';' { if (!symbol_table.insert (std::make_pair (* $1, $3)).second) { @@ -199,7 +214,7 @@ decl: delete $1; $3->ins_access = RegExp::PRIVATE; } - | FID expr FID_END + | TOKEN_FID expr TOKEN_FID_END { if (!symbol_table.insert (std::make_pair (* $1, $2)).second) { @@ -208,19 +223,19 @@ decl: delete $1; $2->ins_access = RegExp::PRIVATE; } - | ID '=' expr '/' + | TOKEN_ID '=' expr '/' { in->fatal("trailing contexts are not allowed in named definitions"); } - | FID expr '/' + | TOKEN_FID expr '/' { in->fatal("trailing contexts are not allowed in named definitions"); } - | CONF {} + | TOKEN_CONF {} ; rule: - expr look CODE + expr look TOKEN_CODE { if (opts->cFlag) { @@ -237,7 +252,7 @@ rule: ); spec.add (rule); } - | STAR CODE /* default rule */ + | TOKEN_STAR TOKEN_CODE /* default rule */ { if (opts->cFlag) in->fatal("condition or '<*>' required when using -c switch"); @@ -255,7 +270,7 @@ rule: in->fatal("code to default rule is already defined"); } } - | '<' cond '>' expr look newcond CODE + | '<' cond '>' expr look newcond TOKEN_CODE { context_rule ($2, $7->loc, $4, $5, $7, $6); } @@ -265,7 +280,7 @@ rule: Loc loc (in->get_fname (), in->get_cline ()); context_rule ($2, loc, $4, $5, NULL, $7); } - | '<' cond '>' look newcond CODE + | '<' cond '>' look newcond TOKEN_CODE { context_none($2); delete $5; @@ -276,11 +291,11 @@ rule: context_none($2); delete $6; } - | '<' cond '>' STAR CODE /* default rule for conditions */ + | '<' cond '>' TOKEN_STAR TOKEN_CODE /* default rule for conditions */ { default_rule($2, $5); } - | '<' STAR '>' expr look newcond CODE + | '<' TOKEN_STAR '>' expr look newcond TOKEN_CODE { context_check(NULL); RuleOp * rule = new RuleOp @@ -295,7 +310,7 @@ rule: specStar.push_back (rule); delete $6; } - | '<' STAR '>' expr look ':' newcond + | '<' TOKEN_STAR '>' expr look ':' newcond { assert($7); context_check(NULL); @@ -312,18 +327,18 @@ rule: specStar.push_back (rule); delete $7; } - | '<' STAR '>' look newcond CODE + | '<' TOKEN_STAR '>' look newcond TOKEN_CODE { context_none(NULL); delete $5; } - | '<' STAR '>' look ':' newcond + | '<' TOKEN_STAR '>' look ':' newcond { assert($6); context_none(NULL); delete $6; } - | '<' STAR '>' STAR CODE /* default rule for all conditions */ + | '<' TOKEN_STAR '>' TOKEN_STAR TOKEN_CODE /* default rule for all conditions */ { if (star_default) { @@ -339,7 +354,7 @@ rule: , NULL ); } - | NOCOND newcond CODE + | TOKEN_NOCOND newcond TOKEN_CODE { context_check(NULL); if (specNone) @@ -357,7 +372,7 @@ rule: ); delete $2; } - | NOCOND ':' newcond + | TOKEN_NOCOND ':' newcond { assert($3); context_check(NULL); @@ -377,13 +392,13 @@ rule: ); delete $3; } - | SETUP STAR '>' CODE + | TOKEN_SETUP TOKEN_STAR '>' TOKEN_CODE { CondList *clist = new CondList(); clist->insert("*"); setup_rule(clist, $4); } - | SETUP cond '>' CODE + | TOKEN_SETUP cond '>' TOKEN_CODE { setup_rule($2, $4); } @@ -401,13 +416,13 @@ cond: ; clist: - ID + TOKEN_ID { $$ = new CondList(); $$->insert(* $1); delete $1; } - | clist ',' ID + | clist ',' TOKEN_ID { $1->insert(* $3); delete $3; @@ -420,7 +435,7 @@ newcond: { $$ = NULL; } - | '=' '>' ID + | '=' '>' TOKEN_ID { $$ = $3; } @@ -490,10 +505,10 @@ factor: break; } } - | primary CLOSESIZE + | primary TOKEN_CLOSESIZE { $1->ins_access = RegExp::PRIVATE; - if ($2.max == UINT32_MAX) + if ($2.max == std::numeric_limits<uint32_t>::max()) { $$ = repeat_from ($1, $2.min); } @@ -510,26 +525,26 @@ factor: ; close: - CLOSE + TOKEN_CLOSE { $$ = $1; } - | STAR + | TOKEN_STAR { $$ = $1; } - | close CLOSE + | close TOKEN_CLOSE { $$ = ($1 == $2) ? $1 : '*'; } - | close STAR + | close TOKEN_STAR { $$ = ($1 == $2) ? $1 : '*'; } ; primary: - ID + TOKEN_ID { symbol_table_t::iterator i = symbol_table.find (* $1); delete $1; @@ -539,7 +554,7 @@ primary: } $$ = i->second; } - | REGEXP + | TOKEN_REGEXP { $$ = $1; } @@ -572,8 +587,8 @@ void parse(Scanner& i, Output & o) in = &i; - o.source.write_version_time (); - o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); + o.source.wversion_time () + .wline_info (in->get_cline (), in->get_fname ().c_str ()); if (opts->target == opt_t::SKELETON) { Skeleton::emit_prolog (o.source); @@ -724,7 +739,7 @@ void parse(Scanner& i, Output & o) } } } - o.source.write_line_info (in->get_cline (), in->get_fname ().c_str ()); + o.source.wline_info (in->get_cline (), in->get_fname ().c_str ()); /* restore original char handling mode*/ opts.reset_encoding (encodingOld); } |