Root/
Source at commit 103933acf59927d84df7f99d9580dfc0f45059c2 created 7 years 2 months ago. By Werner Almesberger, fix a few whitespace issues in previous commit | |
---|---|
1 | %{ |
2 | /* |
3 | * fpd.l - FootPrint Definition language |
4 | * |
5 | * Written 2009, 2010, 2012, 2016 by Werner Almesberger |
6 | * Copyright 2009, 2010, 2016 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 | |
27 | static int start_token = START_FPD; |
28 | static int disable_keywords = 0; |
29 | static int is_table = 0; |
30 | |
31 | |
32 | void scan_empty(void) |
33 | { |
34 | yy_scan_string(""); |
35 | } |
36 | |
37 | |
38 | void scan_file(void) |
39 | { |
40 | start_token = START_FPD; |
41 | } |
42 | |
43 | |
44 | void scan_expr(const char *s) |
45 | { |
46 | start_token = START_EXPR; |
47 | yy_scan_string(s); |
48 | } |
49 | |
50 | |
51 | void scan_var(const char *s) |
52 | { |
53 | start_token = START_VAR; |
54 | yy_scan_string(s); |
55 | } |
56 | |
57 | |
58 | void scan_values(const char *s) |
59 | { |
60 | start_token = START_VALUES; |
61 | yy_scan_string(s); |
62 | } |
63 | |
64 | %} |
65 | |
66 | |
67 | /* keywords are only accepted at the beginning of a line */ |
68 | %s NOKEYWORD |
69 | /* ALLOW is followed by special keywords (we could use NOKEYWORD as well) */ |
70 | %s ALLOW |
71 | |
72 | NUM [0-9]+\.?[0-9]* |
73 | SP [\t ]* |
74 | |
75 | |
76 | %% |
77 | |
78 | %{ |
79 | /* |
80 | * Nice hack: |
81 | * |
82 | * http://www.gnu.org/software/bison/manual/bison.html# |
83 | * Multiple-start_002dsymbols |
84 | */ |
85 | |
86 | if (start_token) { |
87 | int tmp = start_token; |
88 | start_token = 0; |
89 | return tmp; |
90 | } |
91 | %} |
92 | |
93 | |
94 | <INITIAL>"set" { BEGIN(NOKEYWORD); |
95 | return TOK_SET; } |
96 | <INITIAL>"loop" { BEGIN(NOKEYWORD); |
97 | return TOK_LOOP; } |
98 | <INITIAL>"part" { BEGIN(NOKEYWORD); |
99 | return TOK_PACKAGE; } |
100 | <INITIAL>"package" { BEGIN(NOKEYWORD); |
101 | return TOK_PACKAGE; } |
102 | <INITIAL>"frame" { BEGIN(NOKEYWORD); |
103 | is_table = 0; |
104 | return TOK_FRAME; } |
105 | <INITIAL>"table" { BEGIN(NOKEYWORD); |
106 | is_table = 1; |
107 | return TOK_TABLE; } |
108 | <INITIAL>"vec" { BEGIN(NOKEYWORD); |
109 | return TOK_VEC; } |
110 | <INITIAL>"pad" { BEGIN(NOKEYWORD); |
111 | return TOK_PAD; } |
112 | <INITIAL>"rpad" { BEGIN(NOKEYWORD); |
113 | return TOK_RPAD; } |
114 | <INITIAL>"hole" { BEGIN(NOKEYWORD); |
115 | return TOK_HOLE; } |
116 | <INITIAL>"rect" { BEGIN(NOKEYWORD); |
117 | return TOK_RECT; } |
118 | <INITIAL>"line" { BEGIN(NOKEYWORD); |
119 | return TOK_LINE; } |
120 | <INITIAL>"circ" { BEGIN(NOKEYWORD); |
121 | return TOK_CIRC; } |
122 | <INITIAL>"arc" { BEGIN(NOKEYWORD); |
123 | return TOK_ARC; } |
124 | <INITIAL>"meas" { BEGIN(NOKEYWORD); |
125 | return TOK_MEAS; } |
126 | <INITIAL>"measx" { BEGIN(NOKEYWORD); |
127 | return TOK_MEASX; } |
128 | <INITIAL>"measy" { BEGIN(NOKEYWORD); |
129 | return TOK_MEASY; } |
130 | <INITIAL>"unit" { BEGIN(NOKEYWORD); |
131 | return TOK_UNIT; } |
132 | |
133 | <INITIAL>"allow" BEGIN(ALLOW); |
134 | <ALLOW>"overlap" return TOK_ALLOW_OVERLAP; |
135 | <ALLOW>"touch" return TOK_ALLOW_TOUCH; |
136 | <ALLOW>"holes" return TOK_ALLOW_HOLES; |
137 | |
138 | <INITIAL>"%del" { BEGIN(NOKEYWORD); |
139 | return TOK_DBG_DEL; } |
140 | <INITIAL>"%move" { BEGIN(NOKEYWORD); |
141 | return TOK_DBG_MOVE; } |
142 | <INITIAL>"%frame" { BEGIN(NOKEYWORD); |
143 | return TOK_DBG_FRAME; } |
144 | <INITIAL>"%print" { BEGIN(NOKEYWORD); |
145 | return TOK_DBG_PRINT; } |
146 | <INITIAL>"%iprint" { BEGIN(NOKEYWORD); |
147 | return TOK_DBG_IPRINT; } |
148 | <INITIAL>"%meas" { BEGIN(NOKEYWORD); |
149 | return TOK_DBG_MEAS; } |
150 | <INITIAL>"%dump" { BEGIN(NOKEYWORD); |
151 | return TOK_DBG_DUMP; } |
152 | <INITIAL>"%exit" { BEGIN(NOKEYWORD); |
153 | return TOK_DBG_EXIT; } |
154 | <INITIAL>"%tsort" { BEGIN(NOKEYWORD); |
155 | return TOK_DBG_TSORT; } |
156 | |
157 | <INITIAL>[a-zA-Z_][a-zA-Z_0-9]*: { *strchr(yytext, ':') = 0; |
158 | yylval.id = unique(yytext); |
159 | return LABEL; } |
160 | [a-zA-Z_][a-zA-Z_0-9]* { yylval.id = unique(yytext); |
161 | return ID; } |
162 | |
163 | {NUM}{SP}mm { yylval.num.type = nt_mm; |
164 | yylval.num.exponent = 1; |
165 | sscanf(yytext, "%lf", &yylval.num.n); |
166 | return NUMBER; } |
167 | {NUM}{SP}um { yylval.num.type = nt_um; |
168 | yylval.num.exponent = 1; |
169 | sscanf(yytext, "%lf", &yylval.num.n); |
170 | return NUMBER; } |
171 | {NUM}{SP}mil { yylval.num.type = nt_mil; |
172 | yylval.num.exponent = 1; |
173 | sscanf(yytext, "%lf", &yylval.num.n); |
174 | return NUMBER; } |
175 | {NUM} { yylval.num.type = nt_mm; /* mm or mil */ |
176 | yylval.num.exponent = 0; |
177 | sscanf(yytext, "%lf", &yylval.num.n); |
178 | return NUMBER; } |
179 | |
180 | \"(\\[^\n\t]|[^\\"\n\t])*\" { *strrchr(yytext, '"') = 0; |
181 | yylval.str = stralloc(yytext+1); |
182 | return STRING; } |
183 | |
184 | "->" return TOK_NEXT; |
185 | "<-" return TOK_NEXT_INVERTED; |
186 | ">>" return TOK_MAX; |
187 | "<<" return TOK_MAX_INVERTED; |
188 | |
189 | {SP} ; |
190 | \n { if (!disable_keywords) |
191 | BEGIN(INITIAL); |
192 | lineno++; } |
193 | |
194 | ; BEGIN(INITIAL); |
195 | |
196 | "{" { disable_keywords = is_table; |
197 | BEGIN(disable_keywords ? |
198 | NOKEYWORD : INITIAL); |
199 | return '{'; } |
200 | "}" { disable_keywords = 0; |
201 | BEGIN(INITIAL); |
202 | return '}'; } |
203 | |
204 | ^#\ [0-9]+\ \"[^"]*\"(\ [0-9]+)*\n { |
205 | if (!disable_keywords) |
206 | BEGIN(INITIAL); |
207 | lineno = strtol(yytext+2, NULL, 0); } |
208 | |
209 | . return *yytext; |
210 |
Branches:
master