1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 10:31:10 +02:00

cameo: split numbers into dimensions and "bare" numbers

- lang.l, lang.y (MIL2MM): moved unit conversion from lang.l to lang.y
- lang.l, lang.y: instead of returning dimensions and numbers as NUMBER,
  return as NUM_EXP_<unit> for numbers with an explicit unit, and as
  NUM_IMP_<unit> if the unit is implied
- lang.y (dimen): perform unit conversion as needed
- lang.y (number): never convert and only accept implicit dimensions
- lang.y: change all uses of NUMBER to "dimen", except for the
  multipliers in "array", where we can now use "number"
- lang.y: removed comment about "array" only working in metric mode
This commit is contained in:
Werner Almesberger 2010-12-14 19:50:53 -03:00
parent f36f7048e6
commit 68d5eff7cd
2 changed files with 47 additions and 19 deletions

View File

@ -24,9 +24,6 @@ static int lineno = 1;
static int metric = 1; static int metric = 1;
static int file_name_follows = 0; static int file_name_follows = 0;
#define MIL2MM(mil) ((mil)/1000*25.4)
%} %}
/* file name can contain any characters */ /* file name can contain any characters */
@ -69,17 +66,15 @@ NUM -?[0-9]+\.?[0-9]*
{NUM}mm { yylval.num = strtod(yytext, NULL); {NUM}mm { yylval.num = strtod(yytext, NULL);
if (file_name_follows) if (file_name_follows)
BEGIN(FILENAME); BEGIN(FILENAME);
return NUMBER; } return NUM_EXP_MM; }
{NUM}mil { yylval.num = MIL2MM(strtod(yytext, NULL)); {NUM}mil { yylval.num = strtod(yytext, NULL);
if (file_name_follows) if (file_name_follows)
BEGIN(FILENAME); BEGIN(FILENAME);
return NUMBER; } return NUM_EXP_MIL; }
{NUM} { yylval.num = strtod(yytext, NULL); {NUM} { yylval.num = strtod(yytext, NULL);
if (!metric)
yylval.num = MIL2MM(yylval.num);
if (file_name_follows) if (file_name_follows)
BEGIN(FILENAME); BEGIN(FILENAME);
return NUMBER; } return metric ? NUM_IMP_MM : NUM_IMP_MIL; }
<FILENAME>[^ \t\n]+([^\t\n]*[^ \t\n]+)? { <FILENAME>[^ \t\n]+([^\t\n]*[^ \t\n]+)? {
BEGIN(INITIAL); BEGIN(INITIAL);

View File

@ -26,6 +26,9 @@ static double xo = 0, yo = 0, zo = 0;
static struct path *paths = NULL; static struct path *paths = NULL;
#define MIL2MM(mil) ((mil)/1000*25.4)
static void add_paths(struct path *new) static void add_paths(struct path *new)
{ {
struct path **anchor = &paths; struct path **anchor = &paths;
@ -118,10 +121,11 @@ static void align(int ref, double x, double y)
%token TOK_GERBER TOK_GNUPLOT TOK_WRITE %token TOK_GERBER TOK_GNUPLOT TOK_WRITE
%token TOK_DOG %token TOK_DOG
%token <num> NUMBER REF %token <num> NUM_EXP_MIL NUM_EXP_MM NUM_IMP_MIL NUM_IMP_MM REF
%token <str> STRING %token <str> STRING
%type <str> opt_filename %type <str> opt_filename
%type <num> dimen number
%% %%
@ -130,11 +134,11 @@ all:
; ;
command: command:
TOK_ALIGN REF NUMBER NUMBER TOK_ALIGN REF dimen dimen
{ {
align((int) $2, $3, $4); align((int) $2, $3, $4);
} }
| TOK_ALIGN REF NUMBER NUMBER NUMBER NUMBER | TOK_ALIGN REF dimen dimen dimen dimen
{ {
int ref = $2; int ref = $2;
double x, y; double x, y;
@ -147,12 +151,11 @@ command:
ref_pick_xy(ref, $3, $4, $5, $6, &x, &y); ref_pick_xy(ref, $3, $4, $5, $6, &x, &y);
align(ref, x, y); align(ref, x, y);
} }
| TOK_ARRAY NUMBER NUMBER NUMBER NUMBER | TOK_ARRAY dimen dimen number number
{ {
double x = $2*$4; double x = $2*$4;
double y = $3*$5; double y = $3*$5;
/* @@@ known bug: doesn't work if not in metric mode */
translate(x, y, 0); translate(x, y, 0);
} }
| TOK_CLEAR | TOK_CLEAR
@ -177,26 +180,26 @@ command:
{ {
tool_comp_paths(paths, 1); tool_comp_paths(paths, 1);
} }
| TOK_TRANSLATE NUMBER NUMBER | TOK_TRANSLATE dimen dimen
{ {
translate($2, $3, 0); translate($2, $3, 0);
xo += $2; xo += $2;
yo += $3; yo += $3;
} }
| TOK_Z NUMBER | TOK_Z dimen
{ {
zo += $2; zo += $2;
} }
| TOK_Z NUMBER NUMBER | TOK_Z dimen dimen
{ {
zo += $3-$2; zo += $3-$2;
} }
| TOK_GERBER NUMBER opt_filename | TOK_GERBER dimen opt_filename
{ {
add_paths(gerber_read($3, $2/2)); add_paths(gerber_read($3, $2/2));
translate(xo, yo, 0); translate(xo, yo, 0);
} }
| TOK_GNUPLOT NUMBER opt_filename | TOK_GNUPLOT dimen opt_filename
{ {
add_paths(gnuplot_read($3, $2/2)); add_paths(gnuplot_read($3, $2/2));
translate(xo, yo, 0); translate(xo, yo, 0);
@ -218,3 +221,33 @@ opt_filename:
$$ = $1; $$ = $1;
} }
; ;
dimen:
NUM_EXP_MM
{
$$ = $1;
}
| NUM_IMP_MM
{
$$ = $1;
}
| NUM_EXP_MIL
{
$$ = MIL2MM($1);
}
| NUM_IMP_MIL
{
$$ = MIL2MM($1);
}
;
number:
NUM_IMP_MIL
{
$$ = $1;
}
| NUM_IMP_MM
{
$$ = $1;
}
;