Root/fpd.l

Source at commit 190bcaf982869388b508a0a4c97cff62fbb73038 created 9 years 6 months ago.
By werner, Added a topological sort algorithm, for use when dumping.
1%{
2/*
3 * fpd.l - FootPrint Definition language
4 *
5 * Written 2009, 2010 by Werner Almesberger
6 * Copyright 2009, 2010 by Werner Almesberger
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14
15#include <stdlib.h>
16
17#include "util.h"
18#include "coord.h"
19#include "expr.h"
20#include "error.h"
21#include "meas.h"
22#include "fpd.h"
23
24#include "y.tab.h"
25
26
27int start_token = START_FPD;
28
29static int disable_keywords = 0;
30static int is_table = 0;
31
32
33void scan_empty(void)
34{
35    yy_scan_string("");
36}
37
38
39void scan_expr(const char *s)
40{
41    start_token = START_EXPR;
42    yy_scan_string(s);
43}
44
45
46void scan_var(const char *s)
47{
48    start_token = START_VAR;
49    yy_scan_string(s);
50}
51
52
53void scan_values(const char *s)
54{
55    start_token = START_VALUES;
56    yy_scan_string(s);
57}
58
59%}
60
61
62/* keywords are only accepted at the beginning of a line */
63%s NOKEYWORD
64
65NUM [0-9]+\.?[0-9]*
66SP [\t ]*
67
68
69%%
70
71%{
72    /*
73     * Nice hack:
74     *
75     * http://www.gnu.org/software/bison/manual/bison.html#
76     * Multiple-start_002dsymbols
77     */
78
79    if (start_token) {
80        int tmp = start_token;
81        start_token = 0;
82        return tmp;
83    }
84%}
85
86
87<INITIAL>"set" { BEGIN(NOKEYWORD);
88                  return TOK_SET; }
89<INITIAL>"loop" { BEGIN(NOKEYWORD);
90                  return TOK_LOOP; }
91<INITIAL>"part" { BEGIN(NOKEYWORD);
92                  return TOK_PACKAGE; }
93<INITIAL>"package" { BEGIN(NOKEYWORD);
94                  return TOK_PACKAGE; }
95<INITIAL>"frame" { BEGIN(NOKEYWORD);
96                  is_table = 0;
97                  return TOK_FRAME; }
98<INITIAL>"table" { BEGIN(NOKEYWORD);
99                  is_table = 1;
100                  return TOK_TABLE; }
101<INITIAL>"vec" { BEGIN(NOKEYWORD);
102                  return TOK_VEC; }
103<INITIAL>"pad" { BEGIN(NOKEYWORD);
104                  return TOK_PAD; }
105<INITIAL>"rpad" { BEGIN(NOKEYWORD);
106                  return TOK_RPAD; }
107<INITIAL>"hole" { BEGIN(NOKEYWORD);
108                  return TOK_HOLE; }
109<INITIAL>"rect" { BEGIN(NOKEYWORD);
110                  return TOK_RECT; }
111<INITIAL>"line" { BEGIN(NOKEYWORD);
112                  return TOK_LINE; }
113<INITIAL>"circ" { BEGIN(NOKEYWORD);
114                  return TOK_CIRC; }
115<INITIAL>"arc" { BEGIN(NOKEYWORD);
116                  return TOK_ARC; }
117<INITIAL>"meas" { BEGIN(NOKEYWORD);
118                  return TOK_MEAS; }
119<INITIAL>"measx" { BEGIN(NOKEYWORD);
120                  return TOK_MEASX; }
121<INITIAL>"measy" { BEGIN(NOKEYWORD);
122                  return TOK_MEASY; }
123<INITIAL>"unit" { BEGIN(NOKEYWORD);
124                  return TOK_UNIT; }
125
126<INITIAL>"%del" { BEGIN(NOKEYWORD);
127                  return TOK_DBG_DEL; }
128<INITIAL>"%move" { BEGIN(NOKEYWORD);
129                  return TOK_DBG_MOVE; }
130<INITIAL>"%print" { BEGIN(NOKEYWORD);
131                  return TOK_DBG_PRINT; }
132<INITIAL>"%dump" { BEGIN(NOKEYWORD);
133                  return TOK_DBG_DUMP; }
134<INITIAL>"%exit" { BEGIN(NOKEYWORD);
135                  return TOK_DBG_EXIT; }
136<INITIAL>"%tsort" { BEGIN(NOKEYWORD);
137                  return TOK_DBG_TSORT; }
138
139<INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
140                  yylval.id = unique(yytext);
141                  return LABEL; }
142[a-zA-Z_][a-zA-Z_0-9]* { yylval.id = unique(yytext);
143                  return ID; }
144
145{NUM}{SP}mm { yylval.num.type = nt_mm;
146                  yylval.num.exponent = 1;
147                  sscanf(yytext, "%lf", &yylval.num.n);
148                  return NUMBER; }
149{NUM}{SP}mil { yylval.num.type = nt_mil;
150                  yylval.num.exponent = 1;
151                  sscanf(yytext, "%lf", &yylval.num.n);
152                  return NUMBER; }
153{NUM} { yylval.num.type = nt_mm; /* mm or mil */
154                  yylval.num.exponent = 0;
155                  sscanf(yytext, "%lf", &yylval.num.n);
156                  return NUMBER; }
157
158\"(\\[^\n\t]|[^\\"\n\t])*\" { *strrchr(yytext, '"') = 0;
159                  yylval.str = stralloc(yytext+1);
160                  return STRING; }
161
162"->" return TOK_NEXT;
163"<-" return TOK_NEXT_INVERTED;
164">>" return TOK_MAX;
165"<<" return TOK_MAX_INVERTED;
166
167{SP} ;
168\n { if (!disable_keywords)
169                    BEGIN(INITIAL);
170                  lineno++; }
171
172; BEGIN(INITIAL);
173
174"{" { BEGIN(NOKEYWORD);
175                  disable_keywords = is_table;
176                  return '{'; }
177"}" { disable_keywords = 0;
178                  return '}'; }
179
180^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
181                  if (!disable_keywords)
182                      BEGIN(INITIAL);
183                  lineno = strtol(yytext+2, NULL, 0); }
184
185. return *yytext;
186

Archive Download this file

Branches:
master



interactive