Lots of exploratory new grammar for instruction definitions and string and
fragment emission (none of which is hooked up to anything yet).
This commit is contained in:
parent
960259f0b0
commit
d96ceea08a
|
@ -23,17 +23,19 @@ static int nextern = 0;
|
||||||
%term PPERCENT
|
%term PPERCENT
|
||||||
|
|
||||||
%term PATTERNS
|
%term PATTERNS
|
||||||
%term PAT
|
|
||||||
%term WHEN
|
%term WHEN
|
||||||
%term EMIT
|
%term EMIT
|
||||||
|
%term FRAGMENT
|
||||||
%term COST
|
%term COST
|
||||||
|
%term INS
|
||||||
|
%term OUTS
|
||||||
|
|
||||||
%token <n> INT
|
%token <n> INT
|
||||||
%token <string> ID
|
%token <string> ID
|
||||||
%token <string> CFRAGMENT
|
%token <string> CFRAGMENT
|
||||||
|
%token <string> STRING
|
||||||
|
|
||||||
%type <n> cost
|
%type <n> cost
|
||||||
%type <string> label
|
|
||||||
%type <string> lhs
|
%type <string> lhs
|
||||||
%type <stringlist> stringlist
|
%type <stringlist> stringlist
|
||||||
%type <stringlist> when
|
%type <stringlist> when
|
||||||
|
@ -69,15 +71,15 @@ patterns
|
||||||
: /* nothing */
|
: /* nothing */
|
||||||
| patterns pattern ';'
|
| patterns pattern ';'
|
||||||
| patterns ';'
|
| patterns ';'
|
||||||
| patterns error ';' { yyerrok; }
|
| patterns error ';' { yyerrok; }
|
||||||
;
|
;
|
||||||
|
|
||||||
pattern
|
pattern
|
||||||
: lhs '=' rhs when cost { rule($1, $3, nextern++, $4, $5); }
|
: lhs '=' rhs when ins outs emits cost { rule($1, $3, nextern++, $4, $8); }
|
||||||
;
|
;
|
||||||
|
|
||||||
lhs
|
lhs
|
||||||
: ID { $$ = $1; nonterm($$); }
|
: ID { $$ = $1; nonterm($$); }
|
||||||
;
|
;
|
||||||
|
|
||||||
rhs
|
rhs
|
||||||
|
@ -87,29 +89,63 @@ rhs
|
||||||
;
|
;
|
||||||
|
|
||||||
labelledid
|
labelledid
|
||||||
: ID { $$[0] = NULL; $$[1] = $1; }
|
: ID { $$[0] = NULL; $$[1] = $1; }
|
||||||
| ID ':' ID { $$[0] = $1; $$[1] = $3; }
|
| ID ':' ID { $$[0] = $1; $$[1] = $3; }
|
||||||
;
|
;
|
||||||
|
|
||||||
when
|
when
|
||||||
: /* nothing */ { $$ = NULL; }
|
: /* nothing */ { $$ = NULL; }
|
||||||
| WHEN stringlist { $$ = $2; }
|
| WHEN stringlist { $$ = $2; }
|
||||||
;
|
;
|
||||||
|
|
||||||
stringlist
|
stringlist
|
||||||
: /* nothing */ { $$ = NULL; }
|
: /* nothing */ { $$ = NULL; }
|
||||||
| CFRAGMENT stringlist { $$ = pushstring($1, $2); }
|
| CFRAGMENT stringlist { $$ = pushstring($1, $2); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
ins
|
||||||
|
: /* nothing */
|
||||||
|
| INS inslist
|
||||||
|
;
|
||||||
|
|
||||||
|
inslist
|
||||||
|
: inslist ',' in
|
||||||
|
| in
|
||||||
|
;
|
||||||
|
|
||||||
|
in
|
||||||
|
: ID ':' ID
|
||||||
|
;
|
||||||
|
|
||||||
|
outs
|
||||||
|
: /* nothing */
|
||||||
|
| OUTS outslist
|
||||||
|
;
|
||||||
|
|
||||||
|
outslist
|
||||||
|
: outslist ',' out
|
||||||
|
| out
|
||||||
|
;
|
||||||
|
|
||||||
|
out
|
||||||
|
: ID ':' ID
|
||||||
|
;
|
||||||
|
|
||||||
|
emits
|
||||||
|
: /* nothing */
|
||||||
|
| EMIT STRING
|
||||||
|
| FRAGMENT STRING
|
||||||
|
;
|
||||||
|
|
||||||
cost
|
cost
|
||||||
: /* lambda */ { $$ = 0; }
|
: /* lambda */ { $$ = 0; }
|
||||||
| COST INT {
|
| COST INT {
|
||||||
if ($2 > maxcost) {
|
if ($2 > maxcost) {
|
||||||
yyerror("%d exceeds maximum cost of %d\n", $2, maxcost);
|
yyerror("%d exceeds maximum cost of %d\n", $2, maxcost);
|
||||||
$$ = maxcost;
|
$$ = maxcost;
|
||||||
} else
|
} else
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
%%
|
%%
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
|
@ -10,7 +10,12 @@ static void dumpCover(NODEPTR_TYPE p, int goalnt, int indent) {
|
||||||
fprintf(stderr, "%s\n", burm_string[eruleno]);
|
fprintf(stderr, "%s\n", burm_string[eruleno]);
|
||||||
burm_kids(p, eruleno, kids);
|
burm_kids(p, eruleno, kids);
|
||||||
for (i = 0; nts[i]; i++)
|
for (i = 0; nts[i]; i++)
|
||||||
dumpCover(kids[i], nts[i], indent + 1);
|
{
|
||||||
|
if (kids[i])
|
||||||
|
dumpCover(kids[i], nts[i], indent + 1);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "failed!\n");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,14 @@ static int braces = 0;
|
||||||
"%start" return START;
|
"%start" return START;
|
||||||
|
|
||||||
"PATTERNS" return PATTERNS;
|
"PATTERNS" return PATTERNS;
|
||||||
"pat" return PAT;
|
|
||||||
"when" return WHEN;
|
"when" return WHEN;
|
||||||
|
"ins" return INS;
|
||||||
|
"outs" return OUTS;
|
||||||
"emit" return EMIT;
|
"emit" return EMIT;
|
||||||
|
"fragment" return FRAGMENT;
|
||||||
"cost" return COST;
|
"cost" return COST;
|
||||||
|
|
||||||
|
\"[^"\n]*\" { yylval.string = strdup(yytext); return STRING; }
|
||||||
[A-Za-z_][A-Za-z0-9_]* { yylval.string = strdup(yytext); return ID; }
|
[A-Za-z_][A-Za-z0-9_]* { yylval.string = strdup(yytext); return ID; }
|
||||||
[0-9]+ { yylval.n = atoi(yytext); return INT; }
|
[0-9]+ { yylval.n = atoi(yytext); return INT; }
|
||||||
[ \t\r\n]* ;
|
[ \t\r\n]* ;
|
||||||
|
|
Loading…
Reference in a new issue