diff --git a/cameo/lang.l b/cameo/lang.l index 7c0cd78..024bd2b 100644 --- a/cameo/lang.l +++ b/cameo/lang.l @@ -24,9 +24,6 @@ static int lineno = 1; static int metric = 1; static int file_name_follows = 0; - -#define MIL2MM(mil) ((mil)/1000*25.4) - %} /* file name can contain any characters */ @@ -69,17 +66,15 @@ NUM -?[0-9]+\.?[0-9]* {NUM}mm { yylval.num = strtod(yytext, NULL); if (file_name_follows) BEGIN(FILENAME); - return NUMBER; } -{NUM}mil { yylval.num = MIL2MM(strtod(yytext, NULL)); + return NUM_EXP_MM; } +{NUM}mil { yylval.num = strtod(yytext, NULL); if (file_name_follows) BEGIN(FILENAME); - return NUMBER; } + return NUM_EXP_MIL; } {NUM} { yylval.num = strtod(yytext, NULL); - if (!metric) - yylval.num = MIL2MM(yylval.num); if (file_name_follows) BEGIN(FILENAME); - return NUMBER; } + return metric ? NUM_IMP_MM : NUM_IMP_MIL; } [^ \t\n]+([^\t\n]*[^ \t\n]+)? { BEGIN(INITIAL); diff --git a/cameo/lang.y b/cameo/lang.y index d0a76f3..468246e 100644 --- a/cameo/lang.y +++ b/cameo/lang.y @@ -26,6 +26,9 @@ static double xo = 0, yo = 0, zo = 0; static struct path *paths = NULL; +#define MIL2MM(mil) ((mil)/1000*25.4) + + static void add_paths(struct path *new) { 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_DOG -%token NUMBER REF +%token NUM_EXP_MIL NUM_EXP_MM NUM_IMP_MIL NUM_IMP_MM REF %token STRING %type opt_filename +%type dimen number %% @@ -130,11 +134,11 @@ all: ; command: - TOK_ALIGN REF NUMBER NUMBER + TOK_ALIGN REF dimen dimen { align((int) $2, $3, $4); } - | TOK_ALIGN REF NUMBER NUMBER NUMBER NUMBER + | TOK_ALIGN REF dimen dimen dimen dimen { int ref = $2; double x, y; @@ -147,12 +151,11 @@ command: ref_pick_xy(ref, $3, $4, $5, $6, &x, &y); align(ref, x, y); } - | TOK_ARRAY NUMBER NUMBER NUMBER NUMBER + | TOK_ARRAY dimen dimen number number { double x = $2*$4; double y = $3*$5; - /* @@@ known bug: doesn't work if not in metric mode */ translate(x, y, 0); } | TOK_CLEAR @@ -177,26 +180,26 @@ command: { tool_comp_paths(paths, 1); } - | TOK_TRANSLATE NUMBER NUMBER + | TOK_TRANSLATE dimen dimen { translate($2, $3, 0); xo += $2; yo += $3; } - | TOK_Z NUMBER + | TOK_Z dimen { zo += $2; } - | TOK_Z NUMBER NUMBER + | TOK_Z dimen dimen { zo += $3-$2; } - | TOK_GERBER NUMBER opt_filename + | TOK_GERBER dimen opt_filename { add_paths(gerber_read($3, $2/2)); translate(xo, yo, 0); } - | TOK_GNUPLOT NUMBER opt_filename + | TOK_GNUPLOT dimen opt_filename { add_paths(gnuplot_read($3, $2/2)); translate(xo, yo, 0); @@ -218,3 +221,33 @@ opt_filename: $$ = $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; + } + ;