1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-01 03:54:12 +03:00

b2/: add parsing of part characteristics (WIP)

This commit is contained in:
Werner Almesberger 2012-04-28 11:46:42 -03:00
parent 08b1ed1c51
commit 90e541cd7a
6 changed files with 70 additions and 7 deletions

2
b2/CHAR Normal file
View File

@ -0,0 +1,2 @@
FOO R101X FP=0603 R=100R TOL=5x
FOO R102Y FP=0603 R=1k TOL=1x

View File

@ -6,7 +6,7 @@
<diode> = D<SCH<Z<TVS; // D < SCH may make sense, the rest doesn't <diode> = D<SCH<Z<TVS; // D < SCH may make sense, the rest doesn't
T=<comp> { T=<comp> {
R: { R=#R TOL=%R }; R: { R=#R TOL=%R FP=* };
C: { C=#F TOL=%C V=#V }; C: { C=#F TOL=%C V=#V };
L: { L=#H TOL=%L I=#A }; L: { L=#H TOL=%L I=#A };
D: { C=#F } D: { C=#F }

View File

@ -36,22 +36,26 @@ static void open_stdin(const char *name)
static void usage(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); exit(1);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i;
switch (argc) { switch (argc) {
case 1: case 1:
break; break;
case 2: default:
open_stdin(argv[1]); open_stdin(argv[1]);
break; break;
default:
usage(*argv);
} }
parse_hierarchy(); parse_hierarchy();
for (i = 2; i < argc; i++) {
open_stdin(argv[i]);
parse_characteristics();
}
return 0; return 0;
} }

View File

@ -23,12 +23,14 @@
extern int yyparse(void); extern int yyparse(void);
static int start_token; static int start_token;
static int expose_nl;
static int lineno = 1; static int lineno = 1;
void parse_hierarchy(void) void parse_hierarchy(void)
{ {
start_token = START_HIERARCHY; start_token = START_HIERARCHY;
expose_nl = 0;
yyparse(); yyparse();
} }
@ -36,6 +38,7 @@ void parse_hierarchy(void)
void parse_characteristics(void) void parse_characteristics(void)
{ {
start_token = START_CHAR; start_token = START_CHAR;
expose_nl = 1;
yyparse(); yyparse();
} }
@ -62,7 +65,9 @@ void parse_characteristics(void)
"/*"([^*]|("*"+([^*/])))*"*"+"/" ; "/*"([^*]|("*"+([^*/])))*"*"+"/" ;
[ \t] ; [ \t] ;
\n lineno++; \n { lineno++;
if (expose_nl)
return TOK_NL; }
^#[^n]*\n lineno++; ^#[^n]*\n lineno++;
. return *yytext; . return *yytext;

View File

@ -17,6 +17,7 @@
#include "util.h" #include "util.h"
#include "param.h" #include "param.h"
#include "chr.h" #include "chr.h"
#include "db.h"
#include "y.tab.h" #include "y.tab.h"
@ -68,11 +69,13 @@ static const struct field *top_field(void)
struct selector *sel; struct selector *sel;
struct condition *cond; struct condition *cond;
struct action act; struct action act;
struct part *part;
struct param *param;
}; };
%token START_HIERARCHY START_CHAR %token START_HIERARCHY START_CHAR
%token TOK_LE TOK_GE %token TOK_LE TOK_GE TOK_NL
%token <s> WORD %token <s> WORD
%type <equiv> nameqs %type <equiv> nameqs
@ -83,11 +86,14 @@ static const struct field *top_field(void)
%type <sel> selectors %type <sel> selectors
%type <cond> conditions condition %type <cond> conditions condition
%type <act> opt_wildcard action %type <act> opt_wildcard action
%type <part> part
%type <param> param params
%% %%
all: all:
START_HIERARCHY hierarchy START_HIERARCHY hierarchy
| START_CHAR characteristics
; ;
hierarchy: hierarchy:
@ -337,3 +343,40 @@ format:
yyerrorf("unknown field \"%s\"", $2); 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;
}
;

View File

@ -69,6 +69,15 @@ struct value {
} u; } u;
}; };
struct param {
union {
const char *name;
const struct field *field;
} u;
struct value value;
struct param *next;
};
struct param_ops { struct param_ops {
int (*eval)(const struct format *fmt, const char *s, int (*eval)(const struct format *fmt, const char *s,
struct value *res); struct value *res);