1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-26 13:06:15 +02: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
T=<comp> {
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 }

View File

@ -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;
}

View File

@ -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;

View File

@ -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 <s> WORD
%type <equiv> nameqs
@ -83,11 +86,14 @@ static const struct field *top_field(void)
%type <sel> selectors
%type <cond> conditions condition
%type <act> opt_wildcard action
%type <part> part
%type <param> 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;
}
;

View File

@ -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);