%defines %{ # include # include "builder.h" # include "build.tab.h" void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); %} %parse-param { Builder &bld } %lex-param { Builder &bld } %pure-parser %locations %debug %error-verbose %union { char *strval; int tval; } %token STRING "string literal" %token REGEXP "regular expression" %token TARGETTYPE "target type" %token FUNCTION "function name" %token TOK_ADDSET "+=" %token TOK_DEFAULT "default" %token TOK_ACTION "action" %token TOK_CHECK "check" %token TOK_CLEAN "clean" %token TOK_RULE "rule" %token TOK_TARGET "target" %token TOK_SET "set" %token TOK_INPUT "input" %token TOK_FILTER "filter" %token TOK_PREFIX "prefix" %token TOK_REQUIRES "requires" %token TOK_MATCHES "matches" %token TOK_PERFORM "perform" %token TOK_PRODUCES "produces" %token ',' ':' '=' '(' ')' %destructor { delete[] $$; } STRING FUNCTION %% // General input format input: | input rule | input action | input target ; // Rule interpretation rule: TOK_RULE STRING {printf("Rule %s:\n", $2 ); } ':' rulecmds ; rulecmds: rulecmd | rulecmds ',' rulecmd ; rulecmd: TOK_MATCHES REGEXP { printf(" Matches: %s\n", $2 ); } | TOK_PRODUCES STRING { printf(" Produces: %s\n", $2 ); } | TOK_REQUIRES { printf(" Requires:\n"); } list {printf("\n");} | TOK_INPUT TOK_FILTER REGEXP { printf(" Input Filter: %s\n", $3 ); } | TOK_INPUT TOK_FILTER { printf(" Input Filter: "); } func {printf("\n");} | TOK_PERFORM { printf(" Perform: "); } func {printf("\n");} ; // Action interpretation action: TOK_DEFAULT TOK_ACTION ':' { printf("Default action:\n"); } actioncmds | STRING TOK_ACTION ':' { printf("\"%s\" action:\n", $1 ); } actioncmds ; actioncmds: actioncmd | actioncmds ',' actioncmd ; actioncmd: { printf("\t"); } actioncmdtype list {printf("\n");} ; actioncmdtype: TOK_CHECK { printf("check "); } | TOK_CLEAN { printf("clean "); } ; // Target interpretation target: list ':' { printf(" are targets:\n"); } targetcmds ; targetcmds: targetcmd | targetcmds ',' targetcmd ; targetcmd: TOK_RULE STRING { printf(" Rule %s\n", $2 ); } | TOK_TARGET TOK_PREFIX STRING { printf(" Target prefix: %s\n", $3 ); } | TOK_TARGET TARGETTYPE { printf(" Target Type: %d\n", $2 ); } | TOK_INPUT { printf(" Input: "); } list { printf("\n"); } | TOK_REQUIRES { printf(" Requires: "); } list { printf("\n"); } | TOK_SET { printf(" Set: "); } targetset ; targetset: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); } | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); } ; // list goo list: listitem listfilter | '[' { printf("["); } listitems ']' { printf("]"); } listfilter ; listfilter: | TOK_FILTER REGEXP | TOK_FILTER func ; listitems: listitem | listitems ',' {printf(", "); } listitem ; listitem: STRING {printf("%s", $1 ); } | func ; // Function func: FUNCTION { printf("%s(", $1 ); } '(' funcparams ')' { printf(")"); } ; funcparams: | STRING { printf("%s", $1 ); } | funcparams ',' STRING { printf(", %s", $3 ); } ; %% void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ) { bld.error( locp, msg ); }