mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 10:18:57 +02:00
cameo: various scanner and parser fixes
- README, lang.y: changed depth parameter of "z" command to position (sign changes) - lang.l: defer FILENAME after "gerber" and "gnuplot", so that we don't mis-read the number - lang.l, lang.y: return the reference point after "align" as new token REF, not as NUMEBER, so that we can catch syntax errors that would cause scanner and parser to become unsynchronized - lang.l: accept negative numbers - lang.l: added support for comments beginning with #
This commit is contained in:
parent
fe50addf65
commit
ddcf5191db
@ -73,7 +73,7 @@ Horizontal adjustments:
|
|||||||
|
|
||||||
Vertical adjustment:
|
Vertical adjustment:
|
||||||
|
|
||||||
z [<z0>] <z0-depth>
|
z [<z0>] <z0-pos>
|
||||||
|
|
||||||
Tool compensation:
|
Tool compensation:
|
||||||
|
|
||||||
|
31
cameo/lang.l
31
cameo/lang.l
@ -22,6 +22,8 @@ void yyerror(const char *s);
|
|||||||
|
|
||||||
static int lineno = 1;
|
static int lineno = 1;
|
||||||
static int metric = 1;
|
static int metric = 1;
|
||||||
|
static int file_name_follows = 0;
|
||||||
|
|
||||||
|
|
||||||
#define MIL2MM(mil) ((mil)/1000*25.4)
|
#define MIL2MM(mil) ((mil)/1000*25.4)
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ static int metric = 1;
|
|||||||
conversion */
|
conversion */
|
||||||
%s DIGIT
|
%s DIGIT
|
||||||
|
|
||||||
NUM [0-9]+\.?[0-9]*
|
NUM -?[0-9]+\.?[0-9]*
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
@ -48,9 +50,9 @@ NUM [0-9]+\.?[0-9]*
|
|||||||
<INITIAL>translate return TOK_TRANSLATE;
|
<INITIAL>translate return TOK_TRANSLATE;
|
||||||
<INITIAL>z return TOK_Z;
|
<INITIAL>z return TOK_Z;
|
||||||
|
|
||||||
<INITIAL>gerber { BEGIN(FILENAME);
|
<INITIAL>gerber { file_name_follows = 1;
|
||||||
return TOK_GERBER; }
|
return TOK_GERBER; }
|
||||||
<INITIAL>gnuplot { BEGIN(FILENAME);
|
<INITIAL>gnuplot { file_name_follows = 1;
|
||||||
return TOK_GNUPLOT; }
|
return TOK_GNUPLOT; }
|
||||||
<INITIAL>write { BEGIN(FILENAME);
|
<INITIAL>write { BEGIN(FILENAME);
|
||||||
return TOK_WRITE; }
|
return TOK_WRITE; }
|
||||||
@ -60,30 +62,39 @@ NUM [0-9]+\.?[0-9]*
|
|||||||
<INITIAL>mm metric = 1;
|
<INITIAL>mm metric = 1;
|
||||||
<INITIAL>mil metric = 0;
|
<INITIAL>mil metric = 0;
|
||||||
|
|
||||||
<INITIAL,FILENAME>{NUM}mm { yylval.num = strtod(yytext, NULL);
|
<DIGIT>[1-9] { BEGIN(INITIAL);
|
||||||
|
yylval.num = strtod(yytext, NULL);
|
||||||
|
return REF; }
|
||||||
|
|
||||||
|
{NUM}mm { yylval.num = strtod(yytext, NULL);
|
||||||
|
if (file_name_follows)
|
||||||
|
BEGIN(FILENAME);
|
||||||
return NUMBER; }
|
return NUMBER; }
|
||||||
<INITIAL,FILENAME>{NUM}mil { yylval.num = MIL2MM(strtod(yytext, NULL));
|
{NUM}mil { yylval.num = MIL2MM(strtod(yytext, NULL));
|
||||||
|
if (file_name_follows)
|
||||||
|
BEGIN(FILENAME);
|
||||||
return NUMBER; }
|
return NUMBER; }
|
||||||
<INITIAL,FILENAME>{NUM} { yylval.num = strtod(yytext, NULL);
|
{NUM} { yylval.num = strtod(yytext, NULL);
|
||||||
if (!metric)
|
if (!metric)
|
||||||
yylval.num = MIL2MM(yylval.num);
|
yylval.num = MIL2MM(yylval.num);
|
||||||
|
if (file_name_follows)
|
||||||
|
BEGIN(FILENAME);
|
||||||
return NUMBER; }
|
return NUMBER; }
|
||||||
|
|
||||||
<FILENAME>[^ \t\n]+([^\t\n]*[^ \t\n]+)? {
|
<FILENAME>[^ \t\n]+([^\t\n]*[^ \t\n]+)? {
|
||||||
BEGIN(INITIAL);
|
BEGIN(INITIAL);
|
||||||
|
file_name_follows = 0;
|
||||||
yylval.str = yytext;
|
yylval.str = yytext;
|
||||||
return STRING; }
|
return STRING; }
|
||||||
|
|
||||||
<DIGIT>[1-9] { BEGIN(INITIAL);
|
|
||||||
yylval.num = strtod(yytext, NULL);
|
|
||||||
return NUMBER; }
|
|
||||||
|
|
||||||
[ \t] ;
|
[ \t] ;
|
||||||
\n lineno++;
|
\n lineno++;
|
||||||
|
|
||||||
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
|
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
|
||||||
lineno = strtol(yytext+2, NULL, 0); }
|
lineno = strtol(yytext+2, NULL, 0); }
|
||||||
|
|
||||||
|
<INITIAL>#.*\n lineno++;
|
||||||
|
|
||||||
. return *yytext;
|
. return *yytext;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
10
cameo/lang.y
10
cameo/lang.y
@ -118,7 +118,7 @@ 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
|
%token <num> NUMBER REF
|
||||||
%token <str> STRING
|
%token <str> STRING
|
||||||
|
|
||||||
%type <str> opt_filename
|
%type <str> opt_filename
|
||||||
@ -130,11 +130,11 @@ all:
|
|||||||
;
|
;
|
||||||
|
|
||||||
command:
|
command:
|
||||||
TOK_ALIGN NUMBER NUMBER NUMBER
|
TOK_ALIGN REF NUMBER NUMBER
|
||||||
{
|
{
|
||||||
align((int) $2, $3, $4);
|
align((int) $2, $3, $4);
|
||||||
}
|
}
|
||||||
| TOK_ALIGN NUMBER NUMBER NUMBER NUMBER NUMBER
|
| TOK_ALIGN REF NUMBER NUMBER NUMBER NUMBER
|
||||||
{
|
{
|
||||||
int ref = $2;
|
int ref = $2;
|
||||||
double x, y;
|
double x, y;
|
||||||
@ -179,11 +179,11 @@ command:
|
|||||||
}
|
}
|
||||||
| TOK_Z NUMBER
|
| TOK_Z NUMBER
|
||||||
{
|
{
|
||||||
zo -= $2;
|
zo += $2;
|
||||||
}
|
}
|
||||||
| TOK_Z NUMBER NUMBER
|
| TOK_Z NUMBER NUMBER
|
||||||
{
|
{
|
||||||
zo -= $2+$3;
|
zo += $3-$2;
|
||||||
}
|
}
|
||||||
| TOK_GERBER NUMBER opt_filename
|
| TOK_GERBER NUMBER opt_filename
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user