Deleted Added
full compact
lex.c (146299) lex.c (170331)
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

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

84 { "sub", SUB, SUB },
85 { "substr", SUBSTR, SUBSTR },
86 { "system", FSYSTEM, BLTIN },
87 { "tolower", FTOLOWER, BLTIN },
88 { "toupper", FTOUPPER, BLTIN },
89 { "while", WHILE, WHILE },
90};
91
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

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

84 { "sub", SUB, SUB },
85 { "substr", SUBSTR, SUBSTR },
86 { "system", FSYSTEM, BLTIN },
87 { "tolower", FTOLOWER, BLTIN },
88 { "toupper", FTOUPPER, BLTIN },
89 { "while", WHILE, WHILE },
90};
91
92#define DEBUG
93#ifdef DEBUG
94#define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); }
92#define RET(x) { if(dbg)printf("lex %s\n", tokname(x)); return(x); }
95#else
96#define RET(x) return(x)
97#endif
98
99int peek(void)
100{
101 int c = input();
102 unput(c);
103 return c;
104}
105

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

117 buf[1] = 0;
118 if (!isalnum(c) && c != '.' && c != '_')
119 return c;
120
121 *bp++ = c;
122 if (isalpha(c) || c == '_') { /* it's a varname */
123 for ( ; (c = input()) != 0; ) {
124 if (bp-buf >= sz)
93
94int peek(void)
95{
96 int c = input();
97 unput(c);
98 return c;
99}
100

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

112 buf[1] = 0;
113 if (!isalnum(c) && c != '.' && c != '_')
114 return c;
115
116 *bp++ = c;
117 if (isalpha(c) || c == '_') { /* it's a varname */
118 for ( ; (c = input()) != 0; ) {
119 if (bp-buf >= sz)
125 if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0))
120 if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok"))
126 FATAL( "out of space for name %.10s...", buf );
127 if (isalnum(c) || c == '_')
128 *bp++ = c;
129 else {
130 *bp = 0;
131 unput(c);
132 break;
133 }
134 }
135 *bp = 0;
136 retc = 'a'; /* alphanumeric */
137 } else { /* maybe it's a number, but could be . */
138 char *rem;
139 /* read input until can't be a number */
140 for ( ; (c = input()) != 0; ) {
141 if (bp-buf >= sz)
121 FATAL( "out of space for name %.10s...", buf );
122 if (isalnum(c) || c == '_')
123 *bp++ = c;
124 else {
125 *bp = 0;
126 unput(c);
127 break;
128 }
129 }
130 *bp = 0;
131 retc = 'a'; /* alphanumeric */
132 } else { /* maybe it's a number, but could be . */
133 char *rem;
134 /* read input until can't be a number */
135 for ( ; (c = input()) != 0; ) {
136 if (bp-buf >= sz)
142 if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, 0))
137 if (!adjbuf(&buf, &sz, bp-buf+2, 100, &bp, "gettok"))
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 }

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

171int regexpr(void);
172int sc = 0; /* 1 => return a } right now */
173int reg = 0; /* 1 => return a REGEXPR now */
174
175int yylex(void)
176{
177 int c;
178 static char *buf = 0;
138 FATAL( "out of space for number %.10s...", buf );
139 if (isdigit(c) || c == 'e' || c == 'E'
140 || c == '.' || c == '+' || c == '-')
141 *bp++ = c;
142 else {
143 unput(c);
144 break;
145 }

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

166int regexpr(void);
167int sc = 0; /* 1 => return a } right now */
168int reg = 0; /* 1 => return a REGEXPR now */
169
170int yylex(void)
171{
172 int c;
173 static char *buf = 0;
179 static int bufsize = 500;
174 static int bufsize = 5; /* BUG: setting this small causes core dump! */
180
181 if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL)
182 FATAL( "out of space in yylex" );
183 if (sc) {
184 sc = 0;
185 RET('}');
186 }
187 if (reg) {
188 reg = 0;
189 return regexpr();
190 }
175
176 if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL)
177 FATAL( "out of space in yylex" );
178 if (sc) {
179 sc = 0;
180 RET('}');
181 }
182 if (reg) {
183 reg = 0;
184 return regexpr();
185 }
191/* printf("top\n"); */
192 for (;;) {
193 c = gettok(&buf, &bufsize);
186 for (;;) {
187 c = gettok(&buf, &bufsize);
194/* printf("gettok [%s]\n", buf); */
195 if (c == 0)
196 return 0;
197 if (isalpha(c) || c == '_')
198 return word(buf);
199 if (isdigit(c)) {
200 yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab);
201 /* should this also have STR set? */
202 RET(NUMBER);

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

366 int c, n;
367 char *s, *bp;
368 static char *buf = 0;
369 static int bufsz = 500;
370
371 if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
372 FATAL("out of space for strings");
373 for (bp = buf; (c = input()) != '"'; ) {
188 if (c == 0)
189 return 0;
190 if (isalpha(c) || c == '_')
191 return word(buf);
192 if (isdigit(c)) {
193 yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab);
194 /* should this also have STR set? */
195 RET(NUMBER);

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

359 int c, n;
360 char *s, *bp;
361 static char *buf = 0;
362 static int bufsz = 500;
363
364 if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
365 FATAL("out of space for strings");
366 for (bp = buf; (c = input()) != '"'; ) {
374 if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, 0))
367 if (!adjbuf(&buf, &bufsz, bp-buf+2, 500, &bp, "string"))
375 FATAL("out of space for string %.10s...", buf);
376 switch (c) {
377 case '\n':
378 case '\r':
379 case 0:
380 SYNTAX( "non-terminated string %.10s...", buf );
381 lineno++;
382 if (c == 0) /* hopeless */

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

460}
461
462int word(char *w)
463{
464 Keyword *kp;
465 int c, n;
466
467 n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
368 FATAL("out of space for string %.10s...", buf);
369 switch (c) {
370 case '\n':
371 case '\r':
372 case 0:
373 SYNTAX( "non-terminated string %.10s...", buf );
374 lineno++;
375 if (c == 0) /* hopeless */

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

453}
454
455int word(char *w)
456{
457 Keyword *kp;
458 int c, n;
459
460 n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0]));
461/* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */
468 kp = keywords + n;
469 if (n != -1) { /* found in table */
470 yylval.i = kp->sub;
471 switch (kp->type) { /* special handling */
462 kp = keywords + n;
463 if (n != -1) { /* found in table */
464 yylval.i = kp->sub;
465 switch (kp->type) { /* special handling */
472 case FSYSTEM:
473 if (safe)
466 case BLTIN:
467 if (kp->sub == FSYSTEM && safe)
474 SYNTAX( "system is unsafe" );
475 RET(kp->type);
476 case FUNC:
477 if (infunc)
478 SYNTAX( "illegal nested function" );
479 RET(kp->type);
480 case RETURN:
481 if (!infunc)

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

513 static char *buf = 0;
514 static int bufsz = 500;
515 char *bp;
516
517 if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
518 FATAL("out of space for rex expr");
519 bp = buf;
520 for ( ; (c = input()) != '/' && c != 0; ) {
468 SYNTAX( "system is unsafe" );
469 RET(kp->type);
470 case FUNC:
471 if (infunc)
472 SYNTAX( "illegal nested function" );
473 RET(kp->type);
474 case RETURN:
475 if (!infunc)

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

507 static char *buf = 0;
508 static int bufsz = 500;
509 char *bp;
510
511 if (buf == 0 && (buf = (char *) malloc(bufsz)) == NULL)
512 FATAL("out of space for rex expr");
513 bp = buf;
514 for ( ; (c = input()) != '/' && c != 0; ) {
521 if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, 0))
515 if (!adjbuf(&buf, &bufsz, bp-buf+3, 500, &bp, "regexpr"))
522 FATAL("out of space for reg expr %.10s...", buf);
523 if (c == '\n') {
524 SYNTAX( "newline in regular expression %.10s...", buf );
525 unput('\n');
526 break;
527 } else if (c == '\\') {
528 *bp++ = '\\';
529 *bp++ = input();

--- 59 unchanged lines hidden ---
516 FATAL("out of space for reg expr %.10s...", buf);
517 if (c == '\n') {
518 SYNTAX( "newline in regular expression %.10s...", buf );
519 unput('\n');
520 break;
521 } else if (c == '\\') {
522 *bp++ = '\\';
523 *bp++ = input();

--- 59 unchanged lines hidden ---