#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef _WIN32
#include <io.h>
#ifdef __GNUC__
#include <unistd.h>
#else
#include <assert.h>
#include <crtdbg.h>

#define strcasecmp	_stricmp
#define strncasecmp	_strnicmp

#ifndef alloca
#define alloca _alloca
#endif

#endif
#else
#include <unistd.h>
#endif

/*
 * The following record is used to keep track of variables
 * as they are declared (theoretically also data types)
 *
 * For simple datatypes the nam and typ fields are required.
 * For arrays the subscript and range entries are required.
 * For structures the nstruct_rec and struct_rec are required.
 *
 * Arrays and structures can be used concurrently
 */
typedef struct {
    int low, high;
} RANGE;

typedef struct _VAR_REC {
    unsigned long typ;
    char *nam;
    int subscript, nstruct_rec;
    RANGE range[64];
    struct _VAR_REC *struct_rec;
} VAR_REC;

#ifdef __cplusplus
extern "C" {
#endif

void yyerror(const char *mesg);

void add_variable(const char *, const PARSE_TREE *datatype,
	const int subscript, const RANGE *range);
void add_variables(const PARSE_TREE *var_list, const PARSE_TREE *datatype,
	const int subscript, const RANGE *range);
void clear_variables(void);

int check_variable(const char *nam, YYSTYPE *yyval);
int check_funcblk(const char *nam, YYSTYPE *yyval);
unsigned long get_variable_type(const char *nam);

double str_to_time(const char *);
double str_to_daytime(const char *);
double str_to_date(const char *);
double str_to_dateandtime(const char *);
long str_to_int(const char *);
double str_to_real(const char *);

#ifdef __cplusplus
}
#endif
