/*--------------------------------------------------------------------*/ /* parameters: */ /* buf_in: character array holding the input to be analyzed */ /* in_length: the size of buf_in */ /* buf: null terminated character array to hold the token */ /* eventually obtained from buf_in */ /* return: token type (T_TIMES, T_DIVIDE, T_PLUS, T_MINUS, */ /* T_EQUALS, T_INTEGER, T_BADSEP, T_INVALID) */ /* action: copies the token from buf_in to buf, */ /* adds a null terminator to buf afterward, */ /* determines and returns the token type */ /* tokens can be preceeded by 0 or more whitespace characters, */ /* T_INTEGER: a sequence of one or more digits */ /* T_TIMES: the * character */ /* T_DIVIDE: the / character */ /* T_PLUS: the + character */ /* T_MINUS: the - character */ /* T_EQUALS: the = character */ /* each token must be followed by at least one whitespace character */ /* otherwise return token type T_BADSEP */ /* if an invalid character (non-whitespace/operator/digit) */ /* is found returns token type T_INVALID */ /*--------------------------------------------------------------------*/ Token read_token(char buf[], char buf_in[], int in_length)
Suppose we also have a driver program, TokenDriver, that works as follows:
the tester provides TokenDriver with an input string, the expected contents
of buf after the call to read_token, and the token type that should
be returned, for example:
TokenDriver "345 " "345" T_INTEGER
TokenDriver "23x" "23" T_BADSEP
TokenDriver "* " "*" T_TIMES
TokenDriver "? " "?" T_INVALID
TokenDriver generates a test, and informs you if read_token passed or failed.
Develop a set of test cases to use with TokenDriver to determine if the new read_token works correctly.