Root/fpd.l

Source at commit 82a12023cdc81c3a4768ac8339b28f3a561272de created 9 years 2 months ago.
By werner, I thought there was a bug in frame ordering, but it turns out that it works fine. Anyway, here's a new debug construct (%frame) and a bunch of new regression tests.
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>"%frame" { BEGIN(NOKEYWORD);
131                  return TOK_DBG_FRAME; }
132<INITIAL>"%print" { BEGIN(NOKEYWORD);
133                  return TOK_DBG_PRINT; }
134<INITIAL>"%dump" { BEGIN(NOKEYWORD);
135                  return TOK_DBG_DUMP; }
136<INITIAL>"%exit" { BEGIN(NOKEYWORD);
137                  return TOK_DBG_EXIT; }
138<INITIAL>"%tsort" { BEGIN(NOKEYWORD);
139                  return TOK_DBG_TSORT; }
140
141<INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0;
142                  yylval.id = unique(yytext);
143                  return LABEL; }
144[a-zA-Z_][a-zA-Z_0-9]* { yylval.id = unique(yytext);
145                  return ID; }
146
147{NUM}{SP}mm { yylval.num.type = nt_mm;
148                  yylval.num.exponent = 1;
149                  sscanf(yytext, "%lf", &yylval.num.n);
150                  return NUMBER; }
151{NUM}{SP}mil { yylval.num.type = nt_mil;
152                  yylval.num.exponent = 1;
153                  sscanf(yytext, "%lf", &yylval.num.n);
154                  return NUMBER; }
155{NUM} { yylval.num.type = nt_mm; /* mm or mil */
156                  yylval.num.exponent = 0;
157                  sscanf(yytext, "%lf", &yylval.num.n);
158                  return NUMBER; }
159
160\"(\\[^\n\t]|[^\\"\n\t])*\" { *strrchr(yytext, '"') = 0;
161                  yylval.str = stralloc(yytext+1);
162                  return STRING; }
163
164"->" return TOK_NEXT;
165"<-" return TOK_NEXT_INVERTED;
166">>" return TOK_MAX;
167"<<" return TOK_MAX_INVERTED;
168
169{SP} ;
170\n { if (!disable_keywords)
171                    BEGIN(INITIAL);
172                  lineno++; }
173
174; BEGIN(INITIAL);
175
176"{" { BEGIN(NOKEYWORD);
177                  disable_keywords = is_table;
178                  return '{'; }
179"}" { disable_keywords = 0;
180                  return '}'; }
181
182^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n {
183                  if (!disable_keywords)
184                      BEGIN(INITIAL);
185                  lineno = strtol(yytext+2, NULL, 0); }
186
187. return *yytext;
188

Archive Download this file

Branches:
master



interactive