/******************************************************************************* * * * lex performs the lexical analysis by analyzing each token in the input * * run string, determining what token it is, and what (if any) its * * value is. * * rjc 92.10.8 * *******************************************************************************/ #include "parser.h" #include "general.h" #include "mk4_sizes.h" #include "ffcontrol.h" #include "msg.h" #include #include #include #include /******************************************************************************* * * * is_keyword scans the list of keywords, looking for one to match the * * input string, which is called next_token. Returns = 0 if * * no match is found; else it returns an index number into * * the keyword array. * * rjc 92.11.06 * *******************************************************************************/ int is_keyword (char* next_token) { extern char *token_string[]; /* array of defined tokens */ int i,number; number = 0; /* number == 0 means token not found */ for (i=0; i 366 || ihh < 0 || ihh > 23 || imm < 0 || imm > 59 || iss < 0 || iss > 59) r_code = 0; /* something amiss, this isn't a time */ } } if (r_code) /* everything AOK, convert to secs since BOY */ *i_value = (((iddd - 1) * 24 + ihh) * 60 + imm) * 60 + iss; return (r_code); } /******************************************************************************* * * * is_integer checks the input token, called next_token, to see if it is * * a valid base-10 integer, which consists of a (optional) * * minus sign, followed by digits from [0-9]. If no invalid * * character is found, 1 is returned; otherwise 0 is returned. * * rjc 92.11.06 * *******************************************************************************/ int is_integer (char *next_token, int *i_value) { int i,sign,value; char c; value = 0; sign = 1; for (i = 0; i < strlen (next_token); i++) { c = next_token[i]; /* fetch next character */ if (c == '-' && i == 0) sign = -1; /* valid minus sign */ else if (isdigit (c)) value = 10 * value + c - '0'; /* valid digit */ else return (0); /* indicate invalid integer */ } *i_value = sign * value; return (1); /* indicate valid integer */ } /******************************************************************************* * * * is_float checks the input string, called next_token, to see if it is a * * valid floating point number. Will accept any floating point * * constant that is acceptable to scanf. * * rjc 92.11.06 * * modified to use sscanf rjc 94.1.27 * *******************************************************************************/ int is_float (char *next_token, double *f_value) { int nfields,nchars; double val; nfields = sscanf (next_token,"%le%n",&val,&nchars); if (nfields != 1 || nchars != strlen (next_token)) return (0); else /* valid float detected, indicate success */ { *f_value = val; return (1); } } /******************************************************************************* * * * is_char checks for a string of 1 to 16 contiguous characters, all of * * which appear in a valid-character list. * * * * rjc 92.12.17 * *******************************************************************************/ int is_char (char *next_token) { int n, i, validity; n = strlen (next_token); // if (n < 1 || n > MAXFREQ) // validity = 0; /* wrong length, post as invalid */ // // else // { validity = 1; for (i=0; i nchars+1) break; /* found line that this token is in */ tokens[itok].line = n; /* save it in token struct */ msg ("token %d: <%s> line %d category %hd symbol %hd value %d", -3, itok, next_token, tokens[itok].line, tokens[itok].category, tokens[itok].symbol, tokens[itok].value); nold = (n > 1) ? n - 1 : 1; nchars += strlen (next_token) + 1; /* total chars to start of token */ itok++; } tokens = (struct token_struct *) realloc (tokens, (itok + 1) * sizeof (struct token_struct)); tokens[itok].category = 0; /* mark end of token array */ return (0); /* signal AOK from lex */ } /* // this was commented out at some point and // the common routine is found in parser.c // // int fcode(char c) { int i; // char fchars[64]; for (i = 0; i < MAXFREQ; i++) if (c == fchars[i]) return i; } char get_fchar_by_index(int i) { if(i < MAXFREQ) { return fchars[i]; } else { return '\0'; } } */