Deleted Added
full compact
lex.c (85587) lex.c (90902)
1/****************************************************************
2Copyright (C) Lucent Technologies 1997
3All Rights Reserved
4
5Permission to use, copy, modify, and distribute this software and
6its documentation for any purpose and without fee is hereby
7granted, provided that the above copyright notice appear in all
8copies and that both that the copyright notice and this

--- 91 unchanged lines hidden (view full) ---

100{
101 int c = input();
102 unput(c);
103 return c;
104}
105
106int gettok(char **pbuf, int *psz) /* get next input token */
107{
1/****************************************************************
2Copyright (C) Lucent Technologies 1997
3All Rights Reserved
4
5Permission to use, copy, modify, and distribute this software and
6its documentation for any purpose and without fee is hereby
7granted, provided that the above copyright notice appear in all
8copies and that both that the copyright notice and this

--- 91 unchanged lines hidden (view full) ---

100{
101 int c = input();
102 unput(c);
103 return c;
104}
105
106int gettok(char **pbuf, int *psz) /* get next input token */
107{
108 int c;
108 int c, retc;
109 char *buf = *pbuf;
110 int sz = *psz;
111 char *bp = buf;
112
113 c = input();
114 if (c == 0)
115 return 0;
116 buf[0] = c;

--- 11 unchanged lines hidden (view full) ---

128 *bp++ = c;
129 else {
130 *bp = 0;
131 unput(c);
132 break;
133 }
134 }
135 *bp = 0;
109 char *buf = *pbuf;
110 int sz = *psz;
111 char *bp = buf;
112
113 c = input();
114 if (c == 0)
115 return 0;
116 buf[0] = c;

--- 11 unchanged lines hidden (view full) ---

128 *bp++ = c;
129 else {
130 *bp = 0;
131 unput(c);
132 break;
133 }
134 }
135 *bp = 0;
136 retc = 'a'; /* alphanumeric */
136 } else { /* it's a number */
137 char *rem;
138 /* read input until can't be a number */
139 for ( ; (c = input()) != 0; ) {
140 if (bp-buf >= sz)
141 if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0))
142 FATAL( "out of space for number %.10s...", buf );
143 if (isdigit(c) || c == 'e' || c == 'E'
144 || c == '.' || c == '+' || c == '-')
145 *bp++ = c;
146 else {
147 unput(c);
148 break;
149 }
150 }
151 *bp = 0;
152 strtod(buf, &rem); /* parse the number */
153 unputstr(rem); /* put rest back for later */
137 } else { /* it's a number */
138 char *rem;
139 /* read input until can't be a number */
140 for ( ; (c = input()) != 0; ) {
141 if (bp-buf >= sz)
142 if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0))
143 FATAL( "out of space for number %.10s...", buf );
144 if (isdigit(c) || c == 'e' || c == 'E'
145 || c == '.' || c == '+' || c == '-')
146 *bp++ = c;
147 else {
148 unput(c);
149 break;
150 }
151 }
152 *bp = 0;
153 strtod(buf, &rem); /* parse the number */
154 unputstr(rem); /* put rest back for later */
154 rem[0] = 0;
155 if (rem == buf) { /* it wasn't a valid number at all */
156 buf[1] = 0; /* so return one character as token */
157 retc = buf[0]; /* character is its own type */
158 } else { /* some prefix was a number */
159 rem[0] = 0; /* so truncate where failure started */
160 retc = '0'; /* number */
161 }
155 }
156 *pbuf = buf;
157 *psz = sz;
162 }
163 *pbuf = buf;
164 *psz = sz;
158 return buf[0];
165 return retc;
159}
160
161int word(char *);
162int string(void);
163int regexpr(void);
164int sc = 0; /* 1 => return a } right now */
165int reg = 0; /* 1 => return a REGEXPR now */
166

--- 14 unchanged lines hidden (view full) ---

181 return regexpr();
182 }
183 for (;;) {
184 c = gettok(&buf, &bufsize);
185 if (c == 0)
186 return 0;
187 if (isalpha(c) || c == '_')
188 return word(buf);
166}
167
168int word(char *);
169int string(void);
170int regexpr(void);
171int sc = 0; /* 1 => return a } right now */
172int reg = 0; /* 1 => return a REGEXPR now */
173

--- 14 unchanged lines hidden (view full) ---

188 return regexpr();
189 }
190 for (;;) {
191 c = gettok(&buf, &bufsize);
192 if (c == 0)
193 return 0;
194 if (isalpha(c) || c == '_')
195 return word(buf);
189 if (isdigit(c) || c == '.') {
196 if (isdigit(c)) {
190 yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab);
191 /* should this also have STR set? */
192 RET(NUMBER);
193 }
194
195 yylval.i = c;
196 switch (c) {
197 case '\n': /* {EOL} */

--- 108 unchanged lines hidden (view full) ---

306 }
307 c = peek();
308 if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) {
309 unputstr(buf);
310 RET(INDIRECT);
311 }
312 yylval.cp = setsymtab(buf, "", 0.0, STR|NUM, symtab);
313 RET(IVAR);
197 yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab);
198 /* should this also have STR set? */
199 RET(NUMBER);
200 }
201
202 yylval.i = c;
203 switch (c) {
204 case '\n': /* {EOL} */

--- 108 unchanged lines hidden (view full) ---

313 }
314 c = peek();
315 if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) {
316 unputstr(buf);
317 RET(INDIRECT);
318 }
319 yylval.cp = setsymtab(buf, "", 0.0, STR|NUM, symtab);
320 RET(IVAR);
321 } else if (c == 0) { /* */
322 SYNTAX( "unexpected end of input after $" );
323 RET(';');
314 } else {
315 unputstr(buf);
316 RET(INDIRECT);
317 }
318
319 case '}':
320 if (--bracecnt < 0)
321 SYNTAX( "extra }" );

--- 39 unchanged lines hidden (view full) ---

361 if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, 0))
362 FATAL("out of space for string %.10s...", buf);
363 switch (c) {
364 case '\n':
365 case '\r':
366 case 0:
367 SYNTAX( "non-terminated string %.10s...", buf );
368 lineno++;
324 } else {
325 unputstr(buf);
326 RET(INDIRECT);
327 }
328
329 case '}':
330 if (--bracecnt < 0)
331 SYNTAX( "extra }" );

--- 39 unchanged lines hidden (view full) ---

371 if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, 0))
372 FATAL("out of space for string %.10s...", buf);
373 switch (c) {
374 case '\n':
375 case '\r':
376 case 0:
377 SYNTAX( "non-terminated string %.10s...", buf );
378 lineno++;
379 if (c == 0) /* hopeless */
380 FATAL( "giving up" );
369 break;
370 case '\\':
371 c = input();
372 switch (c) {
373 case '"': *bp++ = '"'; break;
374 case 'n': *bp++ = '\n'; break;
375 case 't': *bp++ = '\t'; break;
376 case 'f': *bp++ = '\f'; break;

--- 195 unchanged lines hidden ---
381 break;
382 case '\\':
383 c = input();
384 switch (c) {
385 case '"': *bp++ = '"'; break;
386 case 'n': *bp++ = '\n'; break;
387 case 't': *bp++ = '\t'; break;
388 case 'f': *bp++ = '\f'; break;

--- 195 unchanged lines hidden ---