static void posRealCheck(double x, char *s) { if (!R_FINITE(x) || x <= 0) par_error(s); }
static void posIntCheck(int x, char *s) { if (x == NA_INTEGER || x <= 0) par_error(s); }
static void naIntCheck(int x, char *s) { if (x == NA_INTEGER) par_error(s); }
static void BoundsCheck(double x, double a, double b, char *s) { /* Check if a <= x <= b */ if (!R_FINITE(x) || (R_FINITE(a) && x < a) || (R_FINITE(b) && x > b)) par_error(s); }
static void nonnegIntCheck(int x, char *s) { if (x == NA_INTEGER || x < 0) par_error(s); }
static void logAxpCheck(int x, char *s) { if (x == NA_INTEGER || x == 0 || x > 4) par_error(s); }
static void naRealCheck(double x, char *s) { if (!R_FINITE(x)) par_error(s); }
static void nonnegRealCheck(double x, char *s) { if (!R_FINITE(x) || x < 0) par_error(s); }
int s_yylex() { register c; register char *cp; int f; char delim; if (yylineno == 0) incrlineno(); while(1) { /* * skip white space */ if (c = lookaheadchar ) { lookaheadchar = 0; } else c = readkey(); cp = yytext; while (c == ' ' || c == '\t' || c == 0 || c == 12 /* FF */) { c = readkey(); } yytext[0] = c; yytext[1] = yytext[2] = 0; if( isascii(c) && (isalpha( c ) || c == '_') ) { do { *cp++ = c; c = readkey(); } while (isascii(c) && (isalnum(c) || c == '_')); *cp = 0; lookaheadchar = c; c = look_kw(yytext); clearla(); if (c == 0) { yylval.strval = allocstring(yytext); return (YID); } return c; } else if( isascii(c) && isdigit(c) ) { f = 0; do { *cp++ = c; c = readkey(); } while (isascii(c) && isdigit(c)); if (c == '.') { c = readkey(); if (c == '.') { *cp = 0; lookaheadchar = YDOTDOT; yylval.strval = allocstring(yytext); return (YINT); } infpnumb: f++; *cp++ = '.'; if (!isascii(c) || !isdigit(c)) { scanerror("syntax error: digits required after decimal point"); *cp++ = '0'; } else while (isdigit(c)) { *cp++ = c; c = readkey(); } } if (c == 'e' || c == 'E') { f++; *cp++ = c; if ((c = lookaheadchar) == 0) c = readkey(); if (c == '+' || c == '-') { *cp++ = c; c = readkey(); } if (!isascii(c) || !isdigit(c)) { scanerror("syntax error: digits required in exponent"); *cp++ = '0'; } else while (isascii(c) && isdigit(c)) { *cp++ = c; c = readkey(); } } *cp = 0; lookaheadchar = c; clearla(); yylval.strval = allocstring(yytext); if (f) return (YNUMB); return (YINT); } printt2("Select on char %d - %c\n", c, c ); switch (c) { case EOF: return 0; case ' ': case '\t': case 12: /* form feed */ break; case '"': case '\'': *cp++ = delim = c; do { do { c = readkey(); if (c == '\n' || c == EOFCHAR) { scanerror("syntax error: unmatched quote for string" ); if (cp == yytext) *cp++ = ' ', cp++; return YILLCH; } *cp++ = c; } while (c != delim); c = readkey(); } while (c == delim); if( c == '^' || c== '#' ) { par_error( "Can't imbed ^A or #nnn codes in strings. Try concatenating strings together\n" ); } *--cp = 0; #ifndef TURBO if (cp == yytext && delim == '\'') { scanerror("syntax error: null string not allowed"); *cp++ = ' '; *cp++ = 0; } #endif lookaheadchar = c; clearla(); /* len of 2 means 1 char and 1 quote char */ if (delim == '"' || strlen(yytext) != 2) { yylval.strval = allocstring(yytext); return (YSTRING); } else { yylval.intval = yytext[1]; return (YCHAR); } case '.': c = readkey(); if (c == '.') return (YDOTDOT); if (isdigit(c)) { scanerror("syntax error: digits required before decimal point"); *cp++ = '0'; goto infpnumb; } lookaheadchar = c; clearla(); return '.'; case '\n': break; case '{': /* { ... } comment */ delim = '{'; comment: c = readkey(); #ifdef TURBO if (c == '$' && turbo_flag) { f = scanturbo(); if (f >= 0) return f; } else #endif if (c == '+') { /* Stubs generated by alist, we know they use {} */ f = scanstub(); if (f == YC_BLCOMMENT) { /* Kludge - throw away to keep grammar LALR. * Doesn't matter since they will be generated * in all appropriate places anyway. */ continue; /* outer while loop */ } if (f >= 0) return f; } else { for (;;) { if (delim=='{' && c == '}') { break; } if (c == '\n') { /* Break into one line pieces */ *cp++ = 0; savecomment(yytext); cp = yytext; *cp = 0; } else { *cp++ = c; if (c <= 0) { /* nonterminated comment */ /* This "can't happen" */ fatal("Bug - nonterm comment"); } } c = readkey(); if (delim=='(' && c == ')' && cp[-1] == '*') { *--cp = 0; break; } } *cp++ = 0; } /* * Comments generated by the lister for procedure or * function calls (in parens, ending in =) are ignored. */ if (parendepth <= 0 || cp[-2] != '=') savecomment(yytext); clearla(); cp = yytext; *cp = 0; if (allowcom) return 0; break; case ':': if ((c=readkey()) == '=') { *++cp = c; return YCOLEQUALS; } lookaheadchar = c; clearla(); return ':'; case '(': if ((c=readkey()) == '*') { delim = '('; goto comment; } lookaheadchar = c; clearla(); parendepth++; return '('; case ')': parendepth--; return ')'; case '$': while( isxdigit(c = readkey()) ) *++cp = c; *++cp = 0; lookaheadchar = c; if( strlen(yytext) <= 1 ) return YILLCH; yylval.strval = allocstring(yytext); return YINT; case '#': c = readkey(); if( c == '$' ) { unsigned hxnum; while( isxdigit(c = readkey()) ) hxnum = (hxnum << 4) + ((c > '9') ? 9 : 0) + (c & 0xf); lookaheadchar = c; yylval.intval = hxnum; return YCHAR; } else while (isdigit(c)) { *++cp = c; c = readkey(); } *++cp = 0; lookaheadchar = c; yylval.intval = atoi(&yytext[1]); return YCHAR; case '^': c = readkey(); if (strchr("\\_", c)) { /* others include []@^ */ yylval.intval = c & 0x1f; return YCHAR; } else { lookaheadchar = c; yylval.intval = '^'; return YPTR; } case '@': yylval.intval = '@'; return YPTR; case ';': case ',': case '=': case '*': case '+': case '/': case '-': case '[': case ']': case '<': case '>': case '_': case '\\': case '}': /* for DO..SET */ return c; case YDOTDOT: return YDOTDOT; default: if (c <= 0) return (0); do lookaheadchar = readkey(); while (lookaheadchar == c); clearla(); printt1("illegal char in scanner %o\n", c); return (YILLCH); } } /* big while */ }
/* ** NUMBER ** scans numerical constants (both integer and floating). Each ** constant is converted from ascii to its numerical representation ** and is entered into the symbol table, indexed by 'yylval'. ** A token is returned for the number type. ** ** due to the current atof in the utility library, floating overflow ** is not checked. */ int number(char chr) { extern int yylval; double ftemp; long ltemp; short itemp; char buf[256]; register int lsave; register char *ptr; lsave = Lcase; Lcase = 0; ptr = buf; if ((*ptr = chr) != '.') { do { /* get integer portion */ if ((ptr - buf) >= 256) { /* buffer overflow */ par_error(NUMBUFOFLO, WARN, 0, 0, 0); } *++ptr = get_scan(NORMAL); } while (parser_cmap(*ptr) == NUMBR); } /* do rest of type determination */ switch (*ptr) { case '.': /* floating point */ do { /* fill into ptr with up to next non-digit */ if ((ptr - buf) >= 256) { /* buf oflo */ par_error(NUMBUFOFLO, WARN, 0, 0, 0); } *++ptr = get_scan(NORMAL); } while (parser_cmap(*ptr) == NUMBR); if (*ptr != 'e' && *ptr != 'E') { backup(*ptr); *ptr = 0; goto convr; } case 'e': case 'E': if ((ptr - buf) >= 256) { par_error(NUMBUFOFLO, WARN, 0, 0, 0); /* buf oflo */ } *++ptr = get_scan(NORMAL); if (parser_cmap(*ptr) == NUMBR || *ptr == '-' || *ptr == '+') { do { /* get exponent */ if ((ptr - buf) >= 256) { /* buf oflo */ par_error(NUMBUFOFLO, WARN, 0, 0, 0); } *++ptr = get_scan(NORMAL); } while (parser_cmap(*ptr) == NUMBR); } backup(*ptr); *ptr = 0; /* FALLTHROUGH */ convr: if (ingres_atof(buf, &ftemp)) { /* floating conversion error */ par_error(FCONSTERR, WARN, buf, 0, 0); } yylval = (int) syment(&ftemp, 8); Lastok.toktyp = Tokens.f8const; break; default: /* integer */ backup(*ptr); *ptr = 0; if (ingres_atol(buf, <emp)) { /* long conversion error */ goto convr; } if (ltemp > 32767) { yylval = (int) syment(<emp, 4); Lastok.toktyp = Tokens.i4const; break; } itemp = ltemp; yylval = (int) syment(&itemp, 2); Lastok.toktyp = Tokens.i2const; break; } Lcase = lsave; Lastok.tok = (char *) yylval; Lastok.tokop = 0; return (Lastok.toktyp); }