diff --git a/b2/CHAR b/b2/CHAR new file mode 100644 index 0000000..a1126bd --- /dev/null +++ b/b2/CHAR @@ -0,0 +1,2 @@ +FOO R101X FP=0603 R=100R TOL=5x +FOO R102Y FP=0603 R=1k TOL=1x diff --git a/b2/HIERARCHY b/b2/HIERARCHY index 6304f12..bf1a47a 100644 --- a/b2/HIERARCHY +++ b/b2/HIERARCHY @@ -6,7 +6,7 @@ = D { - R: { R=#R TOL=%R }; + R: { R=#R TOL=%R FP=* }; C: { C=#F TOL=%C V=#V }; L: { L=#H TOL=%L I=#A }; D: { C=#F } diff --git a/b2/boom.c b/b2/boom.c index b575ab5..c85f8cd 100644 --- a/b2/boom.c +++ b/b2/boom.c @@ -36,22 +36,26 @@ static void open_stdin(const char *name) static void usage(const char *name) { - fprintf(stderr, "usage: %s [file]\n", name); + fprintf(stderr, "usage: %s [file ...]\n", name); exit(1); } int main(int argc, char **argv) { + int i; + switch (argc) { case 1: break; - case 2: + default: open_stdin(argv[1]); break; - default: - usage(*argv); } parse_hierarchy(); + for (i = 2; i < argc; i++) { + open_stdin(argv[i]); + parse_characteristics(); + } return 0; } diff --git a/b2/lang.l b/b2/lang.l index 85c777c..55be66b 100644 --- a/b2/lang.l +++ b/b2/lang.l @@ -23,12 +23,14 @@ extern int yyparse(void); static int start_token; +static int expose_nl; static int lineno = 1; void parse_hierarchy(void) { start_token = START_HIERARCHY; + expose_nl = 0; yyparse(); } @@ -36,6 +38,7 @@ void parse_hierarchy(void) void parse_characteristics(void) { start_token = START_CHAR; + expose_nl = 1; yyparse(); } @@ -62,7 +65,9 @@ void parse_characteristics(void) "/*"([^*]|("*"+([^*/])))*"*"+"/" ; [ \t] ; -\n lineno++; +\n { lineno++; + if (expose_nl) + return TOK_NL; } ^#[^n]*\n lineno++; . return *yytext; diff --git a/b2/lang.y b/b2/lang.y index b34bb45..39b67a0 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -17,6 +17,7 @@ #include "util.h" #include "param.h" #include "chr.h" +#include "db.h" #include "y.tab.h" @@ -68,11 +69,13 @@ static const struct field *top_field(void) struct selector *sel; struct condition *cond; struct action act; + struct part *part; + struct param *param; }; %token START_HIERARCHY START_CHAR -%token TOK_LE TOK_GE +%token TOK_LE TOK_GE TOK_NL %token WORD %type nameqs @@ -83,11 +86,14 @@ static const struct field *top_field(void) %type selectors %type conditions condition %type opt_wildcard action +%type part +%type param params %% all: START_HIERARCHY hierarchy + | START_CHAR characteristics ; hierarchy: @@ -337,3 +343,40 @@ format: yyerrorf("unknown field \"%s\"", $2); } ; + +characteristics: + | TOK_NL + | part characteristics + ; + +part: + WORD WORD params TOK_NL + { + $$ = part_lookup($1, $2); + if (!$$) + $$ = part_add($1, $2); + if ($$->param) + yyerror("parameters already defined"); + $$->param = $3; + } + ; + +params: + { + $$ = NULL; + } + | param params + { + $$ = $1; + $$->next = $2; + } + ; + +param: + WORD '=' WORD + { + $$ = alloc_type(struct param); + $$->u.name = $1; + $$->value.u.name = $3; + } + ; diff --git a/b2/param.h b/b2/param.h index dd4360c..09acd12 100644 --- a/b2/param.h +++ b/b2/param.h @@ -69,6 +69,15 @@ struct value { } u; }; +struct param { + union { + const char *name; + const struct field *field; + } u; + struct value value; + struct param *next; +}; + struct param_ops { int (*eval)(const struct format *fmt, const char *s, struct value *res);