1
2 %option nounput
3
4 %{
5 /*
6 * This file is part of the Alliance CAD System
7 * Copyright (C) Laboratoire LIP6 - D�partement ASIM
8 * Universite Pierre et Marie Curie
9 *
10 * Home page : http://www-asim.lip6.fr/alliance/
11 * E-mail : mailto:alliance-users@asim.lip6.fr
12 *
13 * This library is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU Library General Public License as published
15 * by the Free Software Foundation; either version 2 of the License, or (at
16 * your option) any later version.
17 *
18 * Alliance VLSI CAD System is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
21 * Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with the GNU C Library; see the file COPYING. If not, write to the Free
25 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27 /*
28 * Parsing Philips modgen format, done during the IDPS project.
29 * Author: Fr�d�ric P�trot
30 */
31
32 #include <string.h>
33 #include <ctype.h>
34 #include <mut.h>
35 #include "mg2mbk_y.h"
36 static void zweep();
37 extern char *filenameforlex();
38 /* change lex input routine to a non case sensitive one */
39 #ifdef FLEX_SCANNER
40 #ifdef YY_INPUT
41 #undef YY_INPUT
42 #endif
43 #define YY_INPUT(buf,result,max_size) \
44 do { \
45 int c = getc(yyin); \
46 result = (c == EOF) ? YY_NULL \
47 : (buf[0] = isupper(c) ? tolower(c) : c, 1); \
48 } while(0)
49
50 int yylineno;
51 #else /* using lex, for sure */
52 #ifdef input
53 #undef input
54 #endif
55 #define input() (((yytchar = yysptr > yysbuf ? U(*--yysptr) \
56 : getc(yyin)) == 10 ?(yylineno++,yytchar) \
57 : yytchar) == EOF ? 0 \
58 : isupper(yytchar) ? tolower(yytchar) \
59 : yytchar)
60 #endif
61 %}
62
63 cset [a-zA-Z_/]
64 digit [0-9]
65 sign [-+]
66 blank [ \t]*
67 ident {cset}({cset}|{digit}|\[{digit}+\]|\.|$)*
68 fp {sign}?{digit}*\.?{digit}+
69
70 %%
71 {blank} {}
72 \n {
73 #ifdef FLEX_SCANNER
74 yylineno++;
75 #endif
76 }
77 \/\* {zweep('/');}
78 \# {zweep('\n');}
79 property {zweep('}');}
80 node {zweep('}');}
81 text {zweep(';');}
82 constraint {zweep(';');}
83 cell {return CELL;}
84 place {return PLACE;}
85 terminal {return TERMINAL;}
86 ra {return RA;}
87 stretch {return STRETCH;}
88 wire {return WIRE;}
89 width {return MWIDTH;}
90 hor {return HORIZ;}
91 ver {return VERTI;}
92 left {return MLEFT;}
93 right {return MRIGHT;}
94 top {return MTOP;}
95 bottom {return MBOTTOM;}
96 at {return AT;}
97 mx {return MX;}
98 my {return MY;}
99 r {return R;}
100 ntr {return NTR;}
101 ptr {return PTR;}
102 cop {return COP;}
103 con {return CON;}
104 cops {return COPS;}
105 copw {return COPW;}
106 conw {return CONW;}
107 pvia {return PVIA;}
108 cxn {return CXN;}
109 cxp {return CXP;}
110 "=" {return '=';}
111 "{" {return '{';}
112 "}" {return '}';}
113 "(" {return '(';}
114 ")" {return ')';}
115 "," {return ',';}
116 ";" {return ';';}
117 {ident} { yylval.s = mbkstrdup(yytext);
118 return STRING;}
119 {fp} {float f;
120 sscanf(yytext, "%f", &f);
121 yylval.n = (long)(f * SCALE_X);
122 #ifdef GRIDDED
123 yylval.n *= 2;
124 #endif
125 return NUM;}
126 %%
127
128 int yywrap()
129 {
130 return 1;
131 }
132
zweep(find_it)133 static void zweep(find_it)
134 char find_it;
135 {
136 char c;
137
138 while (1) {
139 if ((c = input()) == 0) {
140 (void)fprintf(stderr, "reached EOF before expected end line %d\n",
141 yylineno);
142 exit(12);
143 }
144 /* special case for comments */
145 if (c == '*')
146 if (find_it == '/')
147 if ((c = input()) == 0) {
148 (void)fprintf(stderr,
149 "reached EOF before expected end of comment\n");
150 exit(12);
151 }
152 if (c == find_it)
153 return;
154 }
155 }
156
yyerror(s)157 int yyerror(s)
158 char *s;
159 {
160 fflush(stdout);
161 fprintf(stderr, "modgen parser : syntax error line %d on %s file %s\n",
162 yylineno, yytext, filenameforlex());
163 exit(13);
164 }
165