mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2024-12-23 09:55:32 +02:00
f80a01a9c0
- README: added description of toolpath adaptation language (in progress) - Makefile (OBJS): added lex.yy.o and y.tab.o - Makefile (SLOPPY): relaxed compiler warnings for files generated by flex/yacc - Makefile (clean): added lex/yacc intermediate files - Makefile: added lex and yacc (bison) to build process - Makefile: added rules for lex/yacc intermediate files - lang.l, lang.y: toolpath adaptation language (in progress)
94 lines
2.0 KiB
Plaintext
94 lines
2.0 KiB
Plaintext
%{
|
|
/*
|
|
* lang.l - Toolpath adaptation language
|
|
*
|
|
* Written 2010 by Werner Almesberger
|
|
* Copyright 2010 by Werner Almesberger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*/
|
|
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "y.tab.h"
|
|
|
|
|
|
void yyerror(const char *s);
|
|
|
|
static int lineno = 1;
|
|
static int metric = 1;
|
|
|
|
#define MIL2MM(mil) ((mil)/1000*25.4)
|
|
|
|
%}
|
|
|
|
/* file name can contain any characters */
|
|
%s FILENAME
|
|
|
|
/* "align" has a one-digit argument we don't want to subject to unit
|
|
conversion */
|
|
%s DIGIT
|
|
|
|
NUM [0-9]+\.?[0-9]*
|
|
|
|
%%
|
|
|
|
|
|
<INITIAL>align { BEGIN(DIGIT);
|
|
return TOK_ALIGN; }
|
|
<INITIAL>array return TOK_ARRAY;
|
|
<INITIAL>clear return TOK_CLEAR;
|
|
<INITIAL>reset return TOK_RESET;
|
|
<INITIAL>tool return TOK_TOOL;
|
|
<INITIAL>translate return TOK_TRANSLATE;
|
|
<INITIAL>z return TOK_Z;
|
|
|
|
<INITIAL>gerber { BEGIN(FILENAME);
|
|
return TOK_GERBER; }
|
|
<INITIAL>gnuplot { BEGIN(FILENAME);
|
|
return TOK_GNUPLOT; }
|
|
<INITIAL>write { BEGIN(FILENAME);
|
|
return TOK_WRITE; }
|
|
|
|
<INITIAL>mm metric = 1;
|
|
<INITIAL>mil metric = 0;
|
|
|
|
<INITIAL,FILENAME>{NUM}mm { yylval.num = strtod(yytext, NULL);
|
|
return NUMBER; }
|
|
<INITIAL,FILENAME>{NUM}mil { yylval.num = MIL2MM(strtod(yytext, NULL));
|
|
return NUMBER; }
|
|
<INITIAL,FILENAME>{NUM} { yylval.num = strtod(yytext, NULL);
|
|
if (!metric)
|
|
yylval.num = MIL2MM(yylval.num);
|
|
return NUMBER; }
|
|
|
|
<FILENAME>[^ \t\n]+([^\t\n]*[^ \t\n]+)? {
|
|
BEGIN(INITIAL);
|
|
yylval.str = yytext;
|
|
return STRING; }
|
|
|
|
<DIGIT>[1-9] { BEGIN(INITIAL);
|
|
yylval.num = strtod(yytext, NULL);
|
|
return NUMBER; }
|
|
|
|
[ \t] ;
|
|
\n lineno++;
|
|
|
|
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
|
|
lineno = strtol(yytext+2, NULL, 0); }
|
|
|
|
. return *yytext;
|
|
|
|
%%
|
|
|
|
void yyerror(const char *s)
|
|
{
|
|
fprintf(stderr, "%d: %s near \"%s\"\n", lineno, s, yytext);
|
|
exit(1);
|
|
}
|