2009-08-03 19:12:47 +03:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* fpd.l - FootPrint Definition language
|
|
|
|
*
|
2010-04-20 04:55:49 +03:00
|
|
|
* Written 2009, 2010 by Werner Almesberger
|
|
|
|
* Copyright 2009, 2010 by Werner Almesberger
|
2009-08-03 19:12:47 +03:00
|
|
|
*
|
|
|
|
* 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 "util.h"
|
|
|
|
#include "coord.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "error.h"
|
2009-08-07 16:37:51 +03:00
|
|
|
#include "meas.h"
|
2009-08-16 07:12:37 +03:00
|
|
|
#include "fpd.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
#include "y.tab.h"
|
|
|
|
|
|
|
|
|
|
|
|
int start_token = START_FPD;
|
|
|
|
|
|
|
|
static int disable_keywords = 0;
|
|
|
|
static int is_table = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void scan_empty(void)
|
|
|
|
{
|
|
|
|
yy_scan_string("");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void scan_expr(const char *s)
|
|
|
|
{
|
|
|
|
start_token = START_EXPR;
|
|
|
|
yy_scan_string(s);
|
|
|
|
}
|
|
|
|
|
2009-08-16 07:12:37 +03:00
|
|
|
|
|
|
|
void scan_var(const char *s)
|
|
|
|
{
|
|
|
|
start_token = START_VAR;
|
|
|
|
yy_scan_string(s);
|
|
|
|
}
|
|
|
|
|
2009-08-16 08:05:12 +03:00
|
|
|
|
|
|
|
void scan_values(const char *s)
|
|
|
|
{
|
|
|
|
start_token = START_VALUES;
|
|
|
|
yy_scan_string(s);
|
|
|
|
}
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
|
|
/* keywords are only accepted at the beginning of a line */
|
|
|
|
%s NOKEYWORD
|
|
|
|
|
|
|
|
NUM [0-9]+\.?[0-9]*
|
|
|
|
SP [\t ]*
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* Nice hack:
|
|
|
|
*
|
|
|
|
* http://www.gnu.org/software/bison/manual/bison.html#
|
|
|
|
* Multiple-start_002dsymbols
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (start_token) {
|
|
|
|
int tmp = start_token;
|
|
|
|
start_token = 0;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
|
|
<INITIAL>"set" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_SET; }
|
|
|
|
<INITIAL>"loop" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_LOOP; }
|
2009-08-06 09:54:41 +03:00
|
|
|
<INITIAL>"part" { BEGIN(NOKEYWORD);
|
2009-08-17 23:42:51 +03:00
|
|
|
return TOK_PACKAGE; }
|
|
|
|
<INITIAL>"package" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_PACKAGE; }
|
2009-08-03 19:12:47 +03:00
|
|
|
<INITIAL>"frame" { BEGIN(NOKEYWORD);
|
|
|
|
is_table = 0;
|
|
|
|
return TOK_FRAME; }
|
|
|
|
<INITIAL>"table" { BEGIN(NOKEYWORD);
|
|
|
|
is_table = 1;
|
|
|
|
return TOK_TABLE; }
|
|
|
|
<INITIAL>"vec" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_VEC; }
|
|
|
|
<INITIAL>"pad" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_PAD; }
|
2009-08-14 13:18:40 +03:00
|
|
|
<INITIAL>"rpad" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_RPAD; }
|
2010-04-25 13:58:07 +03:00
|
|
|
<INITIAL>"hole" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_HOLE; }
|
2009-08-03 19:12:47 +03:00
|
|
|
<INITIAL>"rect" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_RECT; }
|
|
|
|
<INITIAL>"line" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_LINE; }
|
|
|
|
<INITIAL>"circ" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_CIRC; }
|
|
|
|
<INITIAL>"arc" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_ARC; }
|
|
|
|
<INITIAL>"meas" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_MEAS; }
|
2009-08-07 16:37:51 +03:00
|
|
|
<INITIAL>"measx" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_MEASX; }
|
|
|
|
<INITIAL>"measy" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_MEASY; }
|
2009-08-22 18:58:58 +03:00
|
|
|
<INITIAL>"unit" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_UNIT; }
|
2009-08-03 19:12:47 +03:00
|
|
|
|
Added debugging directives to the fped language. They're describe at the end
of README.
- fpd.l, fpd.y, README: added debugging directives %del, %move, %print, %dump,
and %exit
- obj.h, fpd.y (find_obj, find_label, new_obj): objects can now be labeled
- obj.c (obj_anchors), inst.c (inst_anchors): gathering the list of anchors is
now a per-object function, not an instance "method". inst_anchors implements
the vector vs. object switch.
- inst.h, inst.c: removed all *_op_anchors functions
- expr.c (str_unit): in the past, we returned a malloc'ed string, but these
times are long gone. Thus, don't stralloc("").
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5919 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-19 17:39:57 +03:00
|
|
|
<INITIAL>"%del" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_DBG_DEL; }
|
|
|
|
<INITIAL>"%move" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_DBG_MOVE; }
|
|
|
|
<INITIAL>"%print" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_DBG_PRINT; }
|
|
|
|
<INITIAL>"%dump" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_DBG_DUMP; }
|
|
|
|
<INITIAL>"%exit" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_DBG_EXIT; }
|
2010-04-26 18:18:01 +03:00
|
|
|
<INITIAL>"%tsort" { BEGIN(NOKEYWORD);
|
|
|
|
return TOK_DBG_TSORT; }
|
Added debugging directives to the fped language. They're describe at the end
of README.
- fpd.l, fpd.y, README: added debugging directives %del, %move, %print, %dump,
and %exit
- obj.h, fpd.y (find_obj, find_label, new_obj): objects can now be labeled
- obj.c (obj_anchors), inst.c (inst_anchors): gathering the list of anchors is
now a per-object function, not an instance "method". inst_anchors implements
the vector vs. object switch.
- inst.h, inst.c: removed all *_op_anchors functions
- expr.c (str_unit): in the past, we returned a malloc'ed string, but these
times are long gone. Thus, don't stralloc("").
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5919 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-19 17:39:57 +03:00
|
|
|
|
2009-08-05 00:45:33 +03:00
|
|
|
<INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
|
2009-08-03 19:12:47 +03:00
|
|
|
yylval.id = unique(yytext);
|
|
|
|
return LABEL; }
|
|
|
|
[a-zA-Z_][a-zA-Z_0-9]* { yylval.id = unique(yytext);
|
|
|
|
return ID; }
|
|
|
|
|
|
|
|
{NUM}{SP}mm { yylval.num.type = nt_mm;
|
|
|
|
yylval.num.exponent = 1;
|
|
|
|
sscanf(yytext, "%lf", &yylval.num.n);
|
|
|
|
return NUMBER; }
|
|
|
|
{NUM}{SP}mil { yylval.num.type = nt_mil;
|
|
|
|
yylval.num.exponent = 1;
|
|
|
|
sscanf(yytext, "%lf", &yylval.num.n);
|
|
|
|
return NUMBER; }
|
|
|
|
{NUM} { yylval.num.type = nt_mm; /* mm or mil */
|
|
|
|
yylval.num.exponent = 0;
|
|
|
|
sscanf(yytext, "%lf", &yylval.num.n);
|
|
|
|
return NUMBER; }
|
|
|
|
|
|
|
|
\"(\\[^\n\t]|[^\\"\n\t])*\" { *strrchr(yytext, '"') = 0;
|
|
|
|
yylval.str = stralloc(yytext+1);
|
|
|
|
return STRING; }
|
|
|
|
|
2009-08-07 16:37:51 +03:00
|
|
|
"->" return TOK_NEXT;
|
|
|
|
"<-" return TOK_NEXT_INVERTED;
|
|
|
|
">>" return TOK_MAX;
|
|
|
|
"<<" return TOK_MAX_INVERTED;
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
{SP} ;
|
|
|
|
\n { if (!disable_keywords)
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
lineno++; }
|
|
|
|
|
2009-08-03 20:58:32 +03:00
|
|
|
; BEGIN(INITIAL);
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
"{" { BEGIN(NOKEYWORD);
|
|
|
|
disable_keywords = is_table;
|
|
|
|
return '{'; }
|
|
|
|
"}" { disable_keywords = 0;
|
|
|
|
return '}'; }
|
|
|
|
|
|
|
|
^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
|
|
|
|
if (!disable_keywords)
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
lineno = strtol(yytext+2, NULL, 0); }
|
|
|
|
|
|
|
|
. return *yytext;
|